Diese Präsentation wurde erfolgreich gemeldet.

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
×

1 von 2 Anzeige

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

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
#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;
}
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
#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;
}
averagedValue=total/n; //calculates average
cout<<\"\ \ The average of the \"<<n<<\" number you entered is: \"<<averagedValue;
return 0;
}
.

Anzeige
Anzeige

## Weitere Verwandte Inhalte

Anzeige

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