/* 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
#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