Write a C Program to read array of integers and print its sum and average. - Pratik Ghelani

Pratik Ghelani

Breaking

Friday, March 29, 2019

Write a C Program to read array of integers and print its sum and average.

Write a C Program to read array of integers and print its sum and average.

Program:-
#include <stdio.h>
void main()
{
    int Arr[100], n, i, sum = 0;

    printf("Enter the number of elements : ");
    scanf("%d", &n);

    for (i = 0; i < n; i++)
    {
        printf("Enter element %d : ", i + 1);
        scanf("%d", &Arr[i]);
        sum += Arr[i];
    }
    printf("\nThe sum of the array is : %d", sum);
    printf("\nThe average of the array is : %0.2f", (float)sum / n);
}

Output:-




No comments:

Post a Comment