Saved Bookmarks
| 1. |
Write a C++ program to find the sum and average of n numbers. |
|
Answer» #include<iostream.h> #include<iomaip.h> void main () { int a [100],n,sum,index; float average; cout<<"Now, enter the numbers"; for (index = 0; index<n; index++) cin>> a[index]; sum = 0; for (index = 0; index<n; index++) sum = sum + a[index]; average = (float)sum/n; cout<<"sum= "<<sum<<end1; cout<<"Average = "<<averge<<end1; } |
|