Enter n: 2
6+12
Sum is: 18
Average is: 9.0
CODE :: #include <stdio.h>
int main ()
{
int n,i=2,j,c=0,sum=0;
double avg;
printf("Enter n: ");
scanf("%d",&n);
while(c!=n)
{
if(i%3==0)
{
if(c<n-1) printf("%d+",i);
else printf("%d",i);
sum=sum+i;
c++;
}
i=i+2;
}
printf("\nSum is: %d",sum);
printf("\nAverage is: %.1lf",sum/(double)n);
return 0;
}
No comments:
Post a Comment