C++ Program to Find Sum of Randomly Generated Array
#include<iostream>
#include<time.h>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int main()
{
int n,s=0;
cout<<"|ARRAY PROGRAM |\n";
int arr[100];
cout<<"Enter size of Array(Max-100): ";
cin>>n;
srand((unsigned)time(NULL));
cout<<"Random array of size :"<<n<<" is shown below\n";
cout<<"=========================================\n";
for(int i=0;i<n;i++)
{
arr[i]=rand()%41+10;
s+=arr[i];
}
for(int i=0;i<n;i++)
{
cout<<setw(4)<<arr[i];
}
cout<<"\n=========================================\n";
cout<<"\nThe Sum Of Above Printed numbers is "<<s;
}
Comments
Post a Comment