c program to find the average and range of n numbers

Description


This program finds the average and range of n numbers. The value for n is read into the variable n. The program uses while loop to repeatedly read n values. The variables l and s is used to store the smallest and largest values, that can be used to find the range. 



Program



#include<stdio.h>

#include<conio.h>

void main()

{

int n,a,l=0,flag=1,sum=0,range,i=1,s,avg;

clrscr();

printf("enter the value of n: ");

scanf("%d",&n);

printf("enter the numbers");

while(i<=n)

{

scanf("%d",&a);

if(flag==1)

{

s=a;

flag=0;

}

if(a>l)

{

l=a;

}

if(a<s)

{

s=a;

}

sum=sum+a;

i++;

}

avg=sum/n;

range=l-s;

printf("Average=%d",avg);

printf("Range=%d",range);

getch();

}

2 comments:

Anonymous said...

Thank you

Anonymous said...

Average and range of n numbers c program