+ 1

Hi! if i want to get largest value with using while how ? and what is the problem with my porgram i want to get the Max value .

#include<stdio.h> #include<math.h> int main () { int n,i; double value,max,sum,avg; printf("Enter how many values to consider :"); scanf("%d",&n); if(n>0){ i=1; sum=0; while(i<=n){ printf("Enter value %d:",i); scanf("%lf",&value); sum=sum+value; max=value; if(value>max) max=value; i++; } avg=sum/n; printf("Largest value= %.2f\n",max); printf("average=%.2f",avg); } else printf("ERROR"); return 0; }

5th Apr 2017, 7:48 AM
mohammed al-khalaf
mohammed al-khalaf - avatar
2 ответов
+ 1
thank you very much
5th Apr 2017, 8:07 AM
mohammed al-khalaf
mohammed al-khalaf - avatar
0
you have 2 assignments "max=value". remove the upper one, then it should work
5th Apr 2017, 7:56 AM
Petja Boigk
Petja Boigk - avatar