diff --git a/Week 3/Solutions/Gantyada Tejesh Kumar/Assignment 3 b/Week 3/Solutions/Gantyada Tejesh Kumar/Assignment 3 new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Week 3/Solutions/Gantyada Tejesh Kumar/Assignment 3 @@ -0,0 +1 @@ + diff --git a/Week 3/Solutions/Gantyada Tejesh Kumar/a1.c b/Week 3/Solutions/Gantyada Tejesh Kumar/a1.c new file mode 100644 index 0000000..e8add28 --- /dev/null +++ b/Week 3/Solutions/Gantyada Tejesh Kumar/a1.c @@ -0,0 +1,25 @@ +#include +#include + +void main() { + char str[100], r, str1[100]; + int i, j=0; + + printf("Enter a string: "); + gets(str); + + printf("Enter the character to remove: "); + scanf("%c", &r); + + + for (i = 0; i < strlen(str); i++) { + if (str[i] != r) { + str1[j++] = str[i]; + } + } + + str1[j] = '\0'; + + printf("String after removing %c: %s", r, str1); + +} diff --git a/Week 3/Solutions/Gantyada Tejesh Kumar/a2.c b/Week 3/Solutions/Gantyada Tejesh Kumar/a2.c new file mode 100644 index 0000000..388a7b5 --- /dev/null +++ b/Week 3/Solutions/Gantyada Tejesh Kumar/a2.c @@ -0,0 +1,23 @@ +#include +#include + +void main() +{ + char str[100]; + int f[256] = {0}, i; + + printf("Enter a string: "); + gets(str); + + for (i = 0; i < strlen(str); i++) { + f[(int)str[i]]++; + } + + printf("Frequency of each character in the string: \n"); + for (i = 0; i < 256; i++) { + if (f[i] != 0) { + printf("%c = %d\n", i, f[i]); + } + } + +} diff --git a/Week 3/Solutions/Gantyada Tejesh Kumar/a3.c b/Week 3/Solutions/Gantyada Tejesh Kumar/a3.c new file mode 100644 index 0000000..94fe5d6 --- /dev/null +++ b/Week 3/Solutions/Gantyada Tejesh Kumar/a3.c @@ -0,0 +1,22 @@ +#include + +void add(int *a, int *b, int *result); + +void main() { + int a, b, result; + + printf("Enter first number: "); + scanf("%d", &a); + + printf("Enter second number: "); + scanf("%d", &b); + + add(&a, &b, &result); + + printf("Sum is %d", result); + +} + +void add(int *a, int *b, int *result) { + *result = *a + *b; +} diff --git a/Week 3/Solutions/Gantyada Tejesh Kumar/a4.c b/Week 3/Solutions/Gantyada Tejesh Kumar/a4.c new file mode 100644 index 0000000..fd8da15 --- /dev/null +++ b/Week 3/Solutions/Gantyada Tejesh Kumar/a4.c @@ -0,0 +1,24 @@ +#include + +void factorial(int n, int *f); + +void main() { + int n, f; + + printf("Enter a number: "); + scanf("%d", &n); + + factorial(n, &f); + + printf("Factorial of %d is %d", n, f); + +} + +void factorial(int n, int *f) { + int i; + *f = 1; + + for (i = 1; i <= n; i++) { + *f *= i; + } +} diff --git a/Week 3/Solutions/Gantyada Tejesh Kumar/a5.txt b/Week 3/Solutions/Gantyada Tejesh Kumar/a5.txt new file mode 100644 index 0000000..36d350e --- /dev/null +++ b/Week 3/Solutions/Gantyada Tejesh Kumar/a5.txt @@ -0,0 +1,2 @@ +5) a--> ii) k is a pointer to a pointer to a pointer to a pointer to a char + b--> iii) 6 diff --git a/Week 3/Solutions/Gantyada Tejesh Kumar/a6.txt b/Week 3/Solutions/Gantyada Tejesh Kumar/a6.txt new file mode 100644 index 0000000..457b126 --- /dev/null +++ b/Week 3/Solutions/Gantyada Tejesh Kumar/a6.txt @@ -0,0 +1 @@ +6) b. Structure members cannot be initialized at the time of declaration. \ No newline at end of file diff --git a/Week 3/Solutions/Gantyada Tejesh Kumar/a7.txt b/Week 3/Solutions/Gantyada Tejesh Kumar/a7.txt new file mode 100644 index 0000000..517a386 --- /dev/null +++ b/Week 3/Solutions/Gantyada Tejesh Kumar/a7.txt @@ -0,0 +1,2 @@ +7) The size of C Structure is the Sum of sizes of different data types present in it. + We can calculate the size by adding the size of individual data types present in that Structure. \ No newline at end of file diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/Assignment b/Week2/Solutions/Gantyada Tejesh Kumar/Assignment new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/Assignment @@ -0,0 +1 @@ + diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a1.c b/Week2/Solutions/Gantyada Tejesh Kumar/a1.c new file mode 100644 index 0000000..8751c00 --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a1.c @@ -0,0 +1,32 @@ +#include + +int countocc(int arr[], int n, int x); + +void main() +{ + int arr[100], n, x, c; + printf("Enter the number of elements in the Array\n"); + scanf("%d", &n); + printf("Enter the %d elements\n", n); + for (int i = 0; i < n; i++) + { + scanf("%d", &arr[i]); + } + printf("Enter the number you want to check the Occurence\n"); + scanf("%d", &x); + c = countocc(arr, n, x); + printf("%d occured %d times", x, c); +} + +int countocc(int arr[], int n, int x) +{ + int c = 0; + for (int i = 0; i < n; i++) + { + if (x == arr[i]) + { + c++; + } + } + return c; +} \ No newline at end of file diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a10.c b/Week2/Solutions/Gantyada Tejesh Kumar/a10.c new file mode 100644 index 0000000..0a2a8d7 --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a10.c @@ -0,0 +1,23 @@ +#include + +void main() { + char str[100]; + int alphabets = 0, digits = 0, specials = 0, i; + + printf("Enter a string: "); + gets(str); + + for (i = 0; str[i] != '\0'; i++) { + if (str[i] >= 'a' && str[i] <= 'z') { + alphabets++; + } else if (str[i] >= '0' && str[i] <= '9') { + digits++; + } else { + specials++; + } + } + + printf("Total number of alphabets: %d\n", alphabets); + printf("Total number of digits: %d\n", digits); + printf("Total number of special characters: %d\n", specials); +} diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a2.c b/Week2/Solutions/Gantyada Tejesh Kumar/a2.c new file mode 100644 index 0000000..2448279 --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a2.c @@ -0,0 +1,30 @@ +#include +void main(){ + int arr1[100], arr2[100], size1, size2, i, j, merge[200]; + printf("Enter Array 1 Size: "); + scanf("%d", &size1); + printf("Enter Array 1 Elements: "); + for(i=0; i= 0; k--) { + printf("%d ", merge[k]); + } +} \ No newline at end of file diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a3.c b/Week2/Solutions/Gantyada Tejesh Kumar/a3.c new file mode 100644 index 0000000..4e396fc --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a3.c @@ -0,0 +1,34 @@ +#include + +void sort(int arr[], int n) { + int i, j, temp; + for (i = 0; i < n-1; i++) { + for (j = 0; j < n-i-1; j++) { + if (arr[j] > arr[j+1]) { + temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + } +} + +void main() { + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + int n = sizeof(arr)/sizeof(arr[0]); + int i; + + printf("Original array:\n"); + for (i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + printf("\n"); + + sort(arr, n); + + printf("Sorted array:\n"); + for (i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + +} \ No newline at end of file diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a4.c b/Week2/Solutions/Gantyada Tejesh Kumar/a4.c new file mode 100644 index 0000000..7bda311 --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a4.c @@ -0,0 +1,14 @@ +#include + +void main() { + int rows = 5, i, j, count = 1; + + for (i = 0; i <= rows; i++) { + for (j = 0; j < i; j++) { + printf("%d ", count); + count++; + } + printf("\n"); + } + + } diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a5.c b/Week2/Solutions/Gantyada Tejesh Kumar/a5.c new file mode 100644 index 0000000..46d55ca --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a5.c @@ -0,0 +1,16 @@ +#include + +void main() { + int arr1[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; + int arr2[10]; + + for (int i = 0; i < 10; i++) { + arr2[i] = arr1[i]; + } + + printf("Elements of arr2: "); + for (int i = 0; i < 10; i++) { + printf("%d ", arr2[i]); + } + +} diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a6.c b/Week2/Solutions/Gantyada Tejesh Kumar/a6.c new file mode 100644 index 0000000..f288f0f --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a6.c @@ -0,0 +1,25 @@ +#include + +void main() { + int n, i, j, mn, mc = 0; + printf("Enter the number of elements in the array: "); + scanf("%d", &n); + int arr[n]; + printf("Enter the elements of the array:\n"); + for (i = 0; i < n; i++) { + scanf("%d", &arr[i]); + } + for (i = 0; i < n; i++) { + int count = 0; + for (j = i; j < n; j++) { + if (arr[j] == arr[i]) { + count++; + } + } + if (count > mc) { + mc = count; + mn = arr[i]; + } + } + printf("The maximum occurring integer is %d", mn); +} diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a7.c b/Week2/Solutions/Gantyada Tejesh Kumar/a7.c new file mode 100644 index 0000000..70e9da7 --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a7.c @@ -0,0 +1,33 @@ +#include + +void moveNegative(int arr[], int n) { + int i, j = 0, temp; + for (i = 0; i < n; i++) { + if (arr[i] < 0) { + if (i != j) { + temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + j++; + } + } +} + +void main() { + int arr[] = {-4, 8, -5, 2, -3, 6, -1, 0}; + int n = sizeof(arr) / sizeof(arr[0]); + int i; + + printf("Original array: "); + for (i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + + moveNegative(arr, n); + + printf("\nArray with negative elements moved to one side: "); + for (i = 0; i < n; i++) { + printf("%d ", arr[i]); + } +} diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a8.c b/Week2/Solutions/Gantyada Tejesh Kumar/a8.c new file mode 100644 index 0000000..c175081 --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a8.c @@ -0,0 +1,32 @@ +#include +#include +# + +void main() +{ + char str[100]; + int i, len, vowel, consonant; + + printf("Enter any string: "); + gets(str); + + vowel = 0; + consonant = 0; + len = strlen(str); + + for(i=0; i='a' && str[i]<='z') + { + + if(str[i] =='a' || str[i]=='e' || str[i]=='i' || str[i]=='o' || str[i]=='u') + vowel++; + else + consonant++; + } + } + + printf("Total number of vowel = %d\n", vowel); + printf("Total number of consonant = %d\n", consonant); + +} \ No newline at end of file diff --git a/Week2/Solutions/Gantyada Tejesh Kumar/a9.c b/Week2/Solutions/Gantyada Tejesh Kumar/a9.c new file mode 100644 index 0000000..8937376 --- /dev/null +++ b/Week2/Solutions/Gantyada Tejesh Kumar/a9.c @@ -0,0 +1,14 @@ +#include + +void main() { + int rows = 5; + int i, j; + + for (i = 1; i <= rows; i++) { + for (j = rows; j >= i; j--) { + printf("* "); + } + printf("\n"); + } + +} \ No newline at end of file