Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions December 01/c_BawadharaniSree_Cricmetric.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include <stdio.h>
int calculateTotalRuns(int runs[], int numBatsmen) {
int totalRuns = 0;
for (int i = 0; i < numBatsmen; i++) {
totalRuns += runs[i];
}
return totalRuns;
}
int findHighestScorer(int runs[], int numBatsmen, int *maxRuns) {
int maxBatsman = -1;
*maxRuns = 0;
for (int i = 0; i < numBatsmen; i++) {
if (runs[i] > *maxRuns) {
*maxRuns = runs[i];
maxBatsman = i;
}
}
return maxBatsman;
}
int main() {
int numBatsmen, runs[100], totalRuns, maxRuns, maxBatsman;
printf("Enter the number of Batsmen: ");
scanf("%d", &numBatsmen);
printf("Enter the runs scored by each Batsman:\n");
for (int i = 0; i < numBatsmen; i++) {
printf("Batsman %d: ", i);
scanf("%d", &runs[i]);
}
totalRuns = calculateTotalRuns(runs, numBatsmen);
maxBatsman = findHighestScorer(runs, numBatsmen, &maxRuns);
printf("\nTotal Runs: %d\n", totalRuns);
printf("Batsman %d scored the highest runs: %d\n", maxBatsman, maxRuns);
return 0;
}
26 changes: 26 additions & 0 deletions December 02/c_BawadharaniSree_ShoppersChoice.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include<string.h>
void calculateProductFrequency(int products[], int numProducts, int frequency[]) {
for (int i = 0; i < numProducts; i++) {
int currentProduct = products[i];
frequency[currentProduct]++;
}
}
int main() {
int products[100], frequency[100] = {0}, numProducts;
printf("Enter the number of products: ");
scanf("%d", &numProducts);
printf("Enter the product IDs:\n");
for (int i = 0; i < numProducts; i++) {
printf("Product %d: ", i + 1);
scanf("%d", &products[i]);
}
calculateProductFrequency(products, numProducts, frequency);
printf("\nProduct Frequencies:\n");
for (int i = 0; i < 100; i++) {
if (frequency[i] > 0) {
printf("Frequency of %d: %d\n", i, frequency[i]);
}
}
return 0;
}
26 changes: 26 additions & 0 deletions December 03/c_BawadharaniSree_Sunburnt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
#include<string.h>
int count_buildings(int heights[], int n) {
int count = 1;
int max_height = heights[0];
for (int i = 1; i < n; i++) {
if (heights[i] > max_height) {
count++;
max_height = heights[i];
}
}
return count;
}
int main() {
int n, heights[100];
printf("Enter the number of buildings: ");
scanf("%d", &n);
printf("Enter the heights of the buildings:\n");
for (int i = 0; i < n; i++) {
printf("Building %d: ", i + 1);
scanf("%d", &heights[i]);
}
int result = count_buildings(heights, n);
printf("\nNumber of buildings that will see the sunrise: %d\n", result);
return 0;
}
41 changes: 41 additions & 0 deletions December 04/c_BawadharaniSree_MirrorMagic.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>
#include <string.h>
int isPalindromic(char str[], int start, int end) {
while (start < end) {
if (str[start] != str[end]) {
return 0;
}
start++;
end--;
}
return 1;
}
void findSmallestPalindromicSubstring(char str[]) {
int n = strlen(str);
int minLen = n;
int minStart = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (isPalindromic(str, i, j) && (j - i + 1) < minLen) {
minLen = j - i + 1;
minStart = i;
}
}
}
if (minLen == n) {
printf("Error\n");
} else {
printf("The smallest palindromic substring: ");
for (int i = minStart; i < minStart + minLen; i++) {
printf("%c", str[i]);
}
printf("\n");
}
}
int main() {
char str[100];
printf("Enter the string: ");
scanf("%s", str);
findSmallestPalindromicSubstring(str);
return 0;
}
20 changes: 20 additions & 0 deletions December 05/c_BawadharaniSree_PeakyBlinders.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <stdio.h>
int main() {
int amounts[100];
int numthieves, totalamount = 0, averageamount, aboveaveragetotal = 0;
printf("Enter the number of thieves: ");
scanf("%d", &numthieves);
printf("Enter the amounts stolen by each thief:\n");
for (int i = 0; i < numthieves; i++) {
scanf("%d", &amounts[i]);
totalamount += amounts[i];
}
averageamount = totalamount / numthieves;
for (int i = 0; i < numthieves; i++) {
if (amounts[i] >= averageamount) {
aboveaveragetotal += amounts[i];
}
}
printf("Total amount stolen by thieves above average: %d\n", aboveaveragetotal);
return 0;
}
59 changes: 59 additions & 0 deletions December 06/c_BawadharaniSree_TheLostAlgorithmScrolls.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_WORDS 100
#define MAX_LENGTH 20
int isOneLetterDifference(const char *word1, const char *word2) {
int differences = 0;
int len1 = strlen(word1);
int len2 = strlen(word2);
if (len1 != len2) {
return 0;
}
for (int i = 0; i < len1; i++) {
if (word1[i] != word2[i]) {
differences++;
}
if (differences > 1) {
return 0;
}
}
return differences == 1;
}
void findWordChain(char *words[], int n) {
int foundChain = 0;
for (int i = 0; i < n; i++) {
printf("Enter word %d: ", i + 1);
scanf("%s", words[i]);
}
printf("\nOutput:\n");
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (isOneLetterDifference(words[i], words[j])) {
printf("%s -> %s\n", words[i], words[j]);
foundChain = 1;
}
}
}
if (!foundChain) {
printf("No valid chain.\n");
}
}
int main() {
char *words[MAX_WORDS];
int n;
printf("Enter the number of words: ");
scanf("%d", &n);
if (n > MAX_WORDS || n <= 0) {
printf("Invalid number of words. Exiting...\n");
return 1;
}
for (int i = 0; i < MAX_WORDS; i++) {
words[i] = (char *)malloc(MAX_LENGTH * sizeof(char));
}
findWordChain(words, n);
for (int i = 0; i < MAX_WORDS; i++) {
free(words[i]);
}
return 0;
}
22 changes: 22 additions & 0 deletions December 07/c_BawadharaniSree_BabyBlocks.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
bool rectangleInCircle(int width, int height, int radius) {
double diagonal = sqrt(width * width + height * height);
return (2 * radius >= diagonal);
}
int main() {
int width, height, radius;
printf("Enter the width of the rectangle: ");
scanf("%d", &width);
printf("Enter the height of the rectangle: ");
scanf("%d", &height);
printf("Enter the radius of the circle: ");
scanf("%d", &radius);
if (rectangleInCircle(width, height, radius)) {
printf("true\n");
} else {
printf("false\n");
}
return 0;
}
51 changes: 51 additions & 0 deletions December 08/c_BawadharaniSree_TheEnchantedForest.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#include <stdio.h>
void find_path(int n) {
if (n % 2 == 0 || n < 3 || n > 15) {
printf("Invalid input. Please enter an odd integer between 3 and 15.\n");
return;
}
int magicSquare[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
magicSquare[i][j] = 0;
}
}
int i = n / 2;
int j = n - 1;
for (int num = 1; num <= n * n;) {
if (i == -1 && j == n) {
j = n - 2;
i = 0;
} else {
if (j == n) {
j = 0;
}
if (i < 0) {
i = n - 1;
}
}
if (magicSquare[i][j] != 0) {
j -= 2;
i++;
continue;
} else {
magicSquare[i][j] = num++;
}
j++;
i--;
}
printf("Output:\n");
for (int row = 0; row < n; row++) {
for (int col = 0; col < n; col++) {
printf("%2d ", magicSquare[row][col]);
}
printf("\n");
}
}
int main() {
int n;
printf("Enter an odd integer between 3 and 15: ");
scanf("%d", &n);
find_path(n);
return 0;
}
18 changes: 18 additions & 0 deletions December 09/c_BawadharaniSree_CamelsonaString!.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
int countWordsInCamelCase(char *s) {
int count = 0;
for (int i = 0; s[i] != '\0'; i++) {
if (s[i] >= 'A' && s[i] <= 'Z') {
count++;
}
}
return count;
}
int main() {
char s[100000];
printf("Enter the camel case string: ");
scanf("%s", s);
int result = countWordsInCamelCase(s);
printf("Output: %d\n", result);
return 0;
}
45 changes: 45 additions & 0 deletions December 10/c_BawadharaniSree_Forgot_Password.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <string.h>

// Function to extract substring based on SQL query
void extractSubstring(char empname[], int start, int end, char result[]) {
// Check if start and end values are within the bounds of empname
if (start >= 1 && end <= strlen(empname) && start <= end) {
// Calculate the length of the substring
int length = end - start + 1;

// Extract substring using strncpy
strncpy(result, empname + start - 1, length);
result[length] = '\0'; // Null-terminate the result string
} else {
// Invalid start or end values
strcpy(result, "Invalid Query");
}
}

int main() {
// Get employee name from the user
printf("Enter employee name: ");
char empname[100]; // Adjust the size accordingly
fgets(empname, sizeof(empname), stdin);
empname[strcspn(empname, "\n")] = '\0'; // Remove the newline character

// Get start from the user
printf("Enter start position: ");
int start;
scanf("%d", &start);

// Get end from the user
printf("Enter end position: ");
int end;
scanf("%d", &end);

// Validate and extract substring
char result[100]; // Adjust the size accordingly
extractSubstring(empname, start, end+1, result);

// Display the result
printf("Output: %s\n", result);

return 0;
}
29 changes: 29 additions & 0 deletions December 11/c_BawadharaniSree_Coder_of_Conversions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>
void addAndConvertToBinary(int num1, int num2)
{
int sum = num1 + num2;
int binary[32];
int index = 0;
while (sum > 0)
{
binary[index++] = sum % 2;
sum = sum / 2;
}
for (int i = index - 1; i >= 0; i--)
{
printf("%d", binary[i]);
}

printf("\n");
}
int main()
{
int num1, num2;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
printf("Input: (%d, %d)\nOutput: ", num1, num2);
addAndConvertToBinary(num1, num2);
return 0;
}
Loading