1. Question:C program for atm machine 

    Answer
    #include<stdio.h>
    
    int totalThousand =1000;
    int totalFiveFundred =1000;
    int totalOneHundred =1000;
    
    int main(){
    
        unsigned long withdrawAmount;
        unsigned long totalMoney;
    
        int thousand=0,fiveHundred=0,oneHundred=0;
    
        printf("Enter the amount in multiple of 100: ");
        scanf("%lu",&withdrawAmount);
    
        if(withdrawAmount %100 != 0){
             printf("Invalid amount;");
             return 0;
        }
    
        totalMoney = totalThousand * 1000 + totalFiveFundred* 500 +  totalOneHundred*100;
    
        if(withdrawAmount > totalMoney){
             printf("Sorry,Insufficient money");
             return 0;
        }
    
        thousand = withdrawAmount / 1000;
        if(thousand > totalThousand)
             thousand = totalThousand;
        withdrawAmount = withdrawAmount - thousand * 1000;
    
        if (withdrawAmount > 0){
             fiveHundred = withdrawAmount / 500;
             if(fiveHundred > totalFiveFundred)
                 fiveHundred = totalFiveFundred;
             withdrawAmount = withdrawAmount - fiveHundred * 500;
        }
    
        if (withdrawAmount > 0)
             oneHundred = withdrawAmount / 100;
    
        printf("Total 1000 note: %d\n",thousand);
        printf("Total  500 note: %d\n",fiveHundred);
        printf("Total  100 note: %d\n",oneHundred);
    
        return 0;
    }
    Sample output: Enter the amount in multiple of 100: 7800 Total 1000 note: 7 Total 500 note: 1 Total 100 note: 3






    1. Report
  2. Question:How to pass one dimensional array to function in c 

    Answer
    #include <stdio.h>
    #define N 5
    void fstore1D(int a[], int a_size);
    void fretrieve1D(int a[], int a_size);
    void fedit1D(int a[], int a_size);
    int main(){
    int a[N];
    printf("Input data into the matrix:\n");
    fstore1D(a, N);
    fretrieve1D(a, N);
    fedit1D(a, N);
    fretrieve1D(a, N);
    return 0;
    }
    
    void fstore1D(int a[], int n){
    int i;
    for ( i = 0; i < n; ++i )
    scanf("%d", &a[i]);
    }
    
    void fretrieve1D(int a[], int n){
    int i;
    for ( i = 0; i < n; ++i )
    printf("%6d ", a[i]);
    printf("\n");
    }
    
    void fedit1D(int a[], int n){
    int i, q;
    for ( i = 0; i < n; ++i ){
    printf("Prev. data: %d\nEnter 1 to edit 0 to skip.", a[i]);
    scanf("%d", &q);
    if ( q == 1 ){
    printf("Enter new value: ");
    scanf("%d", &a[i]);
    }
    }
    }






    1. Report
  3. Question:How to pass two dimensional array to a function in c 

    Answer
    #include <stdio.h>
    #define M 3
    #define N 5
    void fstore2D(int a[][N]);
    void fretrieve2D(int a[][N]);
    int main(){
      int a[M][N];
      printf("Input data in matrix (%d X %d)\n", M, N);
      fstore2D(a);
      fretrieve2D(a);
      return 0;
    }
    void fstore2D(int a[][N]){
        int i, j;
        for (i = 0; i < M; ++i){
        for (j = 0; j < N; ++j)
             scanf("%d", &a[i][j]);
        }
    }
    void fretrieve2D(int a[][N]){
       int i, j;
       for ( i = 0; i < M; ++i ){
           for ( j = 0; j < N; ++j)
                printf("%6d ", a[i][j]);
           printf("\n");
       }
    }






    1. Report
  4. Question:Write a c program which takes password from users 

    Answer
    #include<stdio.h>
    #define MAX 500
    
    int main(){
    
        char password[MAX];
        char p;
        int i=0;
    
        printf("Enter the password:");
       
        while((p=getch())!= 13){
             password[i++] = p;
             printf("*");
        }
    
        password[i] = '\0';
        if(i<6)
             printf("\nWeak password");
        printf("\nYou have entered: %s",password);
        return 0;
    }
    Sample output: Enter the password:******* You have entered: fgt67m,






    1. Report
  5. Question:Write a scanf function in c programming language which accept sentence from user 

    Answer
    #include<stdio.h>
    #define MAX 500
    
    int main(){
    
        char arr[MAX];
    
        printf("Enter any sentence which can include spaces.\n");
        printf("To exit press enter key.\n");
        scanf("%[^\n]s",arr);
    
        printf("You had entered: \n");
        printf("%s",arr);
    
        return 0;
    }
    Sample output: Enter any sentence which can include spaces. To exit press enter key. May I help you? You had entered: May I help you?






    1. Report
Copyright © 2025. Powered by Intellect Software Ltd