Posts

WAP to add or to multiply two matrices of order nXn.

#include <stdio.h> int main() {     // Write C code here     int n1, n2, i, j, m1[10][10], m2[10][10], sum[10][10], mul[10][10], k;     printf("Enter the order of the matrix: ");     scanf("%d%d", &n1, &n2);     printf("Enter the elements of the 1st matrix: ");     for (i=0; i<n1; i++) {         for (j=0; j<n2; j++) {             scanf("%d", &m1[i][j]);         }     }     printf("Enter the elements of the 2st matrix: ");     for (i=0; i<n1; i++) {         for (j=0; j<n2; j++) {             scanf("%d", &m2[i][j]);         }     }     for (i=0; i...

WAP that inputs two arrays and saves sum of corresponding elements of these arrays in a third array

  #include <stdio.h> int main() {     int a[50], b[50], sum[50], i, n;     printf("Enter the Elements in an array: ");     scanf("%d", &n);     printf("Enter the Elements of 1st array: ");     for (i=0; i<n; i++)     scanf("%d", &a[i]);     printf("Enter the Elements of 2nd array: ");     for (i=0; i<n; i++)     scanf("%d", &b[i]);     for (i=0; i<n; i++)     sum[i] = a[i] + b[i];          printf("Sum of the corresponding element of 1st and 2nd array is ", sum[i]);     for (i=0; i<n; i++)     printf("%d,", sum[i]);     return 0; }

WAP to find the largest and second largest element in an array.

Image
Here is your code in C - #include <stdio.h> int main() {     int a[6], i, l1, l2;          printf ("Enter the elements of array: ");          for (i=0; i<6; i++) {         scanf("%d", &a[i]);     }          l1 = a[0];          l2= a[0];          for (i=0; i<6; i++) {                  if (l1<a[i]){             l2 = l1;             l1 = a[i];         }                  if (l2<a[i] && a[i]!=l1)             l2 = a[i]...

WAP that swaps values of two variables without third variable.

Image
 Here is your code in c:- #include <stdio.h> int main() {     int n1, n2;          printf("Enter the first number: ");          scanf("%d", &n1);          printf("Enter the Second number: ");          scanf("%d", &n2);          printf("The numbers before swap is n1 = %d and n2 = %d \n", n1, n2);          n1 = n1 + n2;     n2 = n1 - n2;     n1 = n1 - n2;          printf("The numbers after swap is n1 = %d and n2 = %d", n1 , n2);     return 0; }   Output:- Logic Behind Swap:- In the code:-           n1 = n1 + n2;                                      n2 = n1 -...

WAP that swaps values of two variables with third variable.

Image
Here is you code in C : -  #include <stdio.h> int main() {     // Intialisation of numbers and third variable     int n1, n2, temp;          printf("Enter the first number: ");          // Input of 1st variable     scanf("%d", &n1);          printf("Enter the Second number: ");          // Input of 2nd variable     scanf("%d", &n2);          printf("The numbers before swap is n1 = %d and n2 = %d \n", n1, n2);          // Below code is for swapping of two variable.     temp = n1;     n1 = n2;     n2 = temp;          printf("The numbers after swap is n1 = %d and n2 = %d", n1 , n2);     return 0; } Output:-       Logic behind swap...

WAP that calculates the simple interest and compound interest. The principal amount, rate of interest and time are entered through the keyboard.

Image
 Here is your code :- #include <stdio.h> #include <math.h> // used for pow function used in compound_Interest formula. int main() {     // Initialisation of variables.     float simple_Interest, compound_Interest, principle,                   rate_of_interest, time;          printf("Enter the Principal amount, rate of Interest and time:      ");          // Taking Input for principle amount, rate_of_interest and time.     scanf("%f%f%f", &principle, &rate_of_interest, &time);          // Using formula to find simple_Interest .     simple_Interest = (principle * rate_of_interest * time) / 100;     // Using formula to find compound_Interest .     compound_Interest =  principle * pow((1 + rate_of_interest/10...