C++ Program to find Average of Randomly Generated Array

 #include<iostream>

#include<time.h>

#include<iomanip>

#include<stdlib.h>

using namespace std;

void line()

{

cout<<"=======================================\n";

}

int main()

{

line();

cout<<"|ARRAY PROGRAM #4|\n";

line();

int n,s=0;

float aver=0;

int arr[100];

cout<<"Enter size of Array(Max-100): ";

cin>>n;

line();

srand((unsigned)time(NULL));

cout<<"Random genrated array of size :"<<n<<"  is shown below\n";

line();

for(int i=0;i<n;i++)

{

arr[i]=rand()%41+10; //between 10 and 50

cout<<setw(4)<<arr[i];

s+=arr[i];

aver=(float)s/n;

}

cout<<endl;

line();

cout<<"\nThe Average of Inputs is "<<aver<<endl;

line();

}

Comments

Popular posts from this blog