//In the Name of ALLAH //This program takes some numbers (the user decides how many numbers to enter) and calculates their sum and average. #include #include void main() { int n; int i,num,sum; sum=0; float ave; ave=0; //If we compile this program with .C format, the compiler will give an error for declaring "ave" after assigning a value for "sum". //This is the mentioned error: "Declaration is not allowed here" //For fixing this problem, we should simply define "ave" before assigning "sum" otherwise we save the program with .CPP format as it is now. //************ clrscr(); printf ("How many numbers do you want to enter?\n"); scanf("%d",&n); printf("Enter your numbers (%d times):\n",n ); for(i=1;i<=n;i++) { scanf("%d",&num); sum= num+sum; } printf("Your sum is: %d",sum); ave=(float)(sum)/n; printf("\nYour average is %f\n", ave); getch(); }