ProAnswers.org

Write a C program to find out the Sum and Average of First N Numbers?

#include

#include 

void main() 

{ 

int i,sum=0,n; 

float avg; 

clrscr(); 

printf(“enter the value of n

”);

scanf(“%d”,&n); 

for(i=1;i<=n;i++) 

{ 

sum=sum+i; 

} 

printf(“sum=%d

”,sum);

avg=sum/n; 

printf(“average=%f”,c); 

getch(); 

} 

Output: 

enter the value of n 

5 

sum=15 

average=3