Wednesday 21 December 2011


TO DISPLAY FIRST ‘N’ ODD NUMBERS ALSO DISPLAY THIR SUM AND AVERAGE




#include<stdio.h>
Void main()
{
Int n,num=1,count=0;
Float sum=0.0,average;
Printf(“how many odd numbers?”);
Scanf(“%d”,&n);
Printf(“first %d odd numbers are :\n”,n);
For(;count<n;++count)
{
Printf(“%d\t”,num);
Sum+=num;
Num+=2;
}
Average=sum/n;
Printf(“\nsum of the first %d odd numbers is %g”,n,sum);
Printf(“average of the first %d odd numbers is %g”,n,average);
Getch();
}

No comments:

Post a Comment