├── Assignment 1 .c ├── Assignment 2.c ├── Assignment 3.c ├── Assignment 4.c ├── Assignment2(Updated).c ├── Assignment3D-1.c ├── Assignment3D-1.exe ├── AssignmentLab.c ├── Hello.c ├── Hello.cpp ├── Hello.exe ├── LabProgram.c ├── LabProgram.exe ├── Practice.c ├── cheque1.c ├── cheque1.exe ├── rand.c └── rand.exe /Assignment 1 .c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | 6 | float m = 20; /*20kg*/ 7 | float v = 5; /*5 m/s*/ 8 | float KE; 9 | KE = 0.5*m*v*v; 10 | 11 | printf("KE = %f",KE); 12 | 13 | } -------------------------------------------------------------------------------- /Assignment 2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | 6 | float m = 20; /*20kg*/ 7 | float g = 9.8; /*9.8 m/s^2*/ 8 | float h = 30; /*30m*/ 9 | float P; 10 | P = m*g*h; 11 | 12 | printf("P = %f",P); 13 | 14 | } -------------------------------------------------------------------------------- /Assignment 3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | 6 | float r = 5; /*5m*/ 7 | float A; 8 | A = 3.14 * r * r; 9 | printf("A = %f", A); 10 | 11 | } -------------------------------------------------------------------------------- /Assignment 4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main() 4 | { 5 | 6 | float A = 23.5; 7 | float B = 15.9; 8 | float C = 16.5; 9 | 10 | float SUM; 11 | SUM = A+B+C; 12 | 13 | float AVG; 14 | AVG = SUM/3; 15 | 16 | printf("SUM = %f",SUM); 17 | printf("\n"); 18 | printf("AVG = %f",AVG); 19 | 20 | } -------------------------------------------------------------------------------- /Assignment2(Updated).c: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | void main() 4 | { 5 | int a,b; 6 | 7 | //taking user input for the values a & b 8 | printf("Enter a Value for a: "); 9 | scanf("%d", &a); 10 | printf("Enter a Value for b: "); 11 | scanf("%d", &b); 12 | 13 | //printing the taken values 14 | printf("The value of 'a' is %d \n", a); 15 | printf("The value of 'b' is %d \n", b); 16 | 17 | //Logic for swapping numbers without 3rd variable 18 | a = a + b; 19 | b = a - b; 20 | a = a - b; 21 | 22 | //printing the swapped values 23 | printf("Now the swapped values of a & b are %d & %d respectively", a, b); 24 | 25 | } 26 | 27 | */ 28 | 29 | 30 | /* 31 | 32 | #include 33 | void main() 34 | { 35 | 36 | float P,T,R,PTR,SI; 37 | 38 | //Taking user input for the values to be used 39 | printf("Enter the priciple amount: "); 40 | scanf("%f", &P); 41 | printf("Enter the Interest Rate: "); 42 | scanf("%f", &R); 43 | printf("Enter the Time Period in Years: "); 44 | scanf("%f", &T); 45 | 46 | //Logic for calculating interest 47 | PTR = P * T * R; 48 | SI = PTR / 100; 49 | 50 | //Printing the value of SI 51 | printf("The Simple Interest amount is %f", SI); 52 | 53 | } 54 | 55 | */ 56 | 57 | 58 | /* 59 | #include 60 | void main() 61 | { 62 | int n,i,fact = 1; 63 | 64 | //Taking user input for the value to which the factorial is to be calculated 65 | printf("Enter a value: "); 66 | scanf("%d", &n); 67 | 68 | //Logic for finding factorial 69 | for(i = 1; i <= n; i++) 70 | { 71 | fact *= i; // fact = fact * i 72 | } 73 | 74 | // Printing the value of factorial for the given number 75 | printf("The factorial for the given value is %d", fact); 76 | 77 | } 78 | 79 | */ 80 | 81 | 82 | /* 83 | #include 84 | #include 85 | #include 86 | 87 | void main() 88 | { 89 | float a, b, c, D, R1, R2, Real, Img; 90 | 91 | // Taking user input for the coefficients for the equation 92 | printf("Enter a value for the coefficient of a: "); 93 | scanf("%f", &a); 94 | printf("Enter a value for the coefficient of b: "); 95 | scanf("%f", &b); 96 | printf("Enter a value for the coefficient of c: "); 97 | scanf("%f", &c); 98 | 99 | //Logic for finiding the Nature of the roots of the given equation 100 | D = b*b - 4*a*c; 101 | 102 | if (D == 0) 103 | { 104 | 105 | printf("The solutions of the given qudratic eqautions is real anf equal\n"); 106 | 107 | //Logic for finding the roots 108 | R1 = R2 = -b / 2*a; 109 | 110 | printf("The roots of the equation are %f and %f ",R1,R2); 111 | 112 | } 113 | 114 | else if (D > 0) 115 | { 116 | printf("The solutions of the given quadratic equation is real and unique\n"); 117 | 118 | //Logic for finding the roots 119 | R1 = (-b + sqrt(D)) / 2*a; 120 | R2 = (-b - sqrt(D)) / 2*a; 121 | 122 | printf("The roots of the quadratic equations are resectively %f & %f",R1,R2); 123 | } 124 | 125 | else 126 | { 127 | 128 | printf("The solutins of the given quadratic equation is imaginary\n"); 129 | 130 | //Logic for finding the roots 131 | Real = -b / (2*a); 132 | Img = sqrt(-D)/ (2*a); 133 | 134 | printf("The roots of the given quadratic equation are %f+%fi & %f-%fi respectively",Real,Img,Real,Img); 135 | 136 | } 137 | 138 | } 139 | 140 | */ 141 | 142 | /* 143 | 144 | #include 145 | void main() 146 | { 147 | int a, rem, og, rev = 0; 148 | 149 | //Taking user input for the number 150 | printf("\nEnter a number to check if it is a palindrome or not: "); 151 | scanf("%d", &a); 152 | 153 | og = a; //storing the original value 154 | 155 | //Loop to reverse the given number 156 | while (a != 0) 157 | { 158 | //Logic to reverse the number by one digit each time 159 | rem = a % 10; 160 | rev = rev * 10 + rem; 161 | 162 | a /= 10; 163 | 164 | } 165 | 166 | //Conditional statement to check if the no. is palindrome 167 | if ( og == rev) 168 | { 169 | printf("The given number %d is a palindrome\n", og); 170 | } 171 | else 172 | { 173 | printf("The given number %d is not a palindrome\n", og); 174 | } 175 | } 176 | 177 | */ 178 | 179 | 180 | /* 181 | 182 | #include 183 | void main() 184 | { 185 | int a,n,i,og; 186 | 187 | //Taking user input for the number and the power to raise it with 188 | printf("Enter the number: "); 189 | scanf("%d", &a); 190 | printf("Choose a power to raise the number with: "); 191 | scanf("%d", &n); 192 | 193 | //Storing the value of original value 194 | og = a; 195 | 196 | //Logic to raise the number by a certain power 197 | for (i = 1; i < n; i++) 198 | { 199 | a *= og; 200 | } 201 | 202 | //Printing the result 203 | printf("The given number %d raised to the power of %d is %d",og,n,a); 204 | 205 | } 206 | 207 | */ -------------------------------------------------------------------------------- /Assignment3D-1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | int add(int A, int B) 5 | { 6 | /*int A, B; 7 | printf("Enter value for A:"); 8 | scanf("%d",&A); 9 | printf("Enter value for B:"); 10 | scanf("%d",&B); 11 | printf("The Sum of the values A and B is: %d",A+B);*/ 12 | return A+B; 13 | } 14 | 15 | 16 | int sub(int A,int B) 17 | { 18 | /*int A, B; 19 | printf("Enter value for A:"); 20 | scanf("%d",&A); 21 | printf("Enter value for B:"); 22 | scanf("%d",&B); 23 | printf("The difference between A and B is: %d",A-B);*/ 24 | return A-B; 25 | } 26 | 27 | 28 | 29 | int mul(int A, int B) 30 | { 31 | /*int A, B; 32 | printf("Enter value for A:"); 33 | scanf("%d",&A); 34 | printf("Enter value for B:"); 35 | scanf("%d",&B); 36 | printf("The product of A and B is equal to:%d",A*B);*/ 37 | return A*B; 38 | } 39 | 40 | 41 | int div(int A, int B) 42 | { 43 | /*int A, B; 44 | printf("Enter value for A:"); 45 | scanf("%d",&A); 46 | printf("Enter value for B:"); 47 | scanf("%d",&B); 48 | printf("The division of A and B is equal to:%d",A/B);*/ 49 | return A/B; 50 | } 51 | 52 | void main() 53 | { 54 | int A,B,Op; 55 | printf("Enter value for A: "); 56 | scanf("%d",&A); 57 | printf("Enter value for B: "); 58 | scanf("%d",&B); 59 | printf("Enter operation Number \n1)Additon\n2)Subtraction\n3)Multiplication\n4)Division\n Operation Number: "); 60 | scanf("%d",&Op); 61 | switch(Op) 62 | { 63 | case 1: 64 | printf("Addition: %d\n",add(A,B)); 65 | break; 66 | case 2: 67 | printf("Subtraction: %d\n",sub(A,B)); 68 | break; 69 | case 3: 70 | printf("Multiplication: %d\n",mul(A,B)); 71 | break; 72 | case 4: 73 | printf("Division: %d\n",div(A,B)); 74 | break; 75 | default: 76 | printf("Invalid operation\n"); 77 | break; 78 | } 79 | 80 | 81 | } -------------------------------------------------------------------------------- /Assignment3D-1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Programs/f292b71eff1e06d32e2c7b433048358077199039/Assignment3D-1.exe -------------------------------------------------------------------------------- /AssignmentLab.c: -------------------------------------------------------------------------------- 1 | /* 2 | #include 3 | void main() 4 | { 5 | int a,b; 6 | printf("Enter a Value for a: "); 7 | scanf("%d", &a); 8 | printf("Enter a Value for b: "); 9 | scanf("%d", &b); 10 | printf("The value of 'a' is %d \n", a); 11 | printf("The value of 'b' is %d \n", b); 12 | a = a + b; 13 | b = a - b; 14 | a = a - b; 15 | printf("Now the swapped values of a & b are %d & %d respectively", a, b); 16 | } 17 | 18 | */ 19 | 20 | 21 | /* 22 | 23 | #include 24 | void main() 25 | { 26 | 27 | float P,T,R,PTR,SI; 28 | printf("Enter the priciple amount: "); 29 | scanf("%f", &P); 30 | printf("Enter the Interest Rate: "); 31 | scanf("%f", &R); 32 | printf("Enter the Time Period in Years: "); 33 | scanf("%f", &T); 34 | PTR = P * T * R; 35 | SI = PTR / 100; 36 | printf("The Simple Interest amount is %f", SI); 37 | 38 | } 39 | 40 | */ 41 | 42 | 43 | /* 44 | #include 45 | void main() 46 | { 47 | int n,i,fact = 1; 48 | printf("Enter a value: "); 49 | scanf("%d", &n); 50 | for(i = 1; i <= n; i++) 51 | { 52 | fact *= i; 53 | } 54 | printf("The factorial for the given value is %d", fact); 55 | 56 | } 57 | 58 | */ 59 | 60 | 61 | /* 62 | #include 63 | #include 64 | #include 65 | 66 | void main() 67 | { 68 | float a, b, c, D, R1, R2, Real, Img; 69 | printf("Enter a value for the coefficient of a: "); 70 | scanf("%f", &a); 71 | printf("Enter a value for the coefficient of b: "); 72 | scanf("%f", &b); 73 | printf("Enter a value for the coefficient of c: "); 74 | scanf("%f", &c); 75 | 76 | D = b*b - 4*a*c; 77 | 78 | if (D == 0) 79 | { 80 | 81 | printf("The solutions of the given qudratic eqautions is real anf equal\n"); 82 | R1 = R2 = -b / 2*a; 83 | printf("The roots of the equation are %f and %f ",R1,R2); 84 | 85 | } 86 | 87 | else if (D > 0) 88 | { 89 | printf("The solutions of the given quadratic equation is real and unique\n"); 90 | R1 = (-b + sqrt(D)) / 2*a; 91 | R2 = (-b - sqrt(D)) / 2*a; 92 | printf("The roots of the quadratic equations are resectively %f & %f",R1,R2); 93 | } 94 | 95 | else 96 | { 97 | 98 | printf("The solutins of the given quadratic equation is imaginary\n"); 99 | Real = -b / (2*a); 100 | Img = sqrt(-D)/ (2*a); 101 | printf("The roots of the given quadratic equation are %f+%fi & %f-%fi respectively",Real,Img,Real,Img); 102 | 103 | } 104 | 105 | } 106 | 107 | */ 108 | 109 | /* 110 | 111 | #include 112 | void main() 113 | { 114 | int a, rem, og, rev = 0; 115 | 116 | printf("\nEnter a number to check if it is a palindrome or not: "); 117 | scanf("%d", &a); 118 | og = a; 119 | 120 | while (a != 0) 121 | { 122 | rem = a % 10; 123 | rev = rev * 10 + rem; 124 | a /= 10; 125 | 126 | } 127 | 128 | if ( og == rev) 129 | { 130 | printf("The given number %d is a palindrome\n", og); 131 | } 132 | else 133 | { 134 | printf("The given number %d is not a palindrome\n", og); 135 | } 136 | } 137 | 138 | */ 139 | 140 | 141 | /* 142 | 143 | #include 144 | void main() 145 | { 146 | int a,n,i,og; 147 | printf("Enter the number: "); 148 | scanf("%d", &a); 149 | printf("Choose a power to raise the number with: "); 150 | scanf("%d", &n); 151 | og = a; 152 | 153 | for (i = 1; i < n; i++) 154 | { 155 | a *= og; 156 | } 157 | 158 | printf("The given number %d raised to the power of %d is %d",og,n,a); 159 | 160 | } 161 | 162 | */ -------------------------------------------------------------------------------- /Hello.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | void reverse_words(char *input_string) { 6 | char *word_start = input_string; 7 | char *word_end = input_string; 8 | 9 | while (*word_end) { 10 | if (*word_end == ' ') { 11 | // Reverse the characters of the word 12 | char *start = word_start; 13 | char *end = word_end - 1; 14 | 15 | while (start < end) { 16 | char temp = *start; 17 | *start = *end; 18 | *end = temp; 19 | start++; 20 | end--; 21 | } 22 | 23 | word_start = word_end + 1; 24 | } 25 | 26 | word_end++; 27 | } 28 | 29 | // Reverse the last word 30 | char *start = word_start; 31 | char *end = word_end - 1; 32 | 33 | while (start < end) { 34 | char temp = *start; 35 | *start = *end; 36 | *end = temp; 37 | start++; 38 | end--; 39 | } 40 | } 41 | 42 | int main() { 43 | char input_string[100]; 44 | 45 | printf("Enter a string: "); 46 | fgets(input_string, sizeof(input_string), stdin); 47 | 48 | // Remove newline character from input 49 | input_string[strcspn(input_string, "\n")] = 0; 50 | 51 | reverse_words(input_string); 52 | 53 | printf("Reversed string: %s\n", input_string); 54 | 55 | return 0; 56 | } -------------------------------------------------------------------------------- /Hello.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | std::cout << "Hello World"; 5 | return 0; 6 | } -------------------------------------------------------------------------------- /Hello.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Programs/f292b71eff1e06d32e2c7b433048358077199039/Hello.exe -------------------------------------------------------------------------------- /LabProgram.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int size; 6 | 7 | printf("Enter the size of the array: "); 8 | scanf("%d", &size); 9 | 10 | char arr[size + 1]; 11 | //char arr[size]; 12 | 13 | getchar(); 14 | 15 | for (int i = 0; i < size; i++) 16 | { 17 | printf("Enter element %d: ", i + 1); 18 | scanf("%c", &arr[i]); 19 | getchar(); 20 | } 21 | 22 | arr[size] = '\0'; 23 | 24 | printf("Array elements: %s\n", arr); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /LabProgram.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Programs/f292b71eff1e06d32e2c7b433048358077199039/LabProgram.exe -------------------------------------------------------------------------------- /Practice.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int dict(); 4 | void main() 5 | { 6 | int DD1, DD2; 7 | char MM1[3], MM2[3]; 8 | int YY1, YY2; 9 | 10 | printf("Enter 1st date (DD MMM YYYY): "); 11 | scanf("%d %s %d",&DD1,&MM1,&YY1); 12 | printf("Enter 2nd date (DD MMM YYYY): "); 13 | scanf("%d %s %d",&DD2,&MM2,&YY2); 14 | int monthnum1 = dict(strlwr(MM1)); 15 | int monthnum2 = dict(strlwr(MM2)); 16 | 17 | printf("%d %d", monthnum1,monthnum2); 18 | 19 | 20 | 21 | 22 | 23 | } 24 | 25 | int dict(char month) 26 | { 27 | char Months[13] = {"jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"}; 28 | 29 | for(int i = 0; i < 12; i++) 30 | { 31 | if(strcmp(month, Months[i]) == 0) 32 | { 33 | return i + 1; 34 | } 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /cheque1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char db[4][4][12] = { 7 | {"ENG23CS0267", "ENG23CS5507", "ENG23CS3423", "ENG23CS2324"}, 8 | {"ENG23CS3242", "ENG23CS2432", "ENG23CS1241", "ENG23CS2342"}, 9 | {"ENG23CS2134", "ENG23CS1342", "ENG23CS4231", "ENG23CS3421"}, 10 | {"ENG23CS4231", "ENG23CS3421", "ENG23CS1342", "ENG23CS2134"} 11 | }; 12 | 13 | char key[12]; 14 | int found = 0; // Flag to track if the key is found 15 | 16 | printf("Enter the key: "); 17 | scanf("%s", key); 18 | 19 | for(int i = 0; i < 4 && !found; i++) // Iterate over rows 20 | { 21 | for(int j = 0; j < 4; j++) // Iterate over columns 22 | { 23 | if(strcmp(key, db[i][j]) == 0) 24 | { 25 | printf("The given USN is present in the database\n"); 26 | found = 1; // Set the flag to indicate that the key has been found 27 | break; // Exit the inner loop once found 28 | } 29 | } 30 | } 31 | 32 | if (!found) 33 | { 34 | printf("The given USN is not present in the database\n"); 35 | } 36 | 37 | return 0; 38 | } 39 | -------------------------------------------------------------------------------- /cheque1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Programs/f292b71eff1e06d32e2c7b433048358077199039/cheque1.exe -------------------------------------------------------------------------------- /rand.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main() 6 | { 7 | long long temp; 8 | long long max = 999999999999; 9 | long long min = 100000000000; 10 | 11 | srand(time(0)); 12 | temp = (rand() % max) + min; 13 | 14 | printf("%lld\n", temp); 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /rand.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ArjiJethin/C-Programs/f292b71eff1e06d32e2c7b433048358077199039/rand.exe --------------------------------------------------------------------------------