Array

Input age of n people and finding average.

#include <stdio.h>

int main()
{
    int s, sum = 0;
    printf("Enter number element in array: ");
    scanf("%d", &s);
    int arr[s];
    for (int i = 0; i < s; i++)
    {
        printf("Enter age person %d = ", i + 1);
        scanf("%d", &arr[i]);
        sum += arr[i];
    }
    for (int i = 0; i < s; i++)
    {
        printf("\nAge of person %d = %d", i + 1, arr[i]);
    }
    float avg = (float)sum / s;
    printf("\nAverage age of people is %.2f.", avg);
    return 0;
}

Popular posts from this blog

AKTU PROGRAMING FOR PROBLEM SOLVING LAB ( ALL QUESTION )

Pattern with nested loop under construction