Se ha denunciado esta presentación.
Se está descargando tu SlideShare. ×

Write a code that ask the user for the number n of decimal to average- (1).docx

Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio
Anuncio

Eche un vistazo a continuación

1 de 2 Anuncio

Write a code that ask the user for the number n of decimal to average- (1).docx

Descargar para leer sin conexión

Write a code that ask the user for the number n of decimal to average.
Then n times the code the user to enter all numbers that you save or accumulate each time.
Finaly print to the console the average of the n values the user entered using the format:
cout << \" The average of the \" << n << \" number you entered is: \" << averagedValue <<endl;
Solution
Answer
#include <iostream>
using namespace std;
int main()
{
int n,averagedValue,num,total=0;
cout<<\"\ Enter count of numbers : \"; //input count of numbers
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<\"\ Enter number \"<<i<<\" : \"; //input number
cin>>num;
total=total+num; //adds to total
}
averagedValue=total/n; //calculates average
cout<<\"\ \ The average of the \"<<n<<\" number you entered is: \"<<averagedValue;
return 0;
}
.

Write a code that ask the user for the number n of decimal to average.
Then n times the code the user to enter all numbers that you save or accumulate each time.
Finaly print to the console the average of the n values the user entered using the format:
cout << \" The average of the \" << n << \" number you entered is: \" << averagedValue <<endl;
Solution
Answer
#include <iostream>
using namespace std;
int main()
{
int n,averagedValue,num,total=0;
cout<<\"\ Enter count of numbers : \"; //input count of numbers
cin>>n;
for(int i=1;i<=n;i++)
{
cout<<\"\ Enter number \"<<i<<\" : \"; //input number
cin>>num;
total=total+num; //adds to total
}
averagedValue=total/n; //calculates average
cout<<\"\ \ The average of the \"<<n<<\" number you entered is: \"<<averagedValue;
return 0;
}
.

Anuncio
Anuncio

Más Contenido Relacionado

Más de lez31palka (20)

Más reciente (20)

Anuncio

Write a code that ask the user for the number n of decimal to average- (1).docx

  1. 1. Write a code that ask the user for the number n of decimal to average. Then n times the code the user to enter all numbers that you save or accumulate each time. Finaly print to the console the average of the n values the user entered using the format: cout << " The average of the " << n << " number you entered is: " << averagedValue <<endl; Solution Answer #include <iostream> using namespace std; int main() { int n,averagedValue,num,total=0; cout<<" Enter count of numbers : "; //input count of numbers cin>>n; for(int i=1;i<=n;i++) { cout<<" Enter number "<<i<<" : "; //input number cin>>num; total=total+num; //adds to total } averagedValue=total/n; //calculates average cout<<" The average of the "<<n<<" number you entered is: "<<averagedValue; return 0; }

×