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
DIA [1.3K]
3 years ago
11

g 1. Write a program that asks the user for a number greater than 5 and prints all values between 1 and n that are multiples of

5 (i.e. evenly divisible by 5). 2. Write a program that prompts the user for an integer n between 1 and 100. If the number is outside the range, it should keep asking the user for a valid number. The program computes and prints at the end two things: a.The sum of the numbers from 1 to n. b.The average of the numbers from 1 to n.
Computers and Technology
1 answer:
a_sh-v [17]3 years ago
5 0

PROGRAM 1

#include <iostream>  

using namespace std;

int main() {

   int n;

   // user input taken for n

   cout<<"Enter any number greater than five: ";

   cin>>n;

   

   cout<<"The multiples of 5 between 1 to "<<n<<" are shown below."<<endl;

   

   // displaying multiples of 5 between 1 to n

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

   {

       // if number is completely divisible by 5, remainder will be 0

       if( (h%5)==0)

           cout<<h<<endl;

   }

 

   return 0;

}

OUTPUT

Enter any number greater than five: 22

The multiples of 5 between 1 to 22 are shown below.

5

10

15

20

The program does not implements any input validation since this is not mentioned in the question.

User input is taken. All the multiples of 5 computed inside a for loop, and displayed to the console.

PROGRAM 2

#include <iostream>

using namespace std;

int main() {

   // variables to hold respective values

   int n;

   int sum=0;

   double avg=0;

   

   do

   {

       // user input taken for n

       cout<<"Enter any number between 1 and 100: ";

       cin>>n;

       if(n<1 || n>100)

           cout<<"Invalid number. Enter valid number."<<endl;

       cout<<""<<endl;

       

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

   

   // computing sum and average of numbers from 1 to n

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

   {

       sum = sum+h;

   }

   

   avg=avg+(sum/n);

   

   cout<<"Sum of all the numbers from 1 to "<<n<<" is "<<sum<<endl;

   

   cout<<""<<endl;

   cout<<"Average of all the numbers from 1 to "<<n<<" is "<<avg<<endl;

   

   return 0;

}

OUTPUT

Enter any number between 1 and 100: 111

Invalid number. Enter valid number.

Enter any number between 1 and 100: 0

Invalid number. Enter valid number.

Enter any number between 1 and 100: 23

Sum of all the numbers from 1 to 23 is 276

Average of all the numbers from 1 to 23 is 12

The program not implements any input validation since this is mentioned in the question.

User input is taken inside do-while loop till valid input is obtained.

The sum of all numbers from 1 to n computed inside a for loop, average computed outside for loop.

Both values are displayed to the console.

You might be interested in
I am a bacterium. I cause stomach cramps and diarrhea. I am caused by eating rotten foods
ZanzabumX [31]

I think it's salmonella. : )

4 0
3 years ago
Read 2 more answers
True/False: Each individual element of an array can be accessed by the array name and an element number, called a subscript. Tru
Dahasolnce [82]

Answer:

True

Explanation:

3 0
2 years ago
When completing an application what color ink do you use
tankabanditka [31]

Black or blue pen would be appropriate.

5 0
3 years ago
Read 2 more answers
Which of the following best describes the purpose of an IP address?
garri49 [273]

IP addresses provide a unique number for identifying devices that send and receive information on the Internet

-scav

8 0
3 years ago
Read 2 more answers
Game Informer (often abbreviated to GI) is an American-based monthly magazine featuring articles, news, strategy, and reviews of
Eddi Din [679]

Answer:

it is d i just took it

Explanation:

6 0
3 years ago
Read 2 more answers
Other questions:
  • An IT technician has manually configured an IP address on a laptop for a new employee. Each time the employee tries to connect t
    8·1 answer
  • Students can use eNotes to type notes directly on screen and
    11·2 answers
  • In an airline reservation system, on entering the flight number, the flight schedule and the flight status are displayed. In thi
    13·2 answers
  • Write any two use of computer in school​
    15·1 answer
  • With an example in each, describe the use of two basic functions which are known by the "string.h" header file.
    6·1 answer
  • ______The statement #include &lt; math.h &gt; defines the name of the current program you are writing as "math". (T/F)
    10·2 answers
  • Briefly explain what are JavaScript librairies​
    12·1 answer
  • Choose the correct term to complete the sentence.
    12·1 answer
  • Write a program to generate the 1,8,27,64,125,226,343,512,729,1000 series.​
    12·1 answer
  • I just wanna know how many times a day y'all hit the tutor button at the bottom
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!