Posts

Showing posts from March, 2021

CodeChef ATM Problem

 Q.  Pooja would like to withdraw  X  $US from an ATM. The cash machine will only accept the transaction if  X  is a multiple of 5, and Pooja's account balance has enough cash to perform the withdrawal transaction (including bank charges). For each successful withdrawal the bank charges 0.50 $US. Calculate Pooja's account balance after an attempted transaction. Input Positive integer 0 <  X  <= 2000 - the amount of cash which Pooja wishes to withdraw. Nonnegative number 0<=  Y  <= 2000 with two digits of precision - Pooja's initial account balance. Output Output the account balance after the attempted transaction, given as a number with two digits of precision. If there is not enough money in the account to complete the transaction, output the current bank balance. Example - Successful Transaction Input: 30 120.00 Output: 89.50 Example - Incorrect Withdrawal Amount (not multiple of 5) Input: 42 120.00 Output: 120.00 Exa...

GCD IN ARRAY

Image
 Here is Your code :- #include <stdio.h> #include <string.h> #include <math.h> #include <stdlib.h> int main() {     int arr[50], size, max1, max2, gcd, i, j, temp;     scanf("%d", &size);     for (i=0; i<size; i++) {         scanf("%d", &arr[i]);     }     for (i=0; i<size; i++) {         for (j=i; j<size; j++) {             if (arr[i]>arr[j]) {                 temp = arr[i];                 arr[i] = arr[j];                 arr[j] = temp;             }   ...

WAP to find the minimum and maximum element of the array by using functions.

  #include <stdio.h> int max(int arr[], int n) {     int max = arr[0];     for(int i=0; i<n; i++) {         if (max < arr[i])         max = arr[i];     }     return max; } int min(int arr[], int n) {     int min = arr[0];     for(int i=0; i<n; i++) {         if (min > arr[i])         min = arr[i];     }     return min; } int main() {     int n, arr[50], i;     printf("Enter the number of element in an array: ");     scanf("%d", &n);     printf("Enter the elements in the array: ");     for (i=0; i<n; i++)     scanf("%d", &arr[i]);     printf("The maximum element of array is %d\nThe minimum elemen...

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; }