Can anyone write this program in C++ using a do while loop for me?
Write a program that asks the user for a series of integers one at a time. When the user enters the integer 0, the program displays the following information.
1) the number of integers in the series (not including zero)
2) the average of the integers
3) the largest integer in the series
4) the smallest integer in the series
5) the range (difference between largest and smallest integer)
Writting this C++ Program?
int a[100];
int x,n,av;
do{
cin%26gt;%26gt;x;
if (x!=0){
n++;
a[n]=x;
}
}while(x!=0);
int min,max;
cout%26lt;%26lt;n%26lt;%26lt;endl; //The number of integer
max=0;
av=0;
for(int i=0;i%26lt;n;i++){
av=av+a[i+1];
if(a[i+1]%26gt;max){
max=a[i+1];
}
if(a[i+1]%26lt;min){
min=a[i+1];
}
}
cout%26lt;%26lt;av/n%26lt;%26lt;endl; //The average of the integer
cout%26lt;%26lt;max%26lt;%26lt;endl; //The maximum value
cout%26lt;%26lt;min%26lt;%26lt;endl; //The minimum value
cout%26lt;%26lt;max-min%26lt;%26lt;endl; //The range
Reply:int a[100];
int x,n,av;
do{
cin%26gt;%26gt;x;
if (x!=0){
n++;
a[n]=x;
}
}while(x!=0);
int min,max;
cout%26lt;%26lt;n%26lt;%26lt;endl; //The number of integer
max=0;
av=0;
for(int i=0;i%26lt;n;i++){
av=av+a[i+1];
if(a[i+1]%26gt;max){
max=a[i+1];
}
if(a[i+1]%26lt;min){
min=a[i+1];
}
}
cout%26lt;%26lt;av/n%26lt;%26lt;endl; //The average of the integer
cout%26lt;%26lt;max%26lt;%26lt;endl; //The maximum value
cout%26lt;%26lt;min%26lt;%26lt;endl; //The minimum value
cout%26lt;%26lt;max-min%26lt;%26lt;endl; //The range
Reply:Heh. I've got this written in Fortran95. Yes, I had it for homework, too.
It's not difficult.
Reply:You will not learn unless you do the assignment yourself.
Reply:how much would you pay me to do your homework during the weekend?
Reply:Go to your room and do your homework.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment