Solution:NIIT/GNIIT Sonugiri0032@gmail.com

Wednesday, January 06, 2016

Calculate the average smallest and the largest number in Array | Array Exercise | Array Logic Building Exercise |

Calculate the average smallest and the largest number in Array | Array Exercise | Array Logic Building Exercise |

Source Code

#include<iostream>
using namespace std;
float division(float[],int);
float minMax(float[] ,int );
int main()
{
      int size;              //Array size
      cout << "How many numbers do you want to input? ";
      cin >> size;        
      float dataArray[size];     //Declaring dataArray        
   for(int index=0;index<size;index++)   //Loop which inputs arrays data 
                                
      {
              cout << "Number " << index+1 << " is: ";
              cin>>dataArray[index];
      }
      //Now calling division function to find the sum...
      cout<<"Average of dataArray elements is "<<division(dataArray,size)<< endl;
      minMax(dataArray,size);
      system("pause");
      return 0;
}
float division(float dataArray[],int size)
{
    float sum;
    float average=0;
    for(int index=0;index<size;index++)
        sum +=dataArray[index];
     average=sum/size;
     return average;
}
float minMax(float dataArray[],int size)
{
 int max;
 int min;
 max=dataArray[0];
 min=dataArray[0];
 
 for (int index=0 ; index<size; index++)
 {
  if (dataArray[index] > max) 
  {
   max = dataArray[index];
  }
  if (dataArray[index] < min) 
  {
   min= dataArray[index];
  }
 }
 cout<<"\nBiggest number is : "<<max;
 cout<<"\nSmallest number is: "<<min<<endl;
}

Output of the Program

Array Logic Building Exercise
Share:

0 comments:

GNIITSOLUTION GNIIT SOLUTION. Powered by Blogger.

Translate

Blog Archive

Unordered List