O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×

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

Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio

Confira estes a seguir

1 de 2 Anúncio

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

Baixar para ler offline

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;
}
.

Anúncio
Anúncio

Mais Conteúdo rRelacionado

Mais de lez31palka (20)

Mais recentes (20)

Anúncio

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; }

×