├── Misc ├── Endsem.pdf ├── Midsem.pdf ├── Quiz 1.docx ├── Quiz 2.pdf └── Practice Lab 1.pdf ├── Assignment_01 ├── CSD Assignment 1.pdf ├── p3i.c ├── p3iii.c ├── p3ii.c ├── p3iv.c ├── p5.c ├── p8.c ├── p6.c ├── p7.c ├── p9.c ├── p10.c └── p4.c ├── Assignment_02 ├── CSD Assignment 2.pdf ├── p6.c ├── p3.c ├── p4.c ├── p2.c ├── p8.c ├── p7.c ├── p5.c ├── p12.c ├── p10.c ├── p9.c ├── p11.c └── p1.c ├── Assignment_03 ├── CSD Assignment 3.pdf ├── p2.c ├── p1.c ├── p7.c ├── p3.c ├── p8.c ├── p6.c ├── p4.c └── p5.c ├── Assignment_04 ├── CSD Assignment 4.pdf ├── p5.c ├── p3.c ├── p2.c ├── p4.c ├── p7.c ├── p1.c └── p6.c ├── Assignment_05 ├── CSD Assignment 5.pdf ├── p6.c ├── p7.c ├── p3.c ├── p1.c ├── p8.c └── p2.c ├── Assignment_06 ├── CSD Assignment 6.pdf ├── p2.c ├── p4.c ├── p5.c ├── p1.c ├── p6.c ├── p8.c ├── p7.c ├── p9.c └── p3.c ├── Assignment_07 ├── CSD Assignment 7.pdf ├── p4.c ├── p1.c ├── p3.c ├── p5.c ├── p6.c └── p2.c ├── Assignment_08 ├── CSD Assignment 8.pdf ├── p6.c ├── p10.c ├── p4.c ├── p8.c ├── p3.c ├── p5.c ├── p9.c ├── p1.c ├── p2.c └── p7.c ├── Assignment_09 ├── CSD Assignment 9.pdf ├── p5.c ├── p2.c ├── p1.c ├── p4.c ├── p3.c └── p6.c ├── Assignment_10 ├── CSD Assignment 10.pdf ├── p2.c ├── p3.c ├── p4.c ├── p1.c ├── p7.c ├── p5.c └── p6.c ├── Assignment_11 ├── CSD Assignment 11.pdf ├── p5.c ├── p1.c ├── p3.c ├── p2.c └── p4.c ├── Assignment_12 ├── CSD Assignment 12.pdf ├── p3.c ├── p2.c ├── p1.c └── p4.c ├── LICENSE └── README.md /Misc/Endsem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Misc/Endsem.pdf -------------------------------------------------------------------------------- /Misc/Midsem.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Misc/Midsem.pdf -------------------------------------------------------------------------------- /Misc/Quiz 1.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Misc/Quiz 1.docx -------------------------------------------------------------------------------- /Misc/Quiz 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Misc/Quiz 2.pdf -------------------------------------------------------------------------------- /Misc/Practice Lab 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Misc/Practice Lab 1.pdf -------------------------------------------------------------------------------- /Assignment_01/CSD Assignment 1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_01/CSD Assignment 1.pdf -------------------------------------------------------------------------------- /Assignment_02/CSD Assignment 2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_02/CSD Assignment 2.pdf -------------------------------------------------------------------------------- /Assignment_03/CSD Assignment 3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_03/CSD Assignment 3.pdf -------------------------------------------------------------------------------- /Assignment_04/CSD Assignment 4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_04/CSD Assignment 4.pdf -------------------------------------------------------------------------------- /Assignment_05/CSD Assignment 5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_05/CSD Assignment 5.pdf -------------------------------------------------------------------------------- /Assignment_06/CSD Assignment 6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_06/CSD Assignment 6.pdf -------------------------------------------------------------------------------- /Assignment_07/CSD Assignment 7.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_07/CSD Assignment 7.pdf -------------------------------------------------------------------------------- /Assignment_08/CSD Assignment 8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_08/CSD Assignment 8.pdf -------------------------------------------------------------------------------- /Assignment_09/CSD Assignment 9.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_09/CSD Assignment 9.pdf -------------------------------------------------------------------------------- /Assignment_10/CSD Assignment 10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_10/CSD Assignment 10.pdf -------------------------------------------------------------------------------- /Assignment_11/CSD Assignment 11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_11/CSD Assignment 11.pdf -------------------------------------------------------------------------------- /Assignment_12/CSD Assignment 12.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnarchistHoneybun/CSD101/HEAD/Assignment_12/CSD Assignment 12.pdf -------------------------------------------------------------------------------- /Assignment_08/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int count = 1; 5 | 6 | void main() { 7 | 8 | count++; 9 | printf("main called %d times.\n", count-1); 10 | main(); 11 | } 12 | -------------------------------------------------------------------------------- /Assignment_01/p3i.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf(" * \n"); 7 | printf(" * * \n"); 8 | printf(" * * \n"); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Assignment_01/p3iii.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf(" _______ \n"); 7 | printf("| | \n"); 8 | printf("| | \n"); 9 | printf(" _______ \n"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Assignment_08/p10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | int i = 5, *p; 7 | p = &i; 8 | printf("value before changing: %d\n", i); 9 | *p += 1; 10 | printf("value after changing: %d", i); 11 | } 12 | -------------------------------------------------------------------------------- /Assignment_01/p3ii.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf(" /\\ \n"); 7 | printf(" / \\ \n"); 8 | printf(" / \\ \n"); 9 | printf(" ________ \n"); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Assignment_04/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | for(int i=1;i<=10;i++){ 7 | for(int j=1;j<=i;j++){ 8 | printf("*"); 9 | } 10 | printf("\n"); 11 | } 12 | 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /Assignment_06/p2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int sub5(int a){ 5 | a-=5; 6 | return a; 7 | 8 | } 9 | 10 | int main() 11 | { 12 | int a; 13 | printf("Enter number:"); 14 | scanf("%d",&a); 15 | a=sub5(a); 16 | printf("%d",a); 17 | } 18 | -------------------------------------------------------------------------------- /Assignment_01/p3iv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("Initials are R S \n"); 7 | printf(" |**** ++++++ \n"); 8 | printf(" | + + \n"); 9 | printf(" |++++ ++++++ \n"); 10 | printf(" | \\ + \n"); 11 | printf(" | \\ ++++++ \n"); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Assignment_03/p2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int a, i; 7 | printf("Factorial calculator!\n"); 8 | printf("Enter a number to calculate factorial..."); 9 | scanf("%d", &a); 10 | i=a-1; 11 | while(i>0) 12 | { 13 | a=a*i; 14 | i--; 15 | } 16 | printf("The factorial of given number is: %d", a); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Assignment_06/p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | float hypotenuse(float a, float b){ 5 | float c=sqrt(pow(a,2)+pow(b,2)); 6 | return c; 7 | } 8 | 9 | int main() 10 | { 11 | float a,b; 12 | printf("Enter side a:"); 13 | scanf("%f",&a); 14 | printf("Enter side b:"); 15 | scanf("%f",&b); 16 | float c=hypotenuse(a,b); 17 | printf("The hypotenuse is: %.2f",c); 18 | } 19 | -------------------------------------------------------------------------------- /Assignment_06/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void func(int a){ 5 | for(int i=1;i<=a;i++){ 6 | for(int j=1;j<=a;j++){ 7 | printf("* "); 8 | } 9 | printf("\n"); 10 | } 11 | 12 | 13 | } 14 | 15 | 16 | int main() 17 | { 18 | int a; 19 | printf("Enter side length of square->"); 20 | scanf("%d",&a); 21 | func(a); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Assignment_05/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int x; 7 | int arr[]={1, 9, 8, 0, 8, 2, 3, 8, 4, 9}; 8 | int len=sizeof(arr)/sizeof(arr[0]); 9 | for(int i=0;i 2 | #include 3 | 4 | int main() 5 | { 6 | char array[26]; 7 | int i=0; 8 | char let='A'; 9 | printf("i + ch array creator!\n"); 10 | while(i<26) 11 | { 12 | array[i]=i+let; 13 | i++; 14 | let++; 15 | } 16 | i=0; 17 | while(i<26) 18 | { 19 | printf("%d\n", array[i]); 20 | i++; 21 | } 22 | printf("Fin!"); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Assignment_04/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int i, r, s, a; 7 | i=0; 8 | printf("Age checker\n"); 9 | printf("Enter Ram's age->"); 10 | scanf("%d", &r); 11 | printf("Enter Shyam's age->"); 12 | scanf("%d", &s); 13 | printf("Enter Ajay's age->"); 14 | scanf("%d", &a); 15 | i=(r<=s && r<=a)?r:((s<=r && s<=a)?s:a); 16 | printf("The youngest age is %d.", i); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Assignment_02/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a; 7 | printf("This program checks if a letter is uppercase or lowercase\n"); 8 | printf("Enter letter to check..."); 9 | scanf("%c", &a); 10 | if(a>=65 && a<=90) 11 | { 12 | printf("Entered letter is uppercase."); 13 | } 14 | else if(a>=97 && a<=122) 15 | { 16 | printf("Entered letter is lowercase."); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Assignment_08/p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int find2Power(int n) { 5 | if (n == 0) { 6 | return 1; 7 | } 8 | 9 | return 2 * find2Power(n-1); 10 | } 11 | 12 | void main() { 13 | int n; 14 | printf("enter n: "); 15 | scanf("%d", &n); 16 | 17 | if (n < 0) { 18 | printf("n must be positive or 0"); 19 | } else { 20 | int power = find2Power(n); 21 | printf("nth power of 2: %d", power); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Assignment_02/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int a; 7 | printf("This program checks if an integer is divisible by both 5 and 11.\n"); 8 | printf("Enter integer to be checked..."); 9 | scanf("%d", &a); 10 | if (0==a%5 && 0==a%11) 11 | { 12 | printf("Number is divisible by both 5 and 11!"); 13 | } 14 | else 15 | { 16 | printf("Number is not divisible by both 5 and 11"); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Assignment_08/p8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | int i, *p, **q; 7 | printf("Enter i: "); 8 | scanf("%d", &i); 9 | p = &i; 10 | q = &p; 11 | 12 | printf("Address of i = %u or p=%u or *q=%u\n", &i, p, *q); 13 | printf("Address of p = %u or q= %u\n", &p, q); 14 | printf("Address of q = %u\n", &q); 15 | printf("Value of i = %d or *(&i) = %d or *p = %d or **q=%d\n", i, *(&i), *p, **q); 16 | printf("Value of q = %d\n", q); 17 | } 18 | -------------------------------------------------------------------------------- /Assignment_06/p1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int main() 5 | { 6 | int x; 7 | x=fabs(7.5); 8 | printf("%d\n",x); 9 | x=floor(7.5); 10 | printf("%d\n",x); 11 | x=fabs(0.0); 12 | printf("%d\n",x); 13 | x=ceil(0.0); 14 | printf("%d\n",x); 15 | x=fabs(-6.4); 16 | printf("%d\n",x); 17 | x=ceil(-fabs(-8+floor(-5.5))); 18 | printf("%d\n",x); 19 | /* Answers: 20 | 7 21 | 7 22 | 0 23 | 0 24 | 6 25 | -14 26 | */ 27 | } 28 | -------------------------------------------------------------------------------- /Assignment_08/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int findSquareSum(int n) { 5 | 6 | if(n == 1) { 7 | return 1; 8 | } 9 | 10 | return n*n + findSquareSum(n-1); 11 | } 12 | 13 | void main() { 14 | int n; 15 | printf("enter n: "); 16 | scanf("%d", &n); 17 | 18 | if (n < 1) { 19 | printf("n must be greater than 0"); 20 | } else { 21 | int sum = findSquareSum(n); 22 | printf("sum of first n squares: %d", sum); 23 | } 24 | 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Assignment_09/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void sumup(int *ar, int *len, int *sum){ 5 | for(int i=0;i<*len;i++){ 6 | *sum += *(ar+i); 7 | } 8 | } 9 | 10 | int main() 11 | { 12 | int sum, ar[10]; 13 | sum = 0; 14 | int len = sizeof(ar)/sizeof(int); 15 | for(int i=0;i<10;i++){ 16 | printf("Enter element %d: ", i+1); 17 | scanf("%d", &ar[i]); 18 | } 19 | sumup(ar, &len, &sum); 20 | printf("The sum is: %d", sum); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Assignment_02/p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a; 7 | printf("This program checks if a letter is a vowel or not.\n"); 8 | printf("Enter letter to check..."); 9 | scanf("%c", &a); 10 | if (a=='A' ||a=='E' ||a=='I' ||a=='O' ||a=='U' ||a=='a' ||a=='e' ||a=='i' ||a=='o' ||a=='u') 11 | { 12 | printf("Entered letter is a vowel"); 13 | } 14 | else 15 | { 16 | printf("Entered letter is a consonant"); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Assignment_08/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int findNthTerm(int n) { 5 | if (n < 3) { 6 | return n; 7 | } 8 | 9 | return findNthTerm(n-1) + findNthTerm(n-2) + findNthTerm(n-3); 10 | } 11 | 12 | void main() { 13 | int n; 14 | printf("enter n: "); 15 | scanf("%d", &n); 16 | 17 | if (n < 0) { 18 | printf("n must be positive or 0"); 19 | } else { 20 | int termN = findNthTerm(n); 21 | printf("nth term of relation: %d", termN); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Assignment_07/p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int binary_conversion(int); 5 | 6 | int main() 7 | { 8 | int num, bin; 9 | 10 | printf("Enter a decimal number: "); 11 | scanf("%d", &num); 12 | bin = binary_conversion(num); 13 | printf("The binary equivalent of %d is %d\n", num, bin); 14 | } 15 | 16 | int binary_conversion(int num) 17 | { 18 | if (num == 0) 19 | { 20 | return 0; 21 | } 22 | else 23 | { 24 | return (num % 2) + 10 * binary_conversion(num / 2); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Assignment_08/p9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int i, *pi; 7 | float f, *pf; 8 | char c, *pc; 9 | printf("Enter a character: "); 10 | scanf("%c", &c); 11 | pc = &c; 12 | printf("Enter an integer: "); 13 | scanf("%d", &i); 14 | pi = &i; 15 | printf("Enter a float: "); 16 | scanf("%f", &f); 17 | pf = &f; 18 | printf("int: %d address: %u\n", i,pi); 19 | printf("float: %f address: %u\n", f,pf); 20 | printf("char: %c address: %u\n", c,pc); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Assignment_02/p2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | float a; 7 | printf("This program checks if a number is positive, negative, or zero!\n"); 8 | printf("Enter number to check..."); 9 | scanf("%f", &a); 10 | if (a>0.000000) 11 | { 12 | printf("Number entered is positive"); 13 | } 14 | else if (a==0) 15 | { 16 | printf("Number entered is zero"); 17 | } 18 | else if (a<0) 19 | { 20 | printf("Number entered is negative"); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Assignment_05/p7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int r,c; 7 | r=0; 8 | c=0; 9 | int arr[]={34, 73, 89, 76, 85, 59, 100, 7, 0, 34}; 10 | int len=sizeof(arr)/sizeof(arr[0]); 11 | for(int i=0;i0;j--){ 13 | r=arr[i]%j; 14 | if(r==0){ 15 | c++; 16 | } 17 | } 18 | if(c==2){ 19 | printf("%d, pos->%d\n", arr[i],i+1); 20 | } 21 | c=0; 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Assignment_01/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int a,b,rem; 7 | printf("This program checks if first number is a multiple of the second \n\n"); 8 | printf("Enter first number"); 9 | scanf("%d", &a); 10 | printf("Enter second number"); 11 | scanf("%d", &b); 12 | rem=a%b; 13 | if(rem==0) 14 | { 15 | printf("%d is a multiple of %d . \n", a, b); 16 | } 17 | else if(rem!=0) 18 | { 19 | printf("%d is not a multiple of %d . \n", a, b); 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Assignment_09/p2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void factorial(int *ptr_n, int *ptr_temp){ 5 | *ptr_temp *= *ptr_n; 6 | //printf("%d\n", *ptr_temp); 7 | *ptr_n-=1; 8 | if(*ptr_n > 1){ 9 | factorial(ptr_n, ptr_temp); 10 | } 11 | } 12 | 13 | int main() 14 | { 15 | int n, temp, *ptr_n, *ptr_temp; 16 | printf("Enter number to compute factorial: "); 17 | scanf("%d", &n); 18 | ptr_n = &n; 19 | temp = 1; 20 | ptr_temp = &temp; 21 | factorial(ptr_n, ptr_temp); 22 | printf("The factorial is: %d", temp); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Assignment_06/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int multiple(int ar1,int ar2){ 5 | if(ar2%ar1==0){ 6 | return 1; 7 | }else{ 8 | return 0; 9 | } 10 | 11 | 12 | } 13 | 14 | 15 | int main() 16 | { 17 | int ar[6][2]={{2,1},{2,5},{2,8},{3,9},{13,65},{80,9}}; 18 | for(int i=0;i<6;i++){ 19 | if(multiple(ar[i][0],ar[i][1])){ 20 | printf("%d is a multiple of %d.\n",ar[i][1],ar[i][0]); 21 | }else{ 22 | printf("%d is not a multiple of %d.\n",ar[i][1],ar[i][0]); 23 | 24 | } 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Assignment_02/p8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | float a,b,c; 7 | printf("This program checks the validity of a triangle\n"); 8 | printf("Enter length of side A..."); 9 | scanf("%f", &a); 10 | printf("Enter length of side B..."); 11 | scanf("%f", &b); 12 | printf("Enter length of side C..."); 13 | scanf("%f", &c); 14 | if (a 2 | #include 3 | 4 | int main() 5 | { 6 | int i,j,m,k; 7 | i=1; 8 | j=2; 9 | k=3; 10 | m=2; 11 | 12 | printf("%d\n", i == 1); 13 | printf("%d\n", j == 3); 14 | printf("%d\n", i >= 1 && j < 4 ); 15 | printf("%d\n", m <= 99 && k < m); 16 | printf("%d\n", j >= 1 || k == m); 17 | printf("%d\n", k+m < j || 3 - j >= k); 18 | printf("%d\n", !m); 19 | printf("%d\n", !(j - m)); 20 | printf("%d\n", !(k > m)); 21 | printf("%d\n", !(j > k)); 22 | /* 23 | 1 24 | 0 25 | 1 26 | 0 27 | 1 28 | 0 29 | 0 30 | 1 31 | 0 32 | 1 33 | */ 34 | } 35 | -------------------------------------------------------------------------------- /Assignment_04/p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int main() 6 | { 7 | char c; 8 | printf("Character Type Determiner!\n"); 9 | printf("Enter character to check->"); 10 | scanf("%c", &c); 11 | if(c>=65 && c<=90){ 12 | printf("Upper-Case character"); 13 | }else if(c>=97 && c<=122){ 14 | printf("Lower-Case character"); 15 | }else if(c>=45 &&c<=57){ 16 | printf("Digit character"); 17 | }else if((c>=0 && c<=47)||(c>=58 && c<=64)||(c>=91 && c<=96)||(c>=123 && c<=127)){ 18 | printf("Special character"); 19 | } 20 | 21 | 22 | 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Assignment_10/p2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | int ar[5]={1,2,3,4,5}; 7 | int (*p)[5]; 8 | p=ar; 9 | printf("Original array: "); 10 | for(int j=0;j<5;j++){ 11 | printf("%d ", ar[j]); 12 | } 13 | printf("\n"); 14 | for(int i=0;i<5;i++){ 15 | *(*p+i)+=5; 16 | } 17 | printf("Printing with array expression: "); 18 | for(int j=0;j<5;j++){ 19 | printf("%d ", ar[j]); 20 | } 21 | printf("\n"); 22 | printf("Printing with pointer expression: "); 23 | for(int j=0;j<5;j++){ 24 | printf("%d ", *(*p+j)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Assignment_06/p8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int flip(){ 6 | 7 | float a=1.0; 8 | float x = (float)rand()/(float)(RAND_MAX/a); 9 | if(round(x)==1.000000){ 10 | return 1; 11 | }else if(round(x)==1.000000){ 12 | return 0; 13 | } 14 | 15 | } 16 | int main() 17 | { 18 | srand(time(NULL)); 19 | int head,tail; 20 | head=tail=0; 21 | for(int i=1;i<101;i++){ 22 | if(flip()){ 23 | head++; 24 | }else{ 25 | tail++; 26 | } 27 | 28 | } 29 | printf("Number of Heads: %d\nNumber of Tails: %d",head,tail); 30 | } 31 | -------------------------------------------------------------------------------- /Assignment_08/p1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void circularShift(int *x, int *y, int *z) { 5 | int temp; 6 | temp = *z; 7 | *z = *y; 8 | *y = *x; 9 | *x = temp; 10 | } 11 | 12 | void main() { 13 | int x,y,z; 14 | printf("Enter x: "); 15 | scanf("%d", &x); 16 | 17 | printf("Enter y: "); 18 | scanf("%d", &y); 19 | 20 | printf("Enter z: "); 21 | scanf("%d", &z); 22 | 23 | printf("Before circular shift: \n x = %d, y = %d, z = %d\n", x, y, z); 24 | 25 | circularShift(&x, &y, &z); 26 | 27 | printf("After circular shift: \n x = %d, y = %d, z = %d\n", x, y, z); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Assignment_09/p1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void circularShift(int *x, int *y, int *z) { 5 | int temp; 6 | temp = *z; 7 | *z = *y; 8 | *y = *x; 9 | *x = temp; 10 | } 11 | 12 | void main() { 13 | int x,y,z; 14 | printf("Enter x: "); 15 | scanf("%d", &x); 16 | 17 | printf("Enter y: "); 18 | scanf("%d", &y); 19 | 20 | printf("Enter z: "); 21 | scanf("%d", &z); 22 | 23 | printf("Before circular shift: \n x = %d, y = %d, z = %d\n", x, y, z); 24 | 25 | circularShift(&x, &y, &z); 26 | 27 | printf("After circular shift: \n x = %d, y = %d, z = %d\n", x, y, z); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Assignment_07/p1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int large(int arr[],int big, int start, int len); 5 | 6 | int main() 7 | { 8 | int arr[]={6, 6, 7, 4, 2, 5, 3, 6, 1, 2, 1, 4, 15, 9, 2, 2, 7, 1, 5, 7}; 9 | int big=0; 10 | int start=0; 11 | int len= sizeof(arr)/sizeof(int); 12 | big=large(arr,big,start,len); 13 | printf("%d\n",big); 14 | 15 | 16 | return 0; 17 | } 18 | 19 | int large(int arr[],int big,int start,int len){ 20 | if(start==len){ 21 | return big; 22 | } 23 | if(arr[start]>=big){ 24 | big=arr[start]; 25 | } 26 | start++; 27 | large(arr,big,start,len); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Assignment_03/p7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int n; 7 | char code[255]; 8 | printf("Code Breaker!\n"); 9 | printf("Enter code-->"); 10 | n=0; 11 | while(n<255) 12 | { 13 | scanf("%c", &code[n]); 14 | if(code[n]=='\n') 15 | {break;} 16 | n++; 17 | } 18 | n=0; 19 | while(n<255 && code[n]!='\n') 20 | { 21 | code[n]=code[n]-3; 22 | n++; 23 | } 24 | printf("The decoded result is :"); 25 | n=0; 26 | while(n<255 && code[n]!='\n') 27 | { 28 | printf("%c", code[n]); 29 | n++; 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Assignment_01/p8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int year, rem; 7 | printf("This program checks if an year is leap.\n"); 8 | printf("Input year to be checked: "); 9 | scanf("%d", &year); 10 | if(year%4==0){ 11 | if(year%100==0){ 12 | if(year%400==0){ 13 | printf("Year is a leap year."); 14 | }else{ 15 | printf("Year is not a leap year."); 16 | } 17 | }else{ 18 | printf("Year is a leap year."); 19 | } 20 | }else{ 21 | printf("Year is not a leap year."); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Assignment_02/p7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int a; 7 | printf("This program prints number of days in a month\n"); 8 | printf("Enter month no. (Jan=1, Feb=2, etc.)..."); 9 | scanf("%d", &a); 10 | if (a==1 ||a==3 ||a==5 ||a==7 ||a==8 ||a==10 ||a==12) 11 | { 12 | printf("Given month has 31 days."); 13 | } 14 | else if (a==4 ||a==6 ||a==9 ||a==11) 15 | { 16 | printf("Given month has 30 days."); 17 | } 18 | else if (a==2) 19 | { 20 | printf("Given month has 27/28 days"); 21 | } 22 | else 23 | { 24 | printf("data out of bounds"); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Assignment_02/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char a; 7 | printf("This program checks if a character is a letter, number, or special character\n"); 8 | printf("Enter character to check..."); 9 | scanf("%c", &a); 10 | if (a>=48 && a<=57) 11 | { 12 | printf("Entered character is a number."); 13 | } 14 | else if((a>=33 && a<=47) || (a>=58 && a<=64) || (a>=91 && a<=96) || (a>=123 && a<=126)) 15 | { 16 | printf("Entered character is a special character."); 17 | } 18 | else if((a>=65 && a<=90) || (a>=97 && a<=122)) 19 | { 20 | printf("Entered character is a letter."); 21 | } 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Assignment_01/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | printf("%d is the integer equivalent of A \n", 'A'); 7 | printf("%d is the integer equivalent of B \n", 'B'); 8 | printf("%d is the integer equivalent of C \n", 'C'); 9 | printf("%d is the integer equivalent of a \n", 'a'); 10 | printf("%d is the integer equivalent of b \n", 'b'); 11 | printf("%d is the integer equivalent of c \n", 'c'); 12 | printf("%d is the integer equivalent of * \n", '*'); 13 | printf("%d is the integer equivalent of %% \n", '%'); 14 | printf("%d is the integer equivalent of \\ \n", '/'); 15 | printf("%d is the integer equivalent of blank space \n", ' '); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Assignment_02/p12.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | float unit, bill, sbill; 7 | printf("This program calculates electricity bill!\n"); 8 | printf("Input number of units of electricity used..."); 9 | scanf("%f", &unit); 10 | if(unit<=50) 11 | { 12 | bill=unit*0.50; 13 | } 14 | else if(unit<=150) 15 | { 16 | bill=((unit-100)*0.75)+25; 17 | } 18 | else if(unit<=250) 19 | { 20 | bill=((unit-150)*1.20)+100; 21 | } 22 | else if(unit>250) 23 | { 24 | bill=((unit-250)*1.5)+220; 25 | } 26 | sbill=bill+(bill*0.20); 27 | printf("The electricity bill is %f", sbill); 28 | 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Assignment_05/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int ar[]={1, 2, 9, 1, 7, 4, 4, 4, 5, 9, 3, 9, 2, 1, 6, 1, 7, 5, 2, 8}; 7 | int len=20; 8 | printf("The array is {"); 9 | for(int k=0;k1;j--){ 15 | if((ar[i]==ar[j]) && (ar[i+1]==ar[j-1]) && (ar[i+2]==ar[j-2])){ 16 | printf("sub-array start and end: %d %d\n", i, i+2); 17 | printf("sub-array(reverse) start and end: %d %d\n", j, j-2); 18 | } 19 | } 20 | } 21 | 22 | 23 | 24 | 25 | 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Assignment_04/p7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int i; 7 | printf("To print number of days in a month!\n"); 8 | printf("Enter month number(January=1, February=2, etc.)-->"); 9 | scanf("%d", &i); 10 | switch (i){ 11 | case 1: 12 | case 3: 13 | case 5: 14 | case 7: 15 | case 8: 16 | case 10: 17 | case 12: printf("This month has 31 days."); 18 | break; 19 | case 2: printf("This month has 28 days, but 29 days in a leap year."); 20 | break; 21 | case 4: 22 | case 6: 23 | case 9: 24 | case 11: printf("This month has 30 days."); 25 | break; 26 | default: printf("Invalid Input"); 27 | 28 | 29 | } 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Assignment_01/p7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int amount, x1, x2, x3, x4, x5, x6, sum; 7 | printf("This program prints the number of notes required for a certain amount of money\n"); 8 | printf("Available denominations 1, 2, 5, 10, 50, 100. \n"); 9 | printf("Enter amount to calculate for..."); 10 | scanf("%d", &amount); 11 | x1=amount/100; 12 | amount=amount%100; 13 | x2=amount/50; 14 | amount=amount%50; 15 | x3=amount/10; 16 | amount=amount%10; 17 | x4=amount/5; 18 | amount=amount%5; 19 | x5=amount/2; 20 | amount=amount%2; 21 | x6=amount/1; 22 | sum=x1+x2+x3+x4+x5+x6; 23 | printf("The number of notes required are %d", sum); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Assignment_01/p9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | float a, b, area, peri; 7 | printf("This program checks if the area of a triangle is more than the perimeter!\n"); 8 | printf("Enter the side lengths of the triangle...\n"); 9 | scanf("%f%f", &a, &b); 10 | area=a*b; 11 | peri=2*(a+b); 12 | printf("The perimeter is %f \n", peri); 13 | printf("The area is %f \n", area); 14 | if (area==peri) 15 | { 16 | printf("Area is not greater than perimeter"); 17 | } 18 | else if(areaperi) 23 | { 24 | printf("Area is greater than perimeter"); 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Assignment_03/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int a, b, i, ctr1, ctr2, hcf, lcm; 7 | printf("This program calculates HCF and LCM of given two numbers!\n"); 8 | printf("Enter first number..."); 9 | scanf("%d", &a); 10 | printf("Enter second number..."); 11 | scanf("%d", &b); 12 | if(a>=b) 13 | { 14 | i=a; 15 | } 16 | else 17 | { 18 | i=b; 19 | } 20 | while(i>0) 21 | { 22 | hcf=i; 23 | ctr1=a%i; 24 | ctr2=b%i; 25 | i--; 26 | if(ctr1==0 && ctr2==0) 27 | { 28 | break; 29 | } 30 | 31 | } 32 | printf("The HCF is %d\n", hcf); 33 | lcm=(a*b)/hcf; 34 | printf("The LCM is %d", lcm); 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /Assignment_07/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int rev(int, int); 6 | 7 | int main() 8 | { 9 | int num, result; 10 | int length = 0, temp; 11 | 12 | printf("Enter an integer number to reverse: "); 13 | scanf("%d", &num); 14 | temp = num; 15 | while (temp != 0) 16 | { 17 | length++; 18 | temp = temp / 10; 19 | } 20 | result = rev(num, length); 21 | if(num==result){ 22 | printf("The reverse of %d is %d.\n", num, result); 23 | } 24 | return 0; 25 | } 26 | 27 | int rev(int num, int len) 28 | { 29 | if (len == 1) 30 | { 31 | return num; 32 | } 33 | else 34 | { 35 | return (((num % 10) * pow(10, len - 1)) + rev(num / 10, --len)); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Assignment_06/p7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int quotient(int a,int b); 6 | int remain(int a,int b); 7 | void split(int input,int length); 8 | 9 | int main() 10 | { 11 | int input; 12 | printf("Input number between 1 and 32767->"); 13 | scanf("%d",&input); 14 | int length = snprintf( NULL, 0, "%d", input); 15 | split(input,length); 16 | return 0; 17 | } 18 | 19 | int quotient(int a,int b){ 20 | int q=a/b; 21 | return q; 22 | } 23 | int remain(int a,int b){ 24 | int r=a%b; 25 | return r; 26 | } 27 | void split(int input,int length){ 28 | int cut; 29 | for(int i=length;i>0;i--){ 30 | cut=round(pow(10,i-1)); 31 | printf("%d ",quotient(input,cut)); 32 | input=remain(input,cut); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Assignment_03/p8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int i, j, k, r; 7 | printf("Zero sorter!\n"); 8 | printf("Enter array length: "); 9 | scanf("%d", &i); 10 | int ar[i]; 11 | printf("Enter array elements--->\n"); 12 | while(j 2 | #include 3 | 4 | int main() 5 | { 6 | int input, inputcopy, inputr, x1, x2, x3, x4, x5; 7 | printf("This program checks if a five digit number is a palindrome!\n"); 8 | printf("Enter five digit number to be checked..."); 9 | scanf("%d", &input); 10 | inputcopy=input; 11 | x1=(input%10)*10000; 12 | input=input/10; 13 | x2=(input%10)*1000; 14 | input=input/10; 15 | x3=(input%10)*100; 16 | input=input/10; 17 | x4=(input%10)*10; 18 | input=input/10; 19 | x5=input; 20 | inputr=x1+x2+x3+x4+x5; 21 | if(inputr==inputcopy) 22 | { 23 | printf("Number is a palindrome."); 24 | } 25 | else 26 | { 27 | printf("Number is not a palindrome."); 28 | } 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Assignment_10/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int ar[2][3][2] = {{{1,2},{3,4},{15,5}},{{6,7},{7,8},{8,9}}}; 7 | for(int i=0;i<2;i++){ 8 | for(int j=0;j<3;j++){ 9 | for(int k=0;k<2;k++){ 10 | printf("(%d,%d,%d) = %d ", i+1, j+1, k+1, *(*(*(ar+i)+j)+k)); 11 | } 12 | printf("\n"); 13 | } 14 | printf("\n"); 15 | } 16 | int big = 0; 17 | for(int i=0;i<2;i++){ 18 | for(int j=0;j<3;j++){ 19 | for(int k=0;k<2;k++){ 20 | if(*(*(*(ar+i)+j)+k) >= big){ 21 | big = *(*(*(ar+i)+j)+k); 22 | } 23 | } 24 | } 25 | } 26 | printf("Biggest number in above 3-d array is: %d", big); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Assignment_03/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int ar[20], a, i, j; 7 | printf("Array checker!\n"); 8 | printf("Enter array elements\n"); 9 | i=0; 10 | j=0; 11 | while(i<20) 12 | { 13 | printf("Enter element %d--->", i+1); 14 | scanf("%d", &ar[i]); 15 | i++; 16 | } 17 | i=0; 18 | printf("Enter number to search for..."); 19 | scanf("%d", &a); 20 | while(i<20) 21 | { 22 | if(a==ar[i]) 23 | { 24 | j++; 25 | } 26 | i++; 27 | } 28 | if(j==0) 29 | { 30 | printf("The number %d is not present in array :(", a); 31 | } 32 | else 33 | { 34 | printf("The number %d appears in given array %d times", a,j); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Assignment_07/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int rev(int, int); 6 | 7 | int main() 8 | { 9 | int num, result; 10 | int length = 0, temp; 11 | 12 | printf("Enter an integer number to check: "); 13 | scanf("%d", &num); 14 | temp = num; 15 | while (temp != 0) 16 | { 17 | length++; 18 | temp = temp / 10; 19 | } 20 | result = rev(num, length); 21 | if(num==result){ 22 | printf("Number is a palindrome."); 23 | }else{ 24 | printf("Number is not a palindrome."); 25 | } 26 | return 0; 27 | } 28 | 29 | int rev(int num, int len) 30 | { 31 | if (len == 1) 32 | { 33 | return num; 34 | } 35 | else 36 | { 37 | return (((num % 10) * pow(10, len - 1)) + rev(num / 10, --len)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Assignment_02/p10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | float a, b, c, aa, bb, cc; 7 | printf("This program checks if a triangle is right angled, equilateral, or none of those\n"); 8 | printf("Enter length of side A..."); 9 | scanf("%f", &a); 10 | printf("Enter length of side B..."); 11 | scanf("%f", &b); 12 | printf("Enter length of side C..."); 13 | scanf("%f", &c); 14 | aa=a*a; 15 | bb=b*b; 16 | cc=c*c; 17 | if (aa==bb+cc || bb==aa+cc || cc==aa+bb) 18 | { 19 | printf("Given triangle is right angled"); 20 | } 21 | else if (a==b && b==c) 22 | { 23 | printf("Given triangle is equilateral"); 24 | } 25 | else 26 | { 27 | printf("Given triangle is neither right-angled or equilateral"); 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Assignment_07/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int primeno(int, int); 5 | 6 | int main() 7 | { 8 | int num1, num2, check; 9 | printf("Enter lower limit: "); 10 | scanf("%d", &num1); 11 | printf("Enter upper limit: "); 12 | scanf("%d", &num2); 13 | printf("Prime numbers in given range are: "); 14 | for(int i=num1+1;i 2 | #include 3 | 4 | int compareInt(const void *pa, const void *pb){ 5 | const int *p1 = pa; 6 | const int *p2 = pb; 7 | return *p1 - *p2; 8 | } 9 | int main() 10 | { 11 | int arr[3][5]={{31, 57, 88, 0, 54}, 12 | {1, 79, 12, 10, 2}, 13 | {49, 15, 98, 11, 77}}; 14 | printf("Unsorted Array->\n"); 15 | for(int i=0;i<3;i++){ 16 | for(int j=0;j<5;j++){ 17 | printf("%d ", *(*(arr+i)+j)); 18 | } 19 | printf("\n"); 20 | } 21 | for(int i=0;i<3;i++){ 22 | qsort(arr[i], 5, sizeof(int), compareInt); 23 | } 24 | printf("\nSorted array->\n"); 25 | for(int i=0;i<3;i++){ 26 | for(int j=0;j<5;j++){ 27 | printf("%d ", *(*(arr+i)+j)); 28 | } 29 | printf("\n"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Assignment_09/p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void reversal(char text[], int *len){ 5 | char temp; 6 | int temp_len = *len; 7 | temp_len-=1; 8 | for(int i=0;i<((*len)/2);i++){ 9 | temp = *(text+i); 10 | *(text+i) = *(text+temp_len-1); 11 | *(text+temp_len-1) = temp; 12 | temp_len--; 13 | //printf("%c %c\n",temp, *(text+i)); 14 | } 15 | } 16 | 17 | int main() 18 | { 19 | int len; 20 | char dump; 21 | printf("Enter length of string: "); 22 | scanf("%d%c", &len, &dump); 23 | len+=1; 24 | char text[len]; 25 | len; 26 | printf("Enter your text: "); 27 | fgets(text, len, stdin); 28 | reversal(text, &len); 29 | /*char temp; 30 | temp = *(text); 31 | *(text) = *(text+5); 32 | *(text+5) = temp;*/ 33 | printf("reversed string is %s", text); 34 | } 35 | -------------------------------------------------------------------------------- /Assignment_08/p2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int findNthFibonacci(int idx) { 5 | if (idx < 2) { 6 | return idx; 7 | } 8 | 9 | return findNthFibonacci(idx - 1) + findNthFibonacci(idx - 2); 10 | } 11 | 12 | void printFibonacci(int start, int end) { 13 | 14 | if (start > end) { 15 | return; 16 | } 17 | 18 | int currentFibo = findNthFibonacci(start); 19 | 20 | printf(" %d ", currentFibo); 21 | 22 | printFibonacci(start+1, end); 23 | } 24 | 25 | void main() { 26 | int n; 27 | printf("Enter the number of terms till where you want to find the Fibonacci series: "); 28 | scanf("%d", &n); 29 | 30 | if (n <= 0) { 31 | printf("n must be greater than 0."); 32 | } else { 33 | // prints fibonacci from 1st term to nth term 34 | printFibonacci(0, n); 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Assignment_08/p7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | double distanceBetween2Points(double *cords1, double *cords2) { 6 | // exp1 = (x1 - x2)^2 7 | double exp1 = (cords1[0] - cords2[0])*(cords1[0] - cords2[0]); 8 | // exp2 = (y1 - y2)^2 9 | double exp2 = (cords1[1] - cords2[1])*(cords1[1] - cords2[1]); 10 | // ans = sqrt(exp1 + exp2); 11 | return sqrt(exp1 + exp2); 12 | } 13 | 14 | void main() { 15 | double cords1[2], cords2[2]; 16 | int i = 2; 17 | printf("Enter X1 : "); 18 | scanf("%lf", &cords1[0]); 19 | printf("Enter Y1 : "); 20 | scanf("%lf", &cords1[1]); 21 | printf("Enter X2 : "); 22 | scanf("%lf", &cords2[0]); 23 | printf("Enter Y2 : "); 24 | scanf("%lf", &cords2[1]); 25 | 26 | printf("Distance between two points: %f units.", distanceBetween2Points(cords1, cords2)); 27 | } 28 | -------------------------------------------------------------------------------- /Assignment_10/p1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | int a[3][4]={ 7 | {1,2,3,4}, 8 | {11,12,13,14}, 9 | {21,22,23,24} 10 | }; 11 | int(*p)[4]; 12 | p=a; 13 | printf("Printing directly: \n"); 14 | printf("p=%u p+1=%u p+2=%u", p,p+1,p+2); 15 | printf("\n"); 16 | for(int i=0;i<3;i++){ 17 | for(int j=0;j<4;j++){ 18 | printf("(%d,%d)=%d ",i+1,j+1,*(*(p+i)+j)); 19 | } 20 | printf("\n"); 21 | } 22 | printf("\n"); 23 | printf("Printing using 'a' as pointer: \n"); 24 | printf("p=%u p+1=%u p+2=%u", *a,*(a+1),*(a+2)); 25 | printf("\n"); 26 | for(int i=0;i<3;i++){ 27 | for(int j=0;j<4;j++){ 28 | printf("(%d,%d)=%d ",i+1,j+1,*(*(a+i)+j)); 29 | } 30 | printf("\n"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Assignment_01/p10.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int input, inputcopy, inputr, x1, x2, x3, x4, x5; 7 | printf("This program checks if a five digit number is a palindrome!\n"); 8 | printf("Enter five digit number to be checked...\n"); 9 | scanf("%d", &input); 10 | printf("The number entered is %d \n", input); 11 | inputcopy=input; 12 | x1=(input%10)*10000; 13 | input=input/10; 14 | x2=(input%10)*1000; 15 | input=input/10; 16 | x3=(input%10)*100; 17 | input=input/10; 18 | x4=(input%10)*10; 19 | input=input/10; 20 | x5=input; 21 | inputr=x1+x2+x3+x4+x5; 22 | printf("%d is the reverse of the given number.\n", inputr); 23 | if(inputr==inputcopy) 24 | { 25 | printf("Number is a palindrome."); 26 | } 27 | else 28 | { 29 | printf("Number is not a palindrome."); 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Assignment_03/p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int a, b, i, j; 7 | i=0; 8 | j=0; 9 | printf("Matrix creator!\n"); 10 | printf("Enter number of rows needed in matrix..."); 11 | scanf("%d", &a); 12 | printf("Enter number of columns needed in matrix..."); 13 | scanf("%d", &b); 14 | int array[a][b]; 15 | while(i", i,j); 20 | scanf("%d", &array[i][j]); 21 | j++; 22 | } 23 | j=0; 24 | i++; 25 | } 26 | i=0; 27 | j=0; 28 | printf("The matrix is\n"); 29 | while(i 2 | #include 3 | 4 | int smalLarge(int ar[],int length){ 5 | int s,l,g; 6 | l=0; 7 | for(int i=1;il){ 9 | l=ar[i]; 10 | } 11 | } 12 | s=l; 13 | for(int j=1;j0;k--){ 22 | if(s%k==0 && l%k==0){ 23 | printf("Their GCD is: %d",k); 24 | break; 25 | } 26 | } 27 | 28 | 29 | 30 | 31 | } 32 | int main() 33 | { 34 | int i; 35 | printf("Enter array length between 20-30 elements->"); 36 | scanf("%d",&i); 37 | int a[i]; 38 | for(int j=0;j 2 | #include 3 | #include 4 | 5 | 6 | int main() 7 | { 8 | srand(time(NULL)); 9 | int ans,guess; 10 | char rerun; 11 | replay: 12 | ans=rand()%1000; 13 | printf("I have a number between 1 and 1000\nCan you guess my number?"); 14 | printf("Please type your first guess.\n"); 15 | scanf("%d",&guess); 16 | while(guess!=ans){ 17 | if(guessans){ 21 | printf("Too high. Try again.\n"); 22 | scanf("%d",&guess); 23 | } 24 | } 25 | if(guess==ans){ 26 | printf("Excellent! You guessed the number.\n"); 27 | } 28 | printf("Would you like to play again(y or n)? "); 29 | scanf(" %c",&rerun); 30 | if(rerun=='y'){ 31 | goto replay; 32 | }else if(rerun=='n'){ 33 | printf("Thank you for playing."); 34 | }else{ 35 | printf("Invalid input. Exiting."); 36 | } 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /Assignment_02/p9.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | float a,b,c,disc,root1,root2,real,imag; 8 | printf("This program prints the roots of a quadratic equation\n"); 9 | printf("Equation is of the form ax^2+bx+c\n"); 10 | printf("Enter a..."); 11 | scanf("%f", &a); 12 | printf("Enter b..."); 13 | scanf("%f", &b); 14 | printf("Enter c..."); 15 | scanf("%f", &c); 16 | printf("Given equation is %.2fx^2+ %.2fx+ %.2f.\n", a,b,c); 17 | disc=(b*b)-(4*a*c); 18 | if(disc>0) 19 | { 20 | root1 = (-b + sqrt(disc)) / (2 * a); 21 | root2 = (-b - sqrt(disc)) / (2 * a); 22 | printf("the roots are %.2f and %.2f", root1, root2); 23 | } 24 | else if(disc==0) 25 | { 26 | root1=((-b)/(2*a)); 27 | root2=root1; 28 | printf("The roots are %.2f and %.2f", root1,root2); 29 | } 30 | else 31 | { 32 | real=((-b)/(2*a)); 33 | imag= sqrt(-disc) / (2 * a); 34 | printf("The roots are %.2f+ %.2f and %.2f- %.2f", real,imag,real,imag); 35 | } 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Assignment_11/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void swap(char[], char[]); 6 | 7 | int main() 8 | { 9 | char** name; 10 | int i, n, j, y; 11 | printf("Enter the number of strings:"); 12 | scanf("%d", &n); 13 | name = malloc(n * sizeof *name); 14 | for (i = 0; i < n; i++) 15 | { 16 | name[i] = (char*)malloc(100 * sizeof(char)); 17 | } 18 | printf("Enter the names:\n"); 19 | for (i = 0; i < n; i++) 20 | { 21 | scanf("%99s", name[i]); 22 | } 23 | for (i = 0; i < n; i++) 24 | { 25 | for (j = i + 1; j < n; j++) 26 | { 27 | y = strcmp(name[i], name[j]); 28 | if (y >= 0) 29 | { 30 | swap(name[i], name[j]); 31 | } 32 | } 33 | } 34 | printf("\nArranged strings:\n"); 35 | for (i = 0; i < n; i++) 36 | { 37 | printf("%s\n", name[i]); 38 | } 39 | free(name); 40 | return 0; 41 | } 42 | 43 | void swap(char a[], char b[]) 44 | { 45 | char temp[100]; 46 | strcpy(temp, a); 47 | strcpy(a, b); 48 | strcpy(b, temp); 49 | } 50 | -------------------------------------------------------------------------------- /Assignment_06/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int calculateCharges(int hours[]); 5 | int main(){ 6 | int t_hour,t_charge; 7 | t_hour=t_charge=0; 8 | int hours[3]; 9 | int hours_copy[3]; 10 | int *charge; 11 | for(int i=0;i<3;i++){ 12 | printf("Enter hours parked by Car no.%d: ",i+1); 13 | scanf("%d",&hours[i]); 14 | } 15 | for(int i=0;i<3;i++){ 16 | hours_copy[i]=hours[i]; 17 | } 18 | charge=calculateCharges(hours_copy); 19 | printf("Car Hours Charge\n"); 20 | for(int i=0;i<3;i++){ 21 | printf("%3d %5d %6d\n",i+1,hours[i],charge[i]); 22 | } 23 | for(int i=0;i<3;i++){ 24 | t_hour+=hours[i]; 25 | t_charge+=charge[i]; 26 | } 27 | printf(".......................\n"); 28 | printf("Total:%6d%10d",t_hour,t_charge); 29 | 30 | return 0; 31 | } 32 | int calculateCharges(int hours_copy[]){ 33 | for(int i=0;i<3;i++){ 34 | if(hours_copy[i]<=3){ 35 | hours_copy[i]=20; 36 | }else if(hours_copy[i]<31){ 37 | hours_copy[i]=((hours_copy[i]-3)*10)+20; 38 | }else{ 39 | hours_copy[i]=300; 40 | } 41 | } 42 | return hours_copy; 43 | } 44 | -------------------------------------------------------------------------------- /Assignment_09/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void populator(int ar[], int *ta, int *tb, int *tc, int *reader){ 5 | 6 | loc0: 7 | if(*reader>2){ 8 | //printf("%d\n", ar[*reader]); 9 | goto loc1; 10 | } 11 | if(*reader==0){ 12 | ar[*reader] = *ta; 13 | //printf("%d\n", ar[*reader]); 14 | *reader+=1; 15 | goto loc0; 16 | } 17 | if(*reader==1){ 18 | ar[*reader] = *tb; 19 | //printf("%d\n", ar[*reader]); 20 | *reader+=1; 21 | goto loc0; 22 | } 23 | if(*reader==2){ 24 | ar[*reader] = *tc; 25 | *reader+=1; 26 | //printf("%d\n", ar[*reader]); 27 | goto loc0; 28 | } 29 | loc1: 30 | while(*reader<30){ 31 | ar[*reader] = *ta + *tc; 32 | *ta = *tb; 33 | *tb = *tc; 34 | *tc = ar[*reader]; 35 | //printf("%d\n", ar[*reader]); 36 | *reader+=1; 37 | } 38 | } 39 | 40 | int main() 41 | { 42 | int ar[30]; 43 | int ta = 0; 44 | int tb = 1; 45 | int tc = 1; 46 | int reader = 0; 47 | printf("let's go\n"); 48 | populator(ar, &ta, &tb, &tc, &reader); 49 | for(int i=0;i<30;i++){ 50 | printf("%d\n", ar[i]); 51 | } 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /Assignment_02/p11.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | float phy, chem, bio, mat, comp, sum, perct; 7 | char grade; 8 | printf("This program calculates percentage and grade for given marks!\n"); 9 | printf("Enter physics marks(out of 100)..."); 10 | scanf("%f", &phy); 11 | printf("Enter chemistry marks(out of 100)..."); 12 | scanf("%f", &chem); 13 | printf("Enter biology marks(out of 100)..."); 14 | scanf("%f", &bio); 15 | printf("Enter mathematics marks(out of 100)..."); 16 | scanf("%f", &mat); 17 | printf("Enter computer marks(out of 100)..."); 18 | scanf("%f", &comp); 19 | sum=phy+chem+bio+mat+comp; 20 | perct=(sum/500)*100; 21 | printf("Percentage of marks earned is %.2f\n", perct); 22 | if(perct>=90) 23 | { 24 | grade='A'; 25 | } 26 | else if(perct>=80) 27 | { 28 | grade='B'; 29 | } 30 | else if(perct>=70) 31 | { 32 | grade='C'; 33 | } 34 | else if(perct>=60) 35 | { 36 | grade='D'; 37 | } 38 | else if(perct>=40) 39 | { 40 | grade='E'; 41 | } 42 | else if(perct<40) 43 | { 44 | grade='F'; 45 | } 46 | printf("Obtained grade is %c", grade); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Assignment_05/p8.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define MAX 100 5 | 6 | bool ortho(int a[][MAX], int m, int n) 7 | { 8 | if (m != n) 9 | return false; 10 | 11 | // Multiply A*A^t 12 | for (int i = 0; i < n; i++) 13 | { 14 | for (int j = 0; j < n; j++) 15 | { 16 | 17 | int sum = 0; 18 | for (int k = 0; k < n; k++) 19 | { 20 | 21 | // Since we are multiplying with 22 | // transpose of itself. We use 23 | // a[j][k] instead of a[k][j] 24 | sum +=((a[i][k] * a[j][k])); 25 | } 26 | 27 | if (i == j && sum != 1) 28 | return false; 29 | if (i != j && sum != 0) 30 | return false; 31 | } 32 | } 33 | 34 | return true; 35 | } 36 | 37 | int main() 38 | { 39 | int s; 40 | printf("enter square matrix size(<100)->"); 41 | scanf("%d", &s); 42 | int a[s][MAX]; 43 | printf("enter matrix elements\n"); 44 | for(int i=0;i 2 | #include 3 | #include 4 | 5 | struct Point{ 6 | float xcor; 7 | float ycor; 8 | 9 | }; 10 | 11 | struct Triangle{ 12 | struct Point p1; 13 | struct Point p2; 14 | struct Point p3; 15 | 16 | }; 17 | 18 | int main(){ 19 | 20 | float dist1, dist2, dist3; 21 | struct Triangle tri1; 22 | printf("Enter triangle coordinates-> \n"); 23 | printf("Point 1 x-coordinate: "); 24 | scanf("%f", &tri1.p1.xcor); 25 | printf("Point 1 y-coordinate: "); 26 | scanf("%f", &tri1.p1.ycor); 27 | printf("Point 2 x-coordinate: "); 28 | scanf("%f", &tri1.p2.xcor); 29 | printf("Point 2 y-coordinate: "); 30 | scanf("%f", &tri1.p2.ycor); 31 | printf("Point 3 x-coordinate: "); 32 | scanf("%f", &tri1.p3.xcor); 33 | printf("Point 3 y-coordinate: "); 34 | scanf("%f", &tri1.p3.ycor); 35 | 36 | dist1 = sqrt(pow((tri1.p2.xcor - tri1.p1.xcor),2)+ pow((tri1.p2.ycor - tri1.p1.ycor),2)); 37 | dist2 = sqrt(pow((tri1.p3.xcor - tri1.p2.xcor),2)+ pow((tri1.p3.ycor - tri1.p2.ycor),2)); 38 | dist3 = sqrt(pow((tri1.p1.xcor - tri1.p3.xcor),2)+ pow((tri1.p1.ycor - tri1.p3.ycor),2)); 39 | 40 | if(dist1 2 | #include 3 | 4 | void prime(int a[]){ 5 | int c,d,k,s,t; 6 | c=0; 7 | d=0; 8 | for(int i=0;i<20;i++){ 9 | for(int j=a[i];j>0;j--){ 10 | if(a[i]%j==0){ 11 | d++; 12 | } 13 | } 14 | if(d==2){ 15 | c++; 16 | } 17 | d=0; 18 | } 19 | k=0; 20 | int b[c]; 21 | for(int i=0;i<20;i++){ 22 | for(int j=a[i];j>0;j--){ 23 | if(a[i]%j==0){ 24 | d++; 25 | } 26 | } 27 | 28 | if(d==2){ 29 | b[k]=a[i]; 30 | k++; 31 | } 32 | 33 | d=0; 34 | } 35 | /*for(int i=0;i 2 | #include 3 | 4 | int main() 5 | { 6 | int mat1[3][3], mat2[3][3], mat3[3][3], i, j, k; 7 | printf("3x3 Matrix Multiplier\n"); 8 | printf("Enter values for first matrix\n"); 9 | i=0; 10 | j=0; 11 | while(i<3) 12 | { 13 | while(j<3) 14 | { 15 | printf("Enter element (%d,%d)->", i+1,j+1); 16 | scanf("%d", &mat1[i][j]); 17 | j++; 18 | } 19 | j=0; 20 | i++; 21 | } 22 | i=0; 23 | j=0; 24 | printf("Enter values for second matrix\n"); 25 | while(i<3) 26 | { 27 | while(j<3) 28 | { 29 | printf("Enter element (%d,%d)->", i+1,j+1); 30 | scanf("%d", &mat2[i][j]); 31 | j++; 32 | } 33 | j=0; 34 | i++; 35 | } 36 | i=0; 37 | j=0; 38 | k=0; 39 | printf("The resultant matrix is:\n"); 40 | while(i<3) 41 | { 42 | while(j<3) 43 | { 44 | mat3[i][j]=0; 45 | while(k<3) 46 | { 47 | mat3[i][j]+=(mat1[i][k]*mat2[k][j]); 48 | k++; 49 | } 50 | k=0; 51 | j++; 52 | } 53 | j=0; 54 | i++; 55 | } 56 | i=0; 57 | j=0; 58 | k=0; 59 | printf("\n"); 60 | while(i<3) 61 | { 62 | printf("|"); 63 | while(j<3) 64 | { 65 | printf(" %d ", mat3[i][j]); 66 | j++; 67 | } 68 | printf("|\n"); 69 | j=0; 70 | i++; 71 | } 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022, Raj Rajeshwar Singh Bisen 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /Assignment_04/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int s; 7 | int a, b, k, r, x, n; 8 | r=0; 9 | printf("|| MENU SCREEN ||\n"); 10 | printf("I. Odd or Even\nII. First number is multiple of the second number or not\nIII. Sum of digits of a given number is odd or even\n"); 11 | printf("Choose Operation 1,2 or 3 to perform->"); 12 | scanf("%d", &s); 13 | printf(".\n"); 14 | switch (s){ 15 | 16 | case 1: printf("Enter number to check->"); 17 | scanf("%d",&n); 18 | if(n%2==0){ 19 | printf("Number is even"); 20 | }else{ 21 | printf("Number is odd"); 22 | } 23 | break; 24 | case 2: printf("Enter first number->"); 25 | scanf("%d",&a); 26 | printf("Enter second number->"); 27 | scanf("%d",&b); 28 | if(a%b==0){ 29 | printf("%d is a multiple of %d", a,b); 30 | }else{ 31 | printf("%d is not a multiple of %d", a,b); 32 | } 33 | break; 34 | case 3: r=0; 35 | printf("Enter number to check if sum of digits is even or odd->"); 36 | scanf("%d", &k); 37 | x=k; 38 | do{ 39 | r+=k%10; 40 | k=k/10; 41 | }while(k>10); 42 | if(r%2==0){ 43 | printf("Sum of digits of %d is even.", x); 44 | }else{ 45 | printf("Sum of digits of %d is odd.", x); 46 | } 47 | break; 48 | default: printf("Invalid Input"); 49 | 50 | 51 | } 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /Assignment_11/p3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Cricketer{ 6 | char name[15]; 7 | int age; 8 | int game_num; 9 | int avg; 10 | 11 | }; 12 | 13 | int compareAvg(const void *s1, const void *s2){ 14 | struct Cricketer *e1 = (struct Cricketer *)s1; 15 | struct Cricketer *e2 = (struct Cricketer *)s2; 16 | return e1->avg - e2->avg; 17 | 18 | } 19 | 20 | int main() 21 | { 22 | srand(time(NULL)); 23 | struct Cricketer player[20]; 24 | char namebank[20][15]={"Noor","Deandra","Simone","Mona","Bryanna","Aliya","Liana","Aliah", 25 | "Patience","Marion","Maren","Kaitlynn","Katelyn","Marin","Mckenzie", 26 | "Keona","Brielle","Maggie","Maddie","Gloria"}; 27 | for(int i=0;i<20;i++){ 28 | strcpy(player[i].name, namebank[i]); 29 | player[i].age = (rand()%21)+14; 30 | player[i].game_num = (rand()%200)+10; 31 | player[i].avg = rand()%350; 32 | 33 | } 34 | printf(" Name | Age | Games Played | Average Runs\n...............................................\n"); 35 | 36 | for(int i=0;i<20;i++){ 37 | printf("%8s |%4d |%12d |%12d\n", player[i].name, player[i].age, player[i].game_num, player[i].avg); 38 | } 39 | 40 | qsort(player, 20, sizeof(struct Cricketer), compareAvg); 41 | printf("\n\nSorted list: \n"); 42 | printf(" Name | Age | Games Played | Average Runs\n...............................................\n"); 43 | for(int i=0;i<20;i++){ 44 | printf("%8s |%4d |%12d |%12d\n", player[i].name, player[i].age, player[i].game_num, player[i].avg); 45 | } 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CSD101 2 | ## Course assignments, quizzes et al. 3 | 4 | ### Description 5 | This repository contains all the coursework, quizzes, projects, code, and other "stuff" assigned in the CSD101 course at 6 | Shiv Nadar University in the Monsoon 2022 Semester. Efforts have been made to keep the directories, code, and source 7 | material up to date. For any requests/issues, reach out to me [here](mailto:typhoeusxoxo@gmail.com). 8 | 9 | ### Notice 10 | * Naming format, unless specified otherwise, is p\.c for the particular assignment. 11 | * Code and other forms of solution provided here are for reference and understanding of person(s) perusing this. 12 | * Any code/solution provided here may not be used as reference/copied for submissions, fully or partially. 13 | * Further usage is governed under the [BSD-3-Clause License](LICENSE). 14 | 15 | ### Contents 16 | 01. Assignment 1 - Graded | Basic C programmes 17 | 02. Assignment 2 - Graded | Conditional statements, If-else, Switch 18 | 03. Assignment 3 - Graded | Array beginner programmes, Arithmetic 19 | 04. Assignment 4 - Ungraded | Arithmetic, Revision for sem-1 midterm lab 20 | 05. Assignment 5 - Ungraded | Matrices, Arrays, Revision for sem-1 midterm lab 21 | 06. Assignment 6 - Graded | Menu-based beginner programmes, Functions 22 | 07. Assignment 7 - Graded | Recursion beginner programmes 23 | 08. Assignment 8 - Graded | Moderate recursion problems 24 | 09. Assignment 9 - Graded | Advanced recursion and pointers problems 25 | 10. Assignment 10 - Graded | Pointer arithmetic, Memory allocation 26 | 11. Assignment 11 - Graded | Structs, Database 27 | 12. Assignment 12 - Graded | File I/O 28 | 13. Misc - Miscellaneous folder to hold stuff other than the assignments 29 | 30 | ## Author 31 | - [@AnarchistHoneybun](https://github.com/AnarchistHoneybun) 32 | 33 | --- 34 | Shoutout to [@Aaradhy-Sharma](https://github.com/Aaradhy-Sharma) for inspiration for setting up this readme. 35 | -------------------------------------------------------------------------------- /Assignment_07/p2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void multiply(int, int, int [][10], int, int, int [][10], int [][10]); 5 | void display(int, int, int[][10]); 6 | 7 | int main() 8 | { 9 | int a[10][10], b[10][10], c[10][10] = {0}; 10 | int m1, n1, m2, n2, i, j, k; 11 | 12 | printf("Enter rows and columns for Matrix A respectively: "); 13 | scanf("%d%d", &m1, &n1); 14 | printf("Enter rows and columns for Matrix B respectively: "); 15 | scanf("%d%d", &m2, &n2); 16 | if (n1 != m2) 17 | { 18 | printf("Matrix multiplication not possible.\n"); 19 | } 20 | else 21 | { 22 | printf("Enter elements in Matrix A:\n"); 23 | for (i = 0; i < m1; i++) 24 | for (j = 0; j < n1; j++) 25 | { 26 | scanf("%d", &a[i][j]); 27 | } 28 | printf("\nEnter elements in Matrix B:\n"); 29 | for (i = 0; i < m2; i++) 30 | for (j = 0; j < n2; j++) 31 | { 32 | scanf("%d", &b[i][j]); 33 | } 34 | multiply(m1, n1, a, m2, n2, b, c); 35 | } 36 | printf("On matrix multiplication of A and B the result is:\n"); 37 | display(m1, n2, c); 38 | } 39 | 40 | void multiply (int m1, int n1, int a[10][10], int m2, int n2, int b[10][10], int c[10][10]) 41 | { 42 | static int i = 0, j = 0, k = 0; 43 | 44 | if (i >= m1) 45 | { 46 | return; 47 | } 48 | else if (i < m1) 49 | { 50 | if (j < n2) 51 | { 52 | if (k < n1) 53 | { 54 | c[i][j] += a[i][k] * b[k][j]; 55 | k++; 56 | multiply(m1, n1, a, m2, n2, b, c); 57 | } 58 | k = 0; 59 | j++; 60 | multiply(m1, n1, a, m2, n2, b, c); 61 | } 62 | j = 0; 63 | i++; 64 | multiply(m1, n1, a, m2, n2, b, c); 65 | } 66 | } 67 | 68 | void display(int m1, int n2, int c[10][10]) 69 | { 70 | int i, j; 71 | 72 | for (i = 0; i < m1; i++) 73 | { 74 | for (j = 0; j < n2; j++) 75 | { 76 | printf("%d ", c[i][j]); 77 | } 78 | printf("\n"); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Assignment_11/p2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct sent{ 6 | int rolln; 7 | char name[15]; 8 | char dept[15]; 9 | int join_yr; 10 | 11 | }; 12 | 13 | void record_printer_year(struct sent s[160], int year_check); 14 | void record_printer_roll(struct sent s[160], int roll_check); 15 | 16 | int main() 17 | { 18 | srand(time(NULL)); 19 | //Filling data in the sent structs 20 | char depts[4][15]={"Civil","Mechanical","Economics","Maths"}; 21 | int years[4]={2015,2016,2017,2018}; 22 | char names[10][10]={"Parker","Devan","Corrina","Jim","Marian","Davon","Shemar","Drew","Sheila","Taniya"}; 23 | struct sent s[160]; 24 | for(int i=0,j=0;i<4;i++){ 25 | for(int k=0;k<4;k++){ 26 | for(int l=0;l<10;l++){ 27 | s[j].join_yr = years[i]; 28 | strcpy(s[j].dept, depts[k]); 29 | s[j].rolln = j; 30 | strcpy(s[j].name, names[rand()%10]); 31 | j+=1; 32 | } 33 | } 34 | } 35 | //testing if data is filled properly 36 | //int test = rand()%160; 37 | //printf("%d %s %s %d", s[test].join_yr, s[test].dept, s[test].name, s[test].rolln); 38 | //for(int test=0;test<160;test++){ 39 | // printf("%d. %d %s %s %d\n", test+1, s[test].join_yr, s[test].dept, s[test].name, s[test].rolln); 40 | //} 41 | 42 | int year_check; 43 | printf("Enter year(2015/2016/2017/2018): "); 44 | scanf("%d", &year_check); 45 | record_printer_year(s, year_check); 46 | 47 | int roll_check; 48 | printf("Enter roll no(1-160): "); 49 | scanf("%d", &roll_check); 50 | record_printer_roll(s, roll_check); 51 | return 0; 52 | } 53 | 54 | void record_printer_year(struct sent s[160], int year_check){ 55 | printf("YEAR DEPARTMENT NAME ROLLNO\n"); 56 | for(int i=0;i<160;i++){ 57 | if(s[i].join_yr==year_check){ 58 | printf("%d |%10s|%7s|%d\n", s[i].join_yr, s[i].dept, s[i].name, s[i].rolln); 59 | } 60 | } 61 | 62 | } 63 | 64 | void record_printer_roll(struct sent s[160], int roll_check){ 65 | for(int i=0;i<160;i++){ 66 | if(s[i].rolln==roll_check){ 67 | printf("Year of joining:%d\nDepartment: %s\nName: %s\n", s[i].join_yr, s[i].dept, s[i].name, s[i].rolln); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Assignment_11/p4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Bankledger{ 6 | int accnum; 7 | char name[15]; 8 | int balance; 9 | 10 | }; 11 | 12 | void mincheck(struct Bankledger customer[15]); 13 | 14 | int main() 15 | { 16 | srand(time(NULL)); 17 | struct Bankledger customer[15]; 18 | //setting up the struct array 19 | char names[15][15]={"Vanesa", "Silas", "Jaron", "Adan", "William", "Pamela", "Ean", "Casey", "Madalyn", "Mya", "Odalis", "Kayla", "Michelle", "Trenton", "Jarett"}; 20 | for(int i=0;i<15;i++){ 21 | customer[i].accnum = rand(); 22 | strcpy(customer[i].name, names[i]); 23 | customer[i].balance = rand()%200; 24 | } 25 | mincheck(customer); 26 | int request; 27 | printf("Enter 1 to deposit or 0 for withdrawal: "); 28 | scanf("%d", &request); 29 | if(request==1){ 30 | int acct_num; 31 | printf("Enter account number: "); 32 | scanf("%d", &acct_num); 33 | int amount; 34 | printf("Enter amount: "); 35 | scanf("%d", &amount); 36 | for(int i=0;i<15;i++){ 37 | if(customer[i].accnum == acct_num){ 38 | customer[i].balance+=amount; 39 | printf("Your new balance is: %d", customer[i].balance); 40 | } 41 | } 42 | }else if(request==0){ 43 | int acct_num; 44 | printf("Enter account number: "); 45 | scanf("%d", &acct_num); 46 | int amount; 47 | printf("Enter amount: "); 48 | scanf("%d", &amount); 49 | for(int i=0;i<15;i++){ 50 | if(customer[i].accnum == acct_num){ 51 | if(customer[i].balance\n"); 67 | for(int i=0;i<15;i++){ 68 | if(customer[i].balance<100){ 69 | printf("Name: %s\nAcc no:%d\n\n", customer[i].name, customer[i].accnum); 70 | 71 | } 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /Assignment_12/p3.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #define null 0 8 | #define max_string 100 9 | #define max_words 1000 10 | 11 | void word_frequency(char *filename); 12 | 13 | 14 | signed main(void) 15 | { 16 | char filename[max_string]; 17 | printf("\n Please enter the filename: "); 18 | scanf("%s", filename); 19 | word_frequency(filename); 20 | return null; 21 | } 22 | 23 | 24 | 25 | void word_frequency(char *filename) 26 | { 27 | 28 | 29 | FILE *fp1; 30 | char ch, word[max_string], words[max_words][max_string]; 31 | int i, j, flag, count[max_words]; 32 | fp1 = fopen(filename, "r"); 33 | if (fp1 == null) 34 | { 35 | printf("\n Error opening file. Please check the filename and try again. "); 36 | exit(1); 37 | } 38 | 39 | char *string = (char *)malloc(max_string * sizeof(char)); 40 | i = null; 41 | while ((ch = fgetc(fp1)) != EOF) 42 | { 43 | string[i] = ch; 44 | i++; 45 | } 46 | string[i] = '\0'; 47 | fclose(fp1); 48 | 49 | printf("\n The file contents are: "); 50 | printf("\n %s", string); 51 | 52 | 53 | i = null; 54 | j = null; 55 | flag = null; 56 | 57 | while (string[i] != '\0') 58 | { 59 | if (string[i] == ' ' || string[i] == ',' || string[i] == '.' || string[i] == '!' || string[i] == '?' || string[i] == ';') 60 | { 61 | word[j] = '\0'; 62 | flag = null; 63 | for (int k = null; k < i; k++) 64 | { 65 | if (strcmp(word, words[k]) == null) 66 | { 67 | flag = 1; 68 | count[k]++; 69 | break; 70 | } 71 | } 72 | if (flag == null) 73 | { 74 | strcpy(words[j], word); 75 | count[j] = 1; 76 | j++; 77 | } 78 | j = null; 79 | } 80 | else 81 | { 82 | word[j] = string[i]; 83 | j++; 84 | } 85 | i++; 86 | } 87 | 88 | 89 | 90 | printf("\n The word frequency statistics are: "); 91 | printf("\n Word \t\t Frequency "); 92 | for (int k = null; k < j; k++) 93 | { 94 | printf("\n %s \t\t %d", words[k], count[k]); 95 | } 96 | printf("\n\n"); 97 | } 98 | -------------------------------------------------------------------------------- /Assignment_02/p1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | float a, b, c, largest, smallest; 7 | printf("This program checks and prints the largest of three numbers\n"); 8 | printf("Enter first number"); 9 | scanf("%f", &a); 10 | printf("Enter second number"); 11 | scanf("%f", &b); 12 | printf("Enter third number"); 13 | scanf("%f", &c); 14 | 15 | printf("The three numbers are %f , %f , %f . \n", a, b, c); 16 | 17 | if (a>b) 18 | { 19 | if (a>c) 20 | { 21 | largest=a; 22 | if (b>c) 23 | { 24 | smallest=c; 25 | } 26 | else if(bc) 49 | { 50 | largest=b; 51 | smallest=c; 52 | } 53 | else if(ac) 56 | { 57 | largest=b; 58 | smallest=a; 59 | } 60 | else if(bc) 80 | { 81 | largest=a; 82 | smallest=c; 83 | } 84 | else if(a 2 | #include 3 | 4 | int main() 5 | { 6 | int a, b, c, largest, smallest; 7 | printf("This program checks and prints the Largest and Smallest of three integers\n"); 8 | printf("Enter first integer"); 9 | scanf("%d", &a); 10 | printf("Enter second integer"); 11 | scanf("%d", &b); 12 | printf("Enter third integer"); 13 | scanf("%d", &c); 14 | 15 | printf("The three integers are %d , %d , %d . \n", a, b, c); 16 | 17 | if (a>b) 18 | { 19 | if (a>c) 20 | { 21 | largest=a; 22 | if (b>c) 23 | { 24 | smallest=c; 25 | } 26 | else if(bc) 49 | { 50 | largest=b; 51 | smallest=c; 52 | } 53 | else if(ac) 56 | { 57 | largest=b; 58 | smallest=a; 59 | } 60 | else if(bc) 80 | { 81 | largest=a; 82 | smallest=c; 83 | } 84 | else if(a 4 | #include 5 | #include 6 | #include 7 | #define null 0 8 | #define max_string 100 // max_string = maximum string length // // edit this according to your needs // 9 | 10 | void remove_stop_words(char *source_file , char *stop_words_file); // function to remove all words listed in the stop-words file from the source file // 11 | 12 | // driver code// 13 | signed main(void) 14 | { 15 | char source_file[max_string]; 16 | char stop_words_file[max_string]; 17 | printf("\n Please enter the source file name(including extension): "); 18 | scanf("%s", source_file); 19 | printf("\n Please enter the stop words file name(including extension): "); 20 | scanf("%s", stop_words_file); 21 | remove_stop_words(source_file, stop_words_file); 22 | return null; 23 | } 24 | 25 | 26 | void remove_stop_words(char *source_file , char *stop_words_file) 27 | { 28 | // to open both files // 29 | FILE *fp1, *fp2; 30 | char ch; 31 | int i, j, flag; 32 | fp1 = fopen(source_file, "r"); 33 | fp2 = fopen("temp.txt", "w"); 34 | 35 | // to read the file contents into the memory // 36 | char *string = (char *)malloc(max_string * sizeof(char)); 37 | i = null; 38 | while ((ch = fgetc(fp1)) != EOF) 39 | { 40 | string[i] = ch; 41 | i++; 42 | } 43 | string[i] = '\0'; 44 | fclose(fp1); 45 | 46 | // while working in memory, to remove from the 'source' content all the words listed in the 'stop words' content // 47 | char *stop_words = (char *)malloc(max_string * sizeof(char)); 48 | fp2 = fopen(stop_words_file, "r"); 49 | 50 | // to read the file contents of stop word file into a string // 51 | i = null; 52 | while (string[i] != '\0') 53 | { 54 | flag = null; 55 | j = null; 56 | while (stop_words[j] != '\0') 57 | { 58 | if (string[i] == stop_words[j]) 59 | { 60 | flag = 1; 61 | break; 62 | } 63 | j++; 64 | } 65 | if (flag == null) 66 | { 67 | fputc(string[i], fp2); 68 | } 69 | i++; 70 | } 71 | fclose(fp2); 72 | 73 | // to write back the modified content to the source file // 74 | fp1 = fopen(source_file, "w"); 75 | fp2 = fopen("output.txt", "r"); 76 | while ((ch = fgetc(fp2)) != EOF) 77 | { 78 | fputc(ch, fp1); 79 | } 80 | 81 | // to close both files // 82 | fclose(fp1); 83 | fclose(fp2); 84 | } 85 | 86 | -------------------------------------------------------------------------------- /Assignment_09/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void encrypt(int start, int end, int n, char padded_string[], char output_string[]) 6 | { 7 | for (int i = 0; i < 5; i++) 8 | { 9 | } 10 | } 11 | 12 | int main() 13 | { 14 | char input_string[255]; 15 | printf("Enter input string: "); 16 | fgets(input_string, 255, stdin); 17 | printf("input string= %s\n", input_string); // Hello, world! 18 | 19 | input_string[strlen(input_string) - 1] = '\0'; // removing last \n character 20 | 21 | int input_string_length = strlen(input_string); // to ignore \n character 22 | printf("input string length = %d\n", input_string_length); // 13 23 | 24 | int n = 0, a = 0, b = 0; 25 | 26 | printf("Enter n: "); 27 | scanf("%d", &n); // 3 28 | 29 | printf("Enter a: "); 30 | scanf("%d", &a); // 3 31 | 32 | printf("Enter b: "); 33 | scanf("%d", &b); // 3 34 | 35 | int buffer = n - (input_string_length % n); // 5 - 13 % 5 = 2 36 | printf("buffer = %d\n", buffer); 37 | 38 | int final_string_length = input_string_length + buffer; // 13 + 2 = 15 39 | 40 | printf("final string length = %d\n", final_string_length); // 15 41 | 42 | char padded_string[final_string_length]; 43 | 44 | strcpy(padded_string, input_string); 45 | 46 | printf("padded string after copying input string: %s\n", padded_string); // final string = Hello, world! 47 | 48 | printf("length of padded string array after copying input array = %zu\n", strlen(padded_string)); // 13 49 | 50 | for (int i = 0; i < buffer; i++) 51 | { 52 | padded_string[input_string_length + i] = '#'; // appending null characters to last block of the new string 53 | } 54 | 55 | int padded_string_length = sizeof(padded_string) / sizeof(padded_string[0]); 56 | 57 | printf("length of padded string array = %zu\n", padded_string_length); // using sizeof because strlen only calculates till null character 58 | 59 | printf("padded string: %s\n", padded_string); // padded string is applesauce with last 2 characters as null 60 | 61 | int number_of_blocks = padded_string_length / n; // 15 / 5 = 3 62 | 63 | char output_string[padded_string_length]; 64 | 65 | int start = 0; 66 | 67 | for (int block = 0; block < number_of_blocks; block++) 68 | { 69 | for (int i = 0; i < n; i++) 70 | { 71 | int output_idx = ((a * i) + b) % n; 72 | output_string[i + start] = padded_string[output_idx + start]; 73 | } 74 | 75 | start += n; 76 | } 77 | 78 | printf("output string = %s\n", output_string); 79 | } 80 | //padding with # for better formating 81 | -------------------------------------------------------------------------------- /Assignment_10/p7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #define NULL 0 6 | #define unity 1 7 | #define len_max 100 8 | 9 | void scoring_func(char *string); 10 | signed string_uppercase(char *string); 11 | signed if_space(char *string); 12 | 13 | 14 | int main() 15 | { 16 | signed return_value = NULL; 17 | char string[len_max]; 18 | printf("\n Please enter the string : "); 19 | fgets(string, len_max, stdin); 20 | 21 | return_value = if_space(string); 22 | if (return_value == unity) 23 | { 24 | printf("\n Illegal input"); 25 | return NULL; 26 | } 27 | string_uppercase(string); 28 | scoring_func(string); 29 | return 0; 30 | } 31 | 32 | 33 | 34 | 35 | void scoring_func(char *string) 36 | { 37 | signed length = strlen(string); 38 | signed score = NULL; 39 | for (signed index = NULL; index < length; index++) 40 | { 41 | switch (string[index]) 42 | { 43 | case 'A': 44 | case 'E': 45 | case 'I': 46 | case 'L': 47 | case 'N': 48 | case 'O': 49 | case 'R': 50 | case 'S': 51 | case 'T': 52 | case 'U': 53 | score += unity; 54 | break; 55 | case 'D': 56 | case 'G': 57 | score += 2; 58 | break; 59 | case 'B': 60 | case 'C': 61 | case 'M': 62 | case 'P': 63 | score += 3; 64 | break; 65 | case 'F': 66 | case 'H': 67 | case 'V': 68 | case 'W': 69 | case 'Y': 70 | score += 4; 71 | break; 72 | case 'K': 73 | score += 5; 74 | break; 75 | case 'J': 76 | case 'X': 77 | score += 8; 78 | break; 79 | case 'Q': 80 | case 'Z': 81 | score += 10; 82 | break; 83 | } 84 | } 85 | printf("\n Your scrabble score is : %d", score); 86 | } 87 | 88 | signed string_uppercase(char *string) 89 | { 90 | signed length = strlen(string); 91 | for (signed index = NULL; index < length; index++) 92 | { 93 | if (string[index] >= 'a' && string[index] <= 'z') 94 | { 95 | string[index] -= 32; 96 | } 97 | } 98 | } 99 | 100 | 101 | signed if_space(char *string) 102 | { 103 | signed length = strlen(string); 104 | for (signed index = NULL; index < length; index++) 105 | { 106 | if(string[index]==' ') 107 | { 108 | return unity; 109 | } 110 | 111 | 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /Assignment_10/p5.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define null 0 5 | 6 | signed square_matrix_maker(signed **matrix, signed dimension); 7 | signed square_matrix_printer(signed **matrix, signed dimension); 8 | signed matrix_multiplication(signed **matrix1, signed **matrix2, signed dimension); 9 | signed square_matrix_printer_mx(signed **matrix, signed dimension); 10 | 11 | 12 | signed main(void) 13 | { 14 | 15 | 16 | 17 | signed dimension; 18 | printf("\n Please enter the dimension of the square matrix : "); 19 | scanf("%d", &dimension); 20 | 21 | signed **matrix1 = (signed **)malloc(dimension * sizeof(signed *)); 22 | for (signed i = null; i < dimension; i++) 23 | { 24 | matrix1[i] = (signed *)malloc(dimension * sizeof(signed)); 25 | } 26 | 27 | signed **matrix2 = (signed **)malloc(dimension * sizeof(signed *)); 28 | for (signed i = null; i < dimension; i++) 29 | { 30 | matrix2[i] = (signed *)malloc(dimension * sizeof(signed)); 31 | } 32 | 33 | 34 | printf("\n Please enter the elements of the first matrix : "); 35 | square_matrix_maker(matrix1, dimension); 36 | square_matrix_printer(matrix1, dimension); 37 | printf("\n Please enter the elements of the second matrix : "); 38 | square_matrix_maker(matrix2, dimension); 39 | square_matrix_printer(matrix2, dimension); 40 | matrix_multiplication(matrix1, matrix2, dimension); 41 | 42 | 43 | free(matrix1); 44 | free(matrix2); 45 | 46 | 47 | return null; 48 | } 49 | 50 | signed square_matrix_maker(signed **matrix, signed dimension) 51 | { 52 | for (signed i = null; i < dimension; i++) 53 | { 54 | for (signed j = null; j < dimension; j++) 55 | { 56 | printf("\n Please enter the element in position [%d][%d] of the matrix : ", i, j); 57 | scanf("%d", &matrix[i][j]); 58 | } 59 | } 60 | printf("\n\n"); 61 | } 62 | 63 | signed square_matrix_printer(signed **matrix, signed dimension) 64 | { 65 | printf("\n The matrix you entered is : \n"); 66 | 67 | for (signed i = null; i < dimension; i++) 68 | { 69 | for (signed j = null; j < dimension; j++) 70 | { 71 | printf("\t %d", matrix[i][j]); 72 | } 73 | printf("\n"); 74 | } 75 | } 76 | 77 | signed matrix_multiplication(signed **matrix1, signed **matrix2, signed dimension) 78 | { 79 | signed **matrix3 = (signed **)malloc(dimension * sizeof(signed *)); 80 | for (signed i = null; i < dimension; i++) 81 | { 82 | matrix3[i] = (signed *)malloc(dimension * sizeof(signed)); 83 | } 84 | 85 | for (signed i = null; i < dimension; i++) 86 | { 87 | for (signed j = null; j < dimension; j++) 88 | { 89 | matrix3[i][j] = null; 90 | for (signed k = null; k < dimension; k++) 91 | { 92 | matrix3[i][j] += matrix1[i][k] * matrix2[k][j]; 93 | } 94 | } 95 | } 96 | printf("\n The product of the two matrices is : "); 97 | square_matrix_printer_mx(matrix3, dimension); 98 | free(matrix3); 99 | } 100 | 101 | signed square_matrix_printer_mx(signed **matrix, signed dimension) 102 | { 103 | printf("\n"); 104 | 105 | for (signed i = null; i < dimension; i++) 106 | { 107 | for (signed j = null; j < dimension; j++) 108 | { 109 | printf("\t %d", matrix[i][j]); 110 | } 111 | printf("\n"); 112 | } 113 | } 114 | 115 | -------------------------------------------------------------------------------- /Assignment_12/p1.c: -------------------------------------------------------------------------------- 1 | // simple c program to find and replace all occurences of a word in a text file using a function // 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #define null 0 8 | #define max_string 100 // max_string = maximum string length // // edit this according to your needs // 9 | 10 | // assignment_11/sourcep1.txt - original file that we will use in this program // 11 | // this will get modified after running this program // 12 | 13 | // we have to assume that source string and replacement string are of the same length so in this program I will be replacing mine with your// 14 | 15 | // function definitions // 16 | 17 | void find_and_replace(char *source_file , char *word_to_find , char *word_to_replace); // function to find and replace all occurences of a word in a file where source file, word to find and word to replace are taken as input from the user// 18 | 19 | // driver code// 20 | signed main(void) 21 | { 22 | char source_file[max_string], word_to_find[max_string], word_to_replace[max_string]; 23 | printf("\n Please enter the source file name(including extension): "); // source file name // 24 | scanf("%s", source_file); // source file name // 25 | printf("\n\n\t NOTE: The word to find and the word to replace should be of the same length or the program would misbehave. This is in accordance with the assignment requirements.\n "); 26 | printf("\n Please enter the word to find: "); // word to find // 27 | scanf("%s", word_to_find); // word to find // 28 | printf("\n Please enter the word to replace: "); // word to replace // 29 | scanf("%s", word_to_replace); // word to replace // 30 | find_and_replace(source_file, word_to_find, word_to_replace); // function call // 31 | return null; 32 | } 33 | 34 | void find_and_replace(char *source_file , char *word_to_find , char *word_to_replace) 35 | { 36 | // to open both files // 37 | FILE *fp1, *fp2; 38 | char ch; 39 | int i, j, flag; 40 | fp1 = fopen(source_file, "r"); // source file // 41 | fp2 = fopen("temp.txt", "w"); // temporary file // 42 | 43 | // to read the file contents into a string // 44 | char *string = (char *)malloc(max_string * sizeof(char)); // string to store the contents of the source file // 45 | i = null; 46 | while ((ch = fgetc(fp1)) != EOF) 47 | { 48 | string[i] = ch; // storing the contents of the source file into a string // 49 | i++; 50 | } 51 | string[i] = '\0'; // null character at the end of the string // 52 | fclose(fp1); 53 | 54 | // to find and replace the word // 55 | i = null; 56 | while (string[i] != '\0') 57 | { 58 | j = null; 59 | flag = null; 60 | while (string[i] == word_to_find[j]) 61 | { 62 | i++; 63 | j++; 64 | if (word_to_find[j] == '\0') 65 | { 66 | flag = 1; 67 | break; 68 | } 69 | } 70 | if (flag == 1) 71 | { 72 | fprintf(fp2, "%s", word_to_replace); // writing the word to replace in the temporary file // 73 | } 74 | else 75 | { 76 | fprintf(fp2, "%c", string[i]); // writing the word to find in the temporary file // 77 | i++; 78 | } 79 | } 80 | fclose(fp2); 81 | 82 | // to copy the contents of temp.txt to source_file // 83 | fp1 = fopen(source_file, "w"); // source file // 84 | fp2 = fopen("temp.txt", "r"); // temporary file // 85 | while ((ch = fgetc(fp2)) != EOF) 86 | { 87 | fputc(ch, fp1); // copying the contents of the temporary file to the source file // 88 | } 89 | rename(source_file, "output_sourcep1.txt"); // renaming the source file // 90 | fclose(fp1); // closing the source file // 91 | fclose(fp2); // closing the temporary file // 92 | // to delete the temp.txt file // 93 | remove("temp.txt"); // deleting the temporary file // 94 | // to remove the string from the memory // 95 | free(string); 96 | } 97 | -------------------------------------------------------------------------------- /Assignment_12/p4.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #define null 0 7 | #define max_string 100 8 | #define max_students 10 9 | #define max_marks_digits 6 10 | 11 | 12 | struct student 13 | { 14 | signed roll_no; 15 | char name[max_string]; 16 | signed marks_in_sub1; 17 | signed marks_in_sub2; 18 | signed marks_in_sub3; 19 | signed marks_in_sub4; 20 | signed marks_in_sub5; 21 | signed marks_in_sub6; 22 | signed total; 23 | }; 24 | 25 | void db_function(char *filename); 26 | void assign_string_to_struct(char *string, struct student *student); 27 | void display_struct(struct student *student); 28 | void db_create(char *filename, struct student *student); 29 | void write_struct_to_file(char *filename, struct student *student); 30 | 31 | signed main(void) 32 | { 33 | char filename[max_string]; 34 | char filename2[max_string]; 35 | struct student student; 36 | printf("\n Please enter the filename(with extension) : "); 37 | scanf("%s", filename); 38 | printf("\n Please enter the filename(with extension) where you want to store the database : "); 39 | scanf("%s", filename2); 40 | db_function(filename); 41 | write_struct_to_file(filename2, &student); 42 | return null; 43 | } 44 | 45 | 46 | 47 | void db_function(char *filename) 48 | { 49 | char string[max_string]; 50 | struct student student; 51 | FILE *file; 52 | file = fopen(filename, "r"); 53 | if (file == null) 54 | { 55 | printf("\n Error opening file. Please check if the file exists and try again. "); 56 | exit(null); 57 | } 58 | else 59 | { 60 | fscanf(file, "%s", string); 61 | fclose(file); 62 | assign_string_to_struct(string, &student); 63 | display_struct(&student); 64 | write_struct_to_file(filename, &student); 65 | } 66 | } 67 | 68 | 69 | void assign_string_to_struct(char *string, struct student *student) 70 | { 71 | char *token; 72 | token = strtok(string, ","); 73 | student->roll_no = atoi(token); 74 | token = strtok(null, ","); 75 | strcpy(student->name, token); 76 | token = strtok(null, ","); 77 | student->marks_in_sub1 = atoi(token); 78 | token = strtok(null, ","); 79 | student->marks_in_sub2 = atoi(token); 80 | token = strtok(null, ","); 81 | student->marks_in_sub3 = atoi(token); 82 | token = strtok(null, ","); 83 | student->marks_in_sub4 = atoi(token); 84 | token = strtok(null, ","); 85 | student->marks_in_sub5 = atoi(token); 86 | token = strtok(null, ","); 87 | student->marks_in_sub6 = atoi(token); 88 | student->total = student->marks_in_sub1 + student->marks_in_sub2 + student->marks_in_sub3 + student->marks_in_sub4 + student->marks_in_sub5 + student->marks_in_sub6; 89 | } 90 | 91 | 92 | void display_struct(struct student *student) 93 | { 94 | printf("\n\t\t ---------------------------------------------------"); 95 | printf("\n\t\t\t student database "); 96 | printf("\n\t\t ---------------------------------------------------"); 97 | printf("\n\n"); 98 | printf("\n Roll no. : %d", student->roll_no); 99 | printf("\n Name : %s", student->name); 100 | printf("\n Marks in subject 1 : %d", student->marks_in_sub1); 101 | printf("\n Marks in subject 2 : %d", student->marks_in_sub2); 102 | printf("\n Marks in subject 3 : %d", student->marks_in_sub3); 103 | printf("\n Marks in subject 4 : %d", student->marks_in_sub4); 104 | printf("\n Marks in subject 5 : %d", student->marks_in_sub5); 105 | printf("\n Marks in subject 6 : %d", student->marks_in_sub6); 106 | printf("\n Total : %d", student->total); 107 | printf("\n\n"); 108 | } 109 | 110 | 111 | void write_struct_to_file(char *filename, struct student *student) 112 | { 113 | FILE *file; 114 | char new_filename[max_string]; 115 | strcpy(new_filename, filename); 116 | strcat(new_filename, ".txt"); 117 | file = fopen(new_filename, "w"); 118 | if (file == null) 119 | { 120 | printf("\n Error opening file. Please check if the file exists and try again. "); 121 | exit(null); 122 | } 123 | else 124 | { 125 | fprintf(file, "Roll no. : %d", student->roll_no); 126 | fprintf(file, "\n Name : %s", student->name); 127 | fprintf(file, "\n Marks in subject 1 : %d", student->marks_in_sub1); 128 | fprintf(file, "\n Marks in subject 2 : %d", student->marks_in_sub2); 129 | fprintf(file, "\n Marks in subject 3 : %d", student->marks_in_sub3); 130 | fprintf(file, "\n Marks in subject 4 : %d", student->marks_in_sub4); 131 | fprintf(file, "\n Marks in subject 5 : %d", student->marks_in_sub5); 132 | fprintf(file, "\n Marks in subject 6 : %d", student->marks_in_sub6); 133 | fprintf(file, "\n Total : %d", student->total); 134 | fclose(file); 135 | } 136 | } 137 | 138 | void db_create(char *filename2, struct student *student) 139 | { 140 | FILE *file; 141 | file = fopen(filename2, "w"); 142 | if (file == null) 143 | { 144 | printf("\n Error opening file. Please check if the file exists and try again. "); 145 | exit(null); 146 | } 147 | else 148 | { 149 | for (signed i = 0; i < 10; i++) 150 | { 151 | fprintf(file, "%d,%s,%d,%d,%d,%d,%d,%d,%d", student[i].roll_no, student[i].name, student[i].marks_in_sub1, student[i].marks_in_sub2, student[i].marks_in_sub3, student[i].marks_in_sub4, student[i].marks_in_sub5, student[i].marks_in_sub6, student[i].total); 152 | fprintf(file, "\n"); 153 | } 154 | fclose(file); 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /Assignment_10/p6.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define null 0 5 | #define dimension 2 6 | 7 | 8 | signed square_matrix_maker(signed **matrix, signed dimensions); 9 | signed square_matrix_printer(signed **matrix, signed dimensions); 10 | signed matrix_multiplication(signed **A, signed **B, signed dimensions); 11 | signed square_matrix_printer_mx(signed **matrix, signed dimensions); 12 | signed square_matrix_inverter(signed **matrix, signed dimensions); 13 | signed store_product(signed **A, signed **B, signed dimensions); 14 | signed memory_allocator(signed **matrix, signed dimensions); 15 | signed memory_free(signed **matrix, signed dimensions); 16 | 17 | // driver code // 18 | signed main(void) 19 | { 20 | 21 | signed **A = (signed **)malloc(dimension * sizeof(signed *)); 22 | for (signed i = null; i < dimension; i++) 23 | { 24 | A[i] = (signed *)malloc(dimension * sizeof(signed)); 25 | } 26 | 27 | signed **B = (signed **)malloc(dimension * sizeof(signed *)); 28 | for (signed i = null; i < dimension; i++) 29 | { 30 | B[i] = (signed *)malloc(dimension * sizeof(signed)); 31 | } 32 | 33 | printf("\n Please enter the elements of the first matrix : "); 34 | square_matrix_maker(A, dimension); 35 | square_matrix_printer(A, dimension); 36 | printf("\n Please enter the elements of the second matrix : "); 37 | square_matrix_maker(B, dimension); 38 | square_matrix_printer(B, dimension); 39 | 40 | signed A_inverse[dimension][dimension]; 41 | signed B_inverse[dimension][dimension]; 42 | 43 | signed **A_inverse_pointer = (signed **)malloc(dimension * sizeof(signed *)); 44 | for (signed i = null; i < dimension; i++) 45 | { 46 | A_inverse_pointer[i] = (signed *)malloc(dimension * sizeof(signed)); 47 | } 48 | 49 | signed **B_inverse_pointer = (signed **)malloc(dimension * sizeof(signed *)); 50 | for (signed i = null; i < dimension; i++) 51 | { 52 | B_inverse_pointer[i] = (signed *)malloc(dimension * sizeof(signed)); 53 | } 54 | 55 | A_inverse_pointer = square_matrix_inverter(A, dimension); 56 | printf("\n The inverse of the first matrix is : "); 57 | square_matrix_printer(A_inverse_pointer, dimension); 58 | B_inverse_pointer = square_matrix_inverter(B, dimension); 59 | printf("\n The inverse of the second matrix is : "); 60 | square_matrix_printer(B_inverse_pointer, dimension); 61 | 62 | signed **product = (signed **)malloc(dimension * sizeof(signed *)); 63 | for (signed i = null; i < dimension; i++) 64 | { 65 | product[i] = (signed *)malloc(dimension * sizeof(signed)); 66 | } 67 | 68 | product = store_product(A, B, dimension); 69 | printf("\n The product of the two matrices is : "); 70 | square_matrix_printer_mx(product, dimension); 71 | signed **product_inverse = (signed **)malloc(dimension * sizeof(signed *)); 72 | for (signed i = null; i < dimension; i++) 73 | { 74 | product_inverse[i] = (signed *)malloc(dimension * sizeof(signed)); 75 | } 76 | 77 | product_inverse = square_matrix_inverter(product, dimension); 78 | printf("\n The inverse of the product of the two matrices is : "); 79 | square_matrix_printer(product_inverse, dimension); 80 | 81 | signed **check = (signed **)malloc(dimension * sizeof(signed *)); 82 | for (signed i = null; i < dimension; i++) 83 | { 84 | check[i] = (signed *)malloc(dimension * sizeof(signed)); 85 | } 86 | 87 | check = store_product(B_inverse_pointer, A_inverse_pointer, dimension); 88 | printf("\n The product of the inverse of the two matrices is : "); 89 | square_matrix_printer_mx(check, dimension); 90 | 91 | 92 | 93 | signed flag = null; 94 | for (signed i = null; i < dimension; i++) 95 | { 96 | for (signed j = null; j < dimension; j++) 97 | { 98 | if (check[i][j] == product_inverse[i][j]) 99 | { 100 | flag = 1; 101 | } 102 | else 103 | { 104 | flag = 0; 105 | break; 106 | } 107 | } 108 | } 109 | 110 | if (flag == 1) 111 | { 112 | printf("\n The formula (A.B)^-1 = (B^-1).(A^-1) is valid. "); 113 | } 114 | else 115 | { 116 | printf("\n The formula (A.B)^-1 = (B^-1).(A^-1) is invalid. "); 117 | } 118 | 119 | 120 | 121 | for (signed i = null; i < dimension; i++) 122 | { 123 | free(A[i]); 124 | } 125 | free(A); 126 | 127 | for (signed i = null; i < dimension; i++) 128 | { 129 | free(B[i]); 130 | } 131 | free(B); 132 | 133 | for (signed i = null; i < dimension; i++) 134 | { 135 | free(A_inverse_pointer[i]); 136 | } 137 | free(A_inverse_pointer); 138 | 139 | for (signed i = null; i < dimension; i++) 140 | { 141 | free(B_inverse_pointer[i]); 142 | } 143 | free(B_inverse_pointer); 144 | 145 | for (signed i = null; i < dimension; i++) 146 | { 147 | free(product[i]); 148 | } 149 | 150 | free(product); 151 | 152 | for (signed i = null; i < dimension; i++) 153 | { 154 | free(product_inverse[i]); 155 | } 156 | 157 | free(product_inverse); 158 | 159 | return null; 160 | 161 | 162 | } 163 | 164 | 165 | 166 | signed square_matrix_maker(signed **matrix, signed dimensions) 167 | { 168 | for (signed i = null; i < dimension; i++) 169 | { 170 | for (signed j = null; j < dimension; j++) 171 | { 172 | printf("\n Enter the element at position [%d][%d] : ", i, j); 173 | scanf("%d", &matrix[i][j]); 174 | } 175 | } 176 | return null; 177 | } 178 | 179 | 180 | signed square_matrix_printer(signed **matrix, signed dimensions) 181 | { 182 | printf("\n The matrix is : "); 183 | for (signed i = null; i < dimension; i++) 184 | { 185 | printf("\n"); 186 | for (signed j = null; j < dimension; j++) 187 | { 188 | printf("\t %d", matrix[i][j]); 189 | } 190 | } 191 | return null; 192 | } 193 | 194 | 195 | signed matrix_multiplication(signed **A, signed **B, signed dimensions) 196 | { 197 | signed **C = (signed **)malloc(dimension * sizeof(signed *)); 198 | for (signed i = null; i < dimension; i++) 199 | { 200 | C[i] = (signed *)malloc(dimension * sizeof(signed)); 201 | } 202 | 203 | for (signed i = null; i < dimension; i++) 204 | { 205 | for (signed j = null; j < dimension; j++) 206 | { 207 | C[i][j] = null; 208 | for (signed k = null; k < dimension; k++) 209 | { 210 | C[i][j] += A[i][k] * B[k][j]; 211 | } 212 | } 213 | } 214 | return C; 215 | } 216 | 217 | 218 | signed square_matrix_printer_mx(signed **matrix, signed dimensions) 219 | { 220 | printf("\n The multiplied matrix is : "); 221 | for (signed i = null; i < dimension; i++) 222 | { 223 | printf("\n"); 224 | for (signed j = null; j < dimension; j++) 225 | { 226 | printf("\t %d", matrix[i][j]); 227 | } 228 | } 229 | return null; 230 | } 231 | 232 | 233 | signed square_matrix_inverter(signed **matrix, signed dimensions) 234 | { 235 | signed determinant = null; 236 | signed **inverse = (signed **)malloc(dimension * sizeof(signed *)); 237 | for (signed i = null; i < dimension; i++) 238 | { 239 | inverse[i] = (signed *)malloc(dimension * sizeof(signed)); 240 | } 241 | 242 | for (signed i = null; i < dimension; i++) 243 | { 244 | for (signed j = null; j < dimension; j++) 245 | { 246 | inverse[i][j] = null; 247 | } 248 | } 249 | 250 | if (dimension == 2) 251 | { 252 | determinant = matrix[null][null] * matrix[1][1] - matrix[1][null] * matrix[null][1]; 253 | inverse[null][null] = matrix[1][1]; 254 | inverse[null][1] = -matrix[null][1]; 255 | inverse[1][null] = -matrix[1][null]; 256 | inverse[1][1] = matrix[null][null]; 257 | } 258 | else 259 | { 260 | printf("\n The dimension of the matrix is not 2. "); 261 | } 262 | 263 | for (signed i = null; i < dimension; i++) 264 | { 265 | for (signed j = null; j < dimension; j++) 266 | { 267 | inverse[i][j] = inverse[i][j] / determinant; 268 | } 269 | } 270 | return inverse; 271 | } 272 | 273 | 274 | signed store_product(signed **A, signed **B, signed dimensions) 275 | { 276 | signed **C = (signed **)malloc(dimension * sizeof(signed *)); 277 | for (signed i = null; i < dimension; i++) 278 | { 279 | C[i] = (signed *)malloc(dimension * sizeof(signed)); 280 | } 281 | 282 | for (signed i = null; i < dimension; i++) 283 | { 284 | for (signed j = null; j < dimension; j++) 285 | { 286 | C[i][j] = null; 287 | for (signed k = null; k < dimension; k++) 288 | { 289 | C[i][j] += A[i][k] * B[k][j]; 290 | } 291 | } 292 | } 293 | return C; 294 | } 295 | 296 | signed memory_free(signed **matrix, signed dimensions) 297 | { 298 | for (signed i = null; i < dimension; i++) 299 | { 300 | free(matrix[i]); 301 | } 302 | free(matrix); 303 | return null; 304 | } 305 | --------------------------------------------------------------------------------