Posts

Showing posts from February, 2021

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...