Sunday, May 26, 2019

C programming : Program to find the average of natural numbers

/* Program to find the average of natural numbers */

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,sum=0;
float avg;
printf("\n Enter the value of n :");
scanf("%d",&n);
for (i=1;i<=n;i++)
sum=sum+i;
avg=sum/n;
printf("\n The average of natural numbers is %f",avg);
getch();
}

Output 

Enter the value of n
10
The average of natural numbers is 5.0000
 
Now the output will be seen as:
 


No comments:

Post a Comment

Function

FUNCTION C enables programmer to break up a program into segments commonly known as functions, each of which can be written more or...