Programming for Problem Solving (3110003)

BE | Semester-1   Winter-2019 | 07-01-2020

Q4) (c)

Write a C program to read 10 numbers from user and store them in an array. Display Sum, Minimum and Average of the numbers.

Program

#include <stdio.h> 
void main() {
    int a[10], i;
    int sum = 0, min;
    float avg = 0;

    for(i=0; i<10; i++) {
        printf("Enter a[%d]: ", i);
        scanf("%d", &a[i]);
    }

    min = a[0];
    for(i=0; i<10; i++) {
        sum += a[i];
        if (a[i] < min)
            min = a[i];
    }
    avg = sum / 10;
   printf("Sum = %d\nMin Element = %d\nAverage = %.2f\n", sum, min, avg);

    printf("\n");
}

Output:

Enter a[0]: 1
Enter a[1]: 1
Enter a[2]: 1
Enter a[3]: 1
Enter a[4]: 1
Enter a[5]: 1
Enter a[6]: 1
Enter a[7]: 1
Enter a[8]: 1
Enter a[9]: 1
Sum = 10
Min Element = 1
Average = 1.00