This is the basic level programming exercise for beginners. The program calculates the Average Smallest and the Largest Number in a Given Array.
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; }
0 comments:
Post a Comment