Design a C++ program where the user inputs the size of an array at the time of execution with random numbers in the array. Then take every other odd number of the array and get the mean. Use delete and new functions.
the program:
#include <iostream>
using namespace std;
int main()
{
int size;
int * array;
int i;
int count=0;
float mean=0;
cout<<"enter the size of array";
cin >>size;// getting the size
array=new int[size];// making dynamic aaray
for(i=0;i<size;i++)// array initialisation by user
{
cout<<"enter an element";
cin>> array[i];
}
for(i=0;i<size;i++)// array display
{
cout<<array[i]<<"\n";
}
for(i=1;i<size;i=i+2)// loop for odd count
{
mean=mean+array[i];// sum of all odd number
// cout<<mean<<"\n";
count=count+1;
}
mean=mean/count;// calculating mean
cout<<"mean of odd locations"<<mean;// printing
mean
delete(array);// deleating array
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.