Anyone please help me know what I'm I doing wrong, I been trying to figure it out literally for the past 3 hours.
Here's the problem:
Write a C program to read positive integers, until the value -1 is read and print the average of the values.
This is my code, the average is off for some reason:
Code:#include <stdio.h> int main (void) { int num,sum=0; double avg; printf("Type a positive number"); scanf("%d",&num); for(num;num>=-1;num--) { printf("%d\n",num); sum=sum+num; } avg= sum/(num+1); printf("\n\nThe average is:%d\n",avg); getch(); }



LinkBack URL
About LinkBacks


