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
what new technology led to the chaos that spurred the establishment of the federal communications commission?
adelina 88 [10]

Answer:

The digital read Harry quaant

3 0
1 year ago
Write a script that calculates the common factors between 8 and 24. To find a common factor, you can use the modulo operator (%)
AnnyKZ [126]

Answer:

  1. common = []
  2. num1 = 8
  3. num2 = 24
  4. for i in range(1, num1 + 1):
  5.    if(num1 % i == 0 and num2 % i == 0):
  6.        common.append(i)
  7. print(common)

Explanation:

The solution is written in Python 3.

Firstly create a common list to hold a list of the common factor between 8 and 24 (Line 1).

Create two variables num1, and num2 and set 8 and 24 as their values, respectively (Line 3 - 4).

Create a for loop to traverse through the number from 1 to 8 and use modulus operator to check if num1 and num2 are divisible by current i value. If so the remainder of both num1%i and num2%i  will be zero and the if block will run to append the current i value to common list (Line 6-8).

After the loop, print the common list and we shall get [1, 2, 4, 8]

8 0
3 years ago
Which of the following is NOT an example of written communication?
Veronika [31]

Answer:A conversation between co-workers

Explanation:

4 0
3 years ago
ven int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 5
monitta

Answer:

Following are statement is given below

int  k=1,total=0; // variable declaration

while(k<50) // iterating the while loop

{

   total=total+k*k;//  calculating the square

   k=k+1; // increments the value of k by 1    

}

Explanation:

Following are the description of Statement.

  • Declared a variable "total" and "k" of the "integer " type initialized the total to 0 and "k" to 1.
  • Iterating the while loop for less then 50 .In this loop, we calculating the sum of square of first 50 number in the "total" variable .
  • After that increment the value of "k" variable by 1 to execute the loop less then 50 .

3 0
3 years ago
Additional rows and columns are inserted into a table using the
Paladinen [302]
The Option D , Table Tools Insert
6 0
2 years ago
Other questions:
  • How many rows and columns does ms-excel 2007 have???
    10·1 answer
  • A. true
    6·1 answer
  • Peter has a website that promotes his local vacation rental site. He uses Google Ads to manage his advertising campaign. He’s cr
    13·1 answer
  • 2.1 Changes in which factors could cause aggregate demand to shift from AD to AD1? What could happen to the unemployment rate? W
    8·1 answer
  • In order to organize your work effectively on the computer, where is the best place to save it?
    14·2 answers
  • write a c++ program that writes weather data from a file wx_data.txt to a file wx_summary for everyday of the year. also add min
    15·1 answer
  • Given a PrintWriter reference variable named output that references a PrintWriter object, write a statement that writes the stri
    5·1 answer
  • 1.) Florida has ____________ roads that are designated as part of the National Highway System.
    12·1 answer
  • What is the best stratiget to avoid paying intrest in your credit cared
    13·1 answer
  • What is the easiest way to deploy a C++ program to a user’s computer? a. Copy the source code to the user’s computer and then co
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!