Write a main program to test the following functions:
void introduction() ; // to display a text to tell what is the program about
bool keepRunning(); // to ask the user for more times to run the program
void ruuProgram(); // to input an array, calculate series (k=0 to n) a^2*[k]
#include <iostream>
using namespace std;
void introduction(){
cout<<"\n********************************\n";
cout<<"Calculates series (k = 0 to n) a^2*a[k]\n";
}
bool keepRunning(){
int x;
cout<<"\nRun the program again?\n0. No\n1. Yes\n";
cin>>x;
return x;
}
void ruuProgram(){
cout<<"Input size of array: ";
int n; cin>>n;
cout<<"Input elements of the array\n";
int *a = new int[n], sum = 0;
for(int k = 0; k < n; k++){
cin>>a[k];
sum += a[0] * a[0] * a[k];
}
cout<<"\nResult of the series: "<<sum<<endl;
delete a;
}
int main(){
do{
introduction();
ruuProgram();
}while(keepRunning());
return 0;
}
Comments
Leave a comment