Tuesday, 6 October 2015

WAP to print the sum and average of first n natural numbers.

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





No comments:

Post a Comment