Hello There, Guest! Login Register
Advertise Here | Remove Ads

C Program to Calculate Average Using Arrays

  • 0 Vote(s) - 0 Average


06-17-2016, 06:23 PM #1
Shompa Offline FFU SENIOR FFU SENIOR
VIP MEMBER
Posts:2,319 Threads:222 Joined:Sep 2014 Reputation: 28 Sex Female
FFUC: $0
This program takes n number of element from user(where, n is specified by user), stores data in an array and calculates the average of those numbers.

Code:
#include <stdio.h>
int main(){
    int n, i;
    float num[100], sum=0.0, average;
    printf("Enter the numbers of data: ");
    scanf("%d",&n);
    while (n>100 || n<=0)
    {
        printf("Error! number should in range of (1 to 100).\n");
        printf("Enter the number again: ");
        scanf("%d",&n);
    }
   for(i=0; i<n; ++i)
   {
      printf("%d. Enter number: ",i+1);
      scanf("%f",&num[i]);
      sum+=num[i];
   }
   average=sum/n;
   printf("Average = %.2f",average);
   return 0;
}







Forum Jump:


Users browsing this thread:1 Guest(s)

Advertise Here | Remove Ads