Wednesday 6 February 2013

Write a c program to accept n numbers from user store these numbers into an array & calculate average of n numbers



#include<stdio.h>
#include<conio.h>
  void main()
{
  int a[20],n,i,t=0;
  float avg=0;
  clrscr();
  printf("\nEnter the n numbers: ");
  scanf("%d",&n);
  printf("\nEnter the numbers: ");
  for(i=0;i<n;i++)
{
  scanf("%d",&a[i]);
  t=t+a[i];
}
  printf("\nTotal is:%d",t);
  avg=(float)t/n;
  printf("\nAverage of n numbers is: %f",avg);
  getch();
}

//OUTPUT:
//Enter the n numbers: 10
//Enter the numbers: 1
//2
//3
//4
//5
//6
//7
//8
//9
//10

//Total is: 55
//Average of n numbers is: 5.5

No comments:

Post a Comment