The trouble is you think you have time. Your success depends on how you utilize your time.

C++ program to find the sum and average of one dimensional (1D) array

Write a C++ program to find the sum and average of one dimensional  (1D) array.


#include<iostream>
using namespace std;
int main()
{cout<<"[www.moznum.blogspot.com]"<<endl<<endl;


int x,sum=0;
 cout<<"Please Enter The Number of Values : ";

 cin>>x;
 int array[x];

 for(int index=0;index<x;index++)
    { cout<< "Please Enter The "<< index+1 <<"st Value : ";
      cin>>array[index];
     }
 for(int index=0;index<x;index++)  // "index is controlling loop as well as working as the index of array.
  {
    sum=sum+array[index];
  }
  double total, average;
  total=x;       //  "x" stored into "total" to make the value of "x" of a double type Because Average Can have decimal point. 
  average=sum/total;
  cout<<endl<< "The Sum Of Your Number Is: " <<sum<<endl;
  cout<< "The Average Of Your Number Is: "<< average<<endl;
}


You Can Also Search this topic by this:
C plus plus program to find sum and average of one dimensional  (1D) array.

How to find sum and average of one dimensional  (1D) array in C++.

2 comments:

  1. thanks i'm new in this field , this is very helpful

    ReplyDelete
  2. 1.Write a two Dimensional array Program that reads value from the user and displays the sum of the two arrays in the matrix format

    The output looks like this.
    ***********************************************
    Enter first value of array
    1
    2
    3
    4
    **************matrix format****************
    1 2
    3 4

    Enter the second value of the array
    4
    4
    5
    6

    **********matrix format*************
    4 4
    5 6

    *****the sum of the two matrix is ******
    5 6
    8 10

    Q2. Write a two dimensional array program that reads value from the user and displays the product of the two arrays in the matrix format. The output must look like as question number 1.

    ReplyDelete