From ecd3d394b31c840d3540705ce7f6ed372dcf9e59 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Mon, 13 Mar 2023 13:45:15 +0530 Subject: [PATCH 01/18] Update Assignment1.c --- Assignment1.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/Assignment1.c b/Assignment1.c index 36c24b5..4f73477 100644 --- a/Assignment1.c +++ b/Assignment1.c @@ -1,7 +1,50 @@ //Write a C program that allows the user to enter 'N' numbers and find the total positive numbers and total negative numbers using a for loop. -int main() + +#include + +int countPositiveNumbers(int* arr, int n) { - //add your code here - return 0; + int pos_count = 0; + int i; + for (i = 0; i < n; i++) { + if (arr[i] > 0) + pos_count++; + } + return pos_count; +} +int countNegativeNumbers(int* arr, int n) +{ + int neg_count = 0; + int i; + for (i = 0; i < n; i++) { + if (arr[i] < 0) + neg_count++; + } + return neg_count; +} +void printArray(int* arr, int n) +{ + int i; + + printf("Array: "); + for (i = 0; i < n; i++) { + printf("%d ", arr[i]); + } + printf("\n"); +} + int main() +{ + int arr[] = { 2, -1, 5, 6, 0, -3 }; + int n; + n = sizeof(arr) / sizeof(arr[0]); + + printArray(arr, n); + + printf("Count of Positive elements = %d\n", + countPositiveNumbers(arr, n)); + printf("Count of Negative elements = %d\n", + countNegativeNumbers(arr, n)); + + return 0; } From 661a2bab845ed52543581cbfad621b1375f5b867 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Tue, 21 Mar 2023 13:28:25 +0530 Subject: [PATCH 02/18] Update Assignment2.c --- Assignment2.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/Assignment2.c b/Assignment2.c index 6924883..929e6bf 100644 --- a/Assignment2.c +++ b/Assignment2.c @@ -1,7 +1,41 @@ //A number is said to be valid if it is divisible by 8. Write a program that allows the user to keep entering numbers as long as the input is valid and also displays a count of the valid numbers. Use a while loop to complete the task int main() -{ +{int n = str.Length; + + // Empty string + if (n == 0) + return false; + + // If there is single digit + if (n == 1) + return ((str[0] - '0') %8 == 0); + + // If there is double digit + if (n == 2) + return (((str[n - 2] - '0') * 10 + + (str[n - 1] - '0')) % 8 == 0); + + // If number formed by last three + // digits is divisible by 8 + int last = str[n - 1] - '0'; + int second_last = str[n - 2] - '0'; + int third_last = str[n - 3] - '0'; + + return ((third_last * 100 + second_last + * 10 + last) % 8 == 0); + } + + // Driver Code + public static void Main () + { + String str = "76952"; + if(check(str)) + Console.Write("Yes"); + else + Console.Write("No"); + } +} return 0; } From a8fec975285904a7d42524c52b291fec2d2cdd57 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Tue, 21 Mar 2023 13:31:05 +0530 Subject: [PATCH 03/18] Update Assignment3.c --- Assignment3.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/Assignment3.c b/Assignment3.c index ec41c9d..da1287b 100644 --- a/Assignment3.c +++ b/Assignment3.c @@ -1,7 +1,30 @@ //Can you help your digital design faculty in correcting the assignment on number conversions by writing a program to convert a decimal number to its binary equivalent using a while loop. //Example, lets say input is 7, output should be 111 -int main() -{ + + + int convert(long long); + +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +// function definition +int convert(long long n) { + int dec = 0, i = 0, rem; + + while (n!=0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + + return dec; +} return 0; } From 8a1f09ad5c850c245b894581545609aee07c30e7 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Tue, 21 Mar 2023 13:33:55 +0530 Subject: [PATCH 04/18] Update Assignment4.c --- Assignment4.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Assignment4.c b/Assignment4.c index c07310e..ce46ec9 100644 --- a/Assignment4.c +++ b/Assignment4.c @@ -2,6 +2,25 @@ int main() { + int mat[3][3], i, j, max; + printf("Enter any 3*3 matrix: "); + for(i=0; i<3; i++) + { + for(j=0; j<3; j++) + scanf("%d", &mat[i][j]); + } + max = mat[0][0]; + for(i=0; i<3; i++) + { + for(j=0; j<3; j++) + { + if(max Date: Tue, 21 Mar 2023 13:39:16 +0530 Subject: [PATCH 05/18] Update Assignment6.c --- Assignment6.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Assignment6.c b/Assignment6.c index 3943441..23cf259 100644 --- a/Assignment6.c +++ b/Assignment6.c @@ -2,5 +2,38 @@ int main() { + int countDistinct(int a[], int n) +{ + int i, j, count = 1; + + for (i = 1; i < n; i++) + { + for (j = 0; j < i; j++) + { + if (a[i] == a[j]) + { + break; + } + } + if (i == j) + { + count++; + } + } + return count; +} +int main() +{ + int n; + printf("Enter the number of elements \n"); + scanf("%d",&n); + + int a[n]; + printf("Enter the array elements : "); + for (int i=0;i Date: Tue, 21 Mar 2023 13:44:28 +0530 Subject: [PATCH 06/18] Update Assignment5.c --- Assignment5.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/Assignment5.c b/Assignment5.c index eca885a..c254815 100644 --- a/Assignment5.c +++ b/Assignment5.c @@ -4,5 +4,38 @@ int main() { + + static string studentRecord(String[, ] S, int N) + { + + // code here + int maxi = Int32.MinValue; + String result = ""; + for (int i = 0; i < N; i++) { + int avg = (Int32.Parse(S[i, 1]) + + Int32.Parse(S[i, 2]) + + Int32.Parse(S[i, 3])) + / 3; + if (avg > maxi) { + maxi = avg; + result = S[i, 0]; + } + else if (avg == maxi) { + result = result + " " + S[i, 0]; + } + } + return result + " " + maxi; + } + public static void Main(string[] args) + { + int N = 2; + String[, ] file + = { { "Shrikanth", "20", "30", "10" }, + { "Ram", "100", "50", "10" } }; + + Console.WriteLine(studentRecord(file, N)); + } +} + return 0; } From caacf9b033f829cca027acb42cda1f2493c927fa Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Tue, 21 Mar 2023 13:45:12 +0530 Subject: [PATCH 07/18] Update Assignment5.c --- Assignment5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assignment5.c b/Assignment5.c index c254815..254c727 100644 --- a/Assignment5.c +++ b/Assignment5.c @@ -30,7 +30,7 @@ int main() { int N = 2; String[, ] file - = { { "Shrikanth", "20", "30", "10" }, + = {"paras", "20", "30", "10" }, { "Ram", "100", "50", "10" } }; Console.WriteLine(studentRecord(file, N)); From 45174499762612cd0c5556379f95b8b2fb1c0690 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:32:28 +0530 Subject: [PATCH 08/18] Update Assignment7.c --- Assignment7.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Assignment7.c b/Assignment7.c index 324bd72..d504907 100644 --- a/Assignment7.c +++ b/Assignment7.c @@ -2,5 +2,27 @@ int main() { + char str[100]; + int len = 0; + + printf("Enter a string: "); + scanf("%s", str); + + // Find length of string + while (str[len] != '\0') { + len++; + } + + printf("Length of string: %d\n", len); + + // Reverse string + char rev_str[100]; + int i, j; + for (i = len - 1, j = 0; i >= 0; i--, j++) { + rev_str[j] = str[i]; + } + rev_str[j] = '\0'; + + printf("Reverse equivalent of string: %s\n", rev_str); return 0; } From 33ef05476306d62c912fc19a71e38deecae10666 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:33:13 +0530 Subject: [PATCH 09/18] Update Assignment8.c --- Assignment8.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Assignment8.c b/Assignment8.c index cc68105..e9566e2 100644 --- a/Assignment8.c +++ b/Assignment8.c @@ -4,5 +4,27 @@ int main() { + char str[100]; + printf("Enter a string: "); + scanf("%s", str); + selectionSort(str, strlen(str)); + printf("Sorted string: %s", str); + return 0; +} + +void selectionSort(char str[], int n) { + int i, j, min_idx; + char temp; + for (i = 0; i < n-1; i++) { + min_idx = i; + for (j = i+1; j < n; j++) { + if (str[j] < str[min_idx]) { + min_idx = j; + } + } + temp = str[i]; + str[i] = str[min_idx]; + str[min_idx] = temp; + } return 0; } From 3ac90a4e49cf0cc118c5d2999dfbff49b58006ab Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:34:53 +0530 Subject: [PATCH 10/18] Update Assignment9.c --- Assignment9.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Assignment9.c b/Assignment9.c index c6a9766..949c42e 100644 --- a/Assignment9.c +++ b/Assignment9.c @@ -5,8 +5,39 @@ //. m = 1 //. n = 1 + + #define MAX_SIZE 100 + int main() { - + char name[MAX_SIZE]; + int freq[26] = {0}; // Array to store frequency of each letter + + printf("Enter your name: "); + fgets(name, MAX_SIZE, stdin); + + int len = strlen(name); + + // Traverse through each character of the name + for(int i = 0; i < len; i++) + { + if(name[i] >= 'a' && name[i] <= 'z') + { + freq[name[i] - 'a']++; // Increment frequency of the corresponding letter + } + else if(name[i] >= 'A' && name[i] <= 'Z') + { + freq[name[i] - 'A']++; // Increment frequency of the corresponding letter + } + } + + // Display the frequency of each letter + for(int i = 0; i < 26; i++) + { + if(freq[i] != 0) + { + printf("%c - %d\n", 'a' + i, freq[i]); + } + } return 0; } From d7d56751136a56ca905a6c73921da0c5cedaeaea Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:35:59 +0530 Subject: [PATCH 11/18] Update Assignment10.c --- Assignment10.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Assignment10.c b/Assignment10.c index 81b569e..0398b7c 100644 --- a/Assignment10.c +++ b/Assignment10.c @@ -10,5 +10,37 @@ int findType(int n, int *) //complete this function } int main() { + int findType(int *arr, int n) { + int oddCount = 0; + int evenCount = 0; + + for(int i = 0; i < n; i++) { + if(arr[i] % 2 == 0) { + evenCount++; + } + else { + oddCount++; + } + } + + if(evenCount == n) { + printf("EVEN ARRAY\n"); + } + else if(oddCount == n) { + printf("ODD ARRAY\n"); + } + else { + printf("MIXED ARRAY\n"); + } +} + +int main() { + int arr1[] = {1,3,5,11,9}; + int arr2[] = {2,4,6,8,10}; + int arr3[] = {1,2,3,4,5,6}; + + findType(arr1, 5); + findType(arr2, 5); + findType(arr3, 6); return 0; } From 29db89858973c22dc4f7ff29bba265fcba53958d Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:36:38 +0530 Subject: [PATCH 12/18] Update Assignment11.c --- Assignment11.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Assignment11.c b/Assignment11.c index 6a751c9..435df8a 100644 --- a/Assignment11.c +++ b/Assignment11.c @@ -3,6 +3,17 @@ int main() { int N = 7; + binary = 0, place = 1, remainder; + + while (N> 0) { + remainder = N % 2; + binary += remainder * place; + place *= 10; + N /= 2; + } + + printf("Binary equivalent: %d", binary); + return 0; } From 5b4b9dd4f6e8f099e0f391dcd5d3ac0e106cfbc8 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:38:42 +0530 Subject: [PATCH 13/18] Update Assignment12.c --- Assignment12.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/Assignment12.c b/Assignment12.c index 0919e82..a887cde 100644 --- a/Assignment12.c +++ b/Assignment12.c @@ -1,6 +1,24 @@ //Input marks of 10 students in an array and then find the student with maximum marks -int main() -{ +#include + #define MAX_STUDENTS10 + +int main() { + int marks[MAX_STUDENTS]; + int max_marks = 0; + int max_index = 0; + + for (int i = 0; i < MAX_STUDENTS; i++) { + printf("Enter marks of student %d: ", i+1); + scanf("%d", &marks[i]); + + if (marks[i] > max_marks) { + max_marks = marks[i]; + max_index = i; + } + } + + printf("The student with maximum marks is student %d with %d marks.\n", + max_index+1, max_marks); return 0; } From e68e653f9d97a4f86396d0ddb1f31a53286f1b44 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:41:20 +0530 Subject: [PATCH 14/18] Update Assignment12.c --- Assignment12.c | 1 + 1 file changed, 1 insertion(+) diff --git a/Assignment12.c b/Assignment12.c index a887cde..a28a9ad 100644 --- a/Assignment12.c +++ b/Assignment12.c @@ -4,6 +4,7 @@ #define MAX_STUDENTS10 int main() { + int marks[MAX_STUDENTS]; int max_marks = 0; int max_index = 0; From 969248d7a5006d36ac96d55fe262027f220a07b1 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:41:46 +0530 Subject: [PATCH 15/18] Update Assignment10.c --- Assignment10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assignment10.c b/Assignment10.c index 0398b7c..ebc15fb 100644 --- a/Assignment10.c +++ b/Assignment10.c @@ -3,7 +3,7 @@ //if all elements in the array are even it is known as "EVEN ARRAY" //if both even and odd available it is known as MIXED array - +#include int findType(int n, int *) //complete this function { From eb7c15df3b63a529dba99e965d628a43bb3d880f Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:42:11 +0530 Subject: [PATCH 16/18] Update Assignment7.c --- Assignment7.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assignment7.c b/Assignment7.c index d504907..e224b6e 100644 --- a/Assignment7.c +++ b/Assignment7.c @@ -1,5 +1,5 @@ //Write a code find the length of a string and its reverse equivalent without using readymade c functions - +#include int main() { char str[100]; From 23e2e4cd3c53deb95d90b4cbe50565bc00c40855 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:43:09 +0530 Subject: [PATCH 17/18] Update Assignment8.c --- Assignment8.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assignment8.c b/Assignment8.c index e9566e2..678d877 100644 --- a/Assignment8.c +++ b/Assignment8.c @@ -1,7 +1,8 @@ //Write a C code to sort a string in alphabetical order //input: Anitha //output: Aahint - +#include +#include int main() { char str[100]; From 0ac280e867e93ecfe8536cbf9b44eca1c5d97d52 Mon Sep 17 00:00:00 2001 From: janvi7106 <127727329+janvi7106@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:44:19 +0530 Subject: [PATCH 18/18] Update Assignment9.c --- Assignment9.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Assignment9.c b/Assignment9.c index 949c42e..6db81dc 100644 --- a/Assignment9.c +++ b/Assignment9.c @@ -6,6 +6,8 @@ //. n = 1 +#include +#include #define MAX_SIZE 100 int main()