1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
miv72 [106K]
3 years ago
5

g Write a program that prompts the user for an integer n between 1 and 100. If the number is outside the range, it prints an err

or. The program computes and prints at the end two things: The sum of the numbers from 1 to n. The average of the numbers from 1 to n. Average should only have 2 digits after the decimal.
Computers and Technology
1 answer:
grin007 [14]3 years ago
3 0

Answer:

The cpp program is given below.

#include<iostream>

#include<iomanip>

using namespace std;

int main() {

   

   // variables declared

   int n;

   int sum=0;

   float avg;

   

   do

   {

       // user input taken for number    

       cout<< "Enter a number between 1 and 100 (inclusive): ";

       cin>>n;

       

       if(n<1 || n>100)

           cout<<" Number is out of range. Enter valid number."<<endl;

       

   }while(n<1 || n>100);

   

   cout<<" "<<endl;

   

   // printing even numbers between num and 50  

   for(int num=1; num<=n; num++)

   {

       sum = sum + num;

   }

   

   avg = sum/n;

   

   // displaying sum and average

   cout<<"Sum of numbers between 1 and "<<n<<" is "<<sum<<endl;

   cout<<"Average of numbers between 1 and "<<n<<" is ";

   printf("%.2f", avg);

   

       return 0;

}

OUTPUT

Enter a number between 1 and 100 (inclusive): 123

Number is out of range. Enter valid number.

Enter a number between 1 and 100 (inclusive): 56

 

Sum of numbers between 1 and 56 is 1596

Average of numbers between 1 and 56 is 28.00

Explanation:

The program is explained below.

1. Two integer variables are declared to hold the number, n, and to hold the sum of numbers from 1 to n, sum. The variable sum is initialized to 0.

2. One float variable, avg, is declared to hold average of numbers from 1 to n.

3. User input is taken for n inside do-while loop. The loop executes till user enters value between 1 and 100. Otherwise, error message is printed.

4. The for loop executes over variable num, which runs from 1 to user-entered value of n.

5. Inside for loop, all the values of num are added to sum.

sum = sum + num;

6. Outside for loop, average is computed and stored in avg.

avg = sum/n;

7. The average is printed with two numbers after decimal using the following code.

printf("%.2f", avg);

8. The program ends with return statement.

9. All the code is written inside main() and no classes are involved.

You might be interested in
You need a VPN to connect to a private, remote network in order to access some files. You click the network icon in your taskbar
sineoko [7]

Answer:

Buy a vpn

Explanation:

NordVPN is a good one I use.

7 0
3 years ago
What's your thoughts on people using Brainly to cheat academically?
lys-0071 [83]

Answer:

At this point, school isnt even about learning anymore. Its just about passing so you dont end up being a dropout or just a bum in general cause not everyone has the skills to make something out of nothing.

Explanation:

7 0
3 years ago
Read 2 more answers
HELP PLEase!!! Which option is an outcome of a project stated in quantifiable terms?
dimulka [17.4K]

Answer: C) a 10 percent increase in efficiency of sales of a particular product line over one year

The term "quantifiable" means that we can attach a number to it. Specifically, a number in which we can do math operations upon it. Something like telephone numbers or serial numbers don't really count as quantifiable entities. They are qualitative variables instead. So you have to be careful what numbers you run into. In this case, "10 percent increase in efficiency" is quantitative and fits what we're after.

A 10% increase corresponds to the multiplier 1.10; for instance, if you had sales of 40 million dollars one year, then a 10% increase is 1.10*40 = 44 million in sales. This is one example where we apply a math operation (specifically multiplication) on the value in question.

4 0
3 years ago
(please help) What do you do if Brainly keeps saying your blocked?
kolezko [41]
You could probably make a new account if it’s just the account blocked
6 0
2 years ago
A Solutions Architect needs to build a resilient data warehouse using Amazon Redshift. The Architect needs to rebuild the Redshi
gulaghasi [49]

Answer:

Explanation:

An Amazon Redshift data warehouse refers to a collection of computing resources that are known as nodes. These nodes are organized into a group called a cluster. In order to correctly replicate/rebuild this cluster in another region, the Architect needs to modify the Redshift cluster to take snapshots of the Amazon EBS volumes each day, sharing those snapshots with the other region. These snapshots will provide accurate and up-to-date information allowing for a correct rebuild of the Redshift cluster.

5 0
4 years ago
Other questions:
  • According to many experts how often should files be backed up
    12·1 answer
  • Most network cards contain a port that accepts a(n) ____, which looks similar to a telephone connector but is larger.
    14·1 answer
  • "This part of the computer fetches instructions, carries out the operations commanded by the instructions, and produces some out
    15·1 answer
  • In c++ 11, the ________ tells the compiler to determine the variable's data type from the initialization value.
    6·1 answer
  • Review the HTML tags that we have gone over in this lesson. Research HTML tags on the web and identify two new tags. Use these t
    9·1 answer
  • The internet's data gathways rely on what kind of hardware devies to route data to its destination?
    14·1 answer
  • PLZ HELP What will be the output? class num: def init (self.a): self. number = a mul* __(self. b) return self. number + b. numbe
    7·1 answer
  • Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a fil
    11·1 answer
  • 1. The correct definition of ergonomics is: (a) The correct way to position your feet when in front of electronic equipment. (b)
    6·1 answer
  • Intro Programming - Problem(s)
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!