Thursday, 12 May 2016

C++ Program of Array to Calculate Sum and Average of given Numbers

// This program calculates the average of any number of numbers.
// Using the for structure
#include <iostream>
using namespace std;
#include <iostream>
 
int main()
{
   int n, count;
   float x, sum, avg;
 
   sum = 0;
   cout << "How many numbers?  ";
   cin >> n;
   int size= n;
   int array[size];
   for (count=1; count<=n; count++){
       cout << "Enter Number:  ";
         cin >> array[n];
        sum = sum + array[n];
   }  //end for
   cout << "The sum is " << sum << endl;
   avg = sum / n;
   cout << "The average is  " << avg << endl;
   system("pause");
   return 0;   //successful termination

 }
Share:

0 comments:

Post a Comment