## C++ Program on Repetitions, Arrays, Functions

• 11th Nov, 2022
• 16:24 PM

#include <iostream>
using namespace std;
int main()
{
int x[9];
int k=0;
char ch;
do
{
if(k<=9)
{
cout<<"Enter the values :- ";
cin>>x[k];
k++;
cout<<"Enter y or Y if you want to continue  :-";
cin>>ch;
}
else
{
cout<<"Max entry reached\n";
break;
}
}while((ch=='y')||(ch=='Y'));
int ent;
cout<<"Enter 1 to calculate avg. of numbers entered \n 2 to calculate sun of numbers entered \n 3 to calculate both sum and avg of entered numbers";
cin>>ent;
switch(ent)
{
case 1 :
{

float avg,sum=0.0;
for(int i =0;i<k;i++)
{
sum=sum+x[i];
}
avg=sum/k;
cout<<"\n The avg of given no. is "<<avg;
break;
}
case 2 :
{
int sum=0;
for(int i =0;i<k;i++)
{
sum=sum+x[i];
}
cout<<"\n The sum of given no. is "<<sum;
break;
}
case 3 :
{
float avg,sum=0.0;
for(int i =0;i<k;i++)
{
sum=sum+x[i];
}
avg=sum/k;
cout<<"\n The avg of given no. is "<<avg;
cout <<"  and sum is "<<sum;
break;
}
default :
{ cout<<"\nWrong entry";
break;
}
}
return 0;
}