Advertisement
coffeebeforecode

Untitled

Jun 8th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.37 KB | None | 0 0
  1. /*
  2. b) Write a structure to store the name, account number and balance of
  3.  Customers (more than 10) and store their information.
  4.  i) Write a function to print the names of all the customers having balance
  5.  less than $200.
  6.  ii) Write a function to add $100 in the balance of all the customers having
  7.  more than $1000 in their balance and then print the incremented value of
  8.  their balance.
  9.  
  10. */
  11.  
  12. #include<stdio.h>
  13. #include <stdlib.h>
  14.  
  15. #define MAX 15
  16. /* Defining Structre*/
  17. struct bank
  18. {
  19.     char name[20];
  20.     int acc_no;
  21.     int bal;
  22. };
  23. /*Function to find the details of customer whose balance < 100.*/
  24. void check(struct bank b[],int n) /*Passing Array of structure to function*/
  25. {
  26.     int i;
  27.     printf("\nCustomer Names whose Balance < $200\n");
  28.     printf("----------------------------------------------\n");
  29.     for(i=0;i<n;i++)
  30.     {    
  31.         if(b[i].bal<200)
  32.         {
  33.             //printf("Account Number : %d\n",b[i].acc_no);
  34.             printf("Name           : %s\n",b[i].name);
  35.             //printf("Balance        : %d\n",b[i].bal);
  36.             printf("------------------------------\n");
  37.           }
  38.      }
  39. }
  40.  
  41. void addHundred(struct bank b[],int n) /*Passing Array of structure to function*/
  42. {
  43.     int i;
  44.     printf("\nCustomer Details whose Balance > $1000 after adding $100\n");
  45.     printf("----------------------------------------------\n");
  46.     for(i=0;i<n;i++)
  47.     {    
  48.         if(b[i].bal>1000)
  49.         {
  50.             //printf("Account Number : %d\n",b[i].acc_no);
  51.             b[i].bal += 100;
  52.             printf("Name           : %s\n",b[i].name);
  53.             printf("Balance        : %d\n",b[i].bal);
  54.             printf("------------------------------\n");
  55.           }
  56.      }
  57. }
  58.  
  59. int main()
  60. {  
  61.     struct bank b[MAX];
  62.     printf("Enter number of customers: ");
  63.     int n;
  64.     scanf("%d", &n);
  65.     int i;
  66.     for(i=0;i<n;i++)
  67.     {
  68.           printf("Enter Details of Customer %d\n",i+1);
  69.           printf("------------------------------\n");
  70.           printf("Enter Account Number : ");
  71.           scanf("%d",&b[i].acc_no);
  72.           printf("Enter Name           : ");
  73.           scanf("%s",b[i].name);
  74.           printf("Enter Balance        : ");
  75.           scanf("%d",&b[i].bal);
  76.           printf("------------------------------\n");
  77.      }
  78.     check(b,n);           //call function check
  79.     addHundred(b, n);
  80.     return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement