Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/ #include <stdio.h> int main() { int a,b=0; double c,d=0; while(1) { scanf("%d", &a); if(a<0) break; else { b+=a; d++; } } c=b/d; printf("%.2lf\n",c); return 0; }
here, what's the use of 'b'?
ReplyDeleteb will calculate the total sum.
ReplyDeleteWhat if d was an int instead of being double?
ReplyDelete#include
ReplyDeleteint main()
{
float n,a,sum=0;
int count=0;
scanf("%f",&n);
while(n>=0)
{
count++;
sum+=n;
scanf("%f",&n);
}
a=sum/(float)count;
printf("%.2f\n",a);
return 0;
}
reply....