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
Modify the statistics program from this chapter so that client programshave more flexibility in computing the mean and/ or stand
vampirchik [111]

Answer and Explanation:

Using Javascript:

function mean(nums){

var array_numbers= new array(nums);

var meanofNums= array_numbers.reduce()/array_numbers.length;

Console.log(meanofNums);

}

Function Std(nums){

var OurArray= new Array(nums);

var meanOfnums= mean(nums);

var i;

for(i=0; i<=OurArray.length; i++){

OurArray[i]= OurArray[i]-meanOfnums*OurArray[i]-meanOfnums;

}

var al_stdOfnums= OurArray.reduce()/OurArray.length;

var stdOfnums= Math. sqrt(al_stdOfnums);

Console.log(stdOfnums);

}

function meanStdDev (nums){

mean(nums);

Std(nums);

}

/*From the code above, we have defined functions and used them in the last function definition meanStdDev (nums), making for code reusability. In defining the functions, we have followed the formulas for calculating mean and standard deviations and implemented in that order. Notice how we used a for loop in std(nums) function definition to iterate through the elements of the array nums, squaring each value and reassigning a new value for each element(using index value) in the array. We then added these values in array using reduce method, dividing by array length and square rooting the value using the math object method sqrt().*/

8 0
3 years ago
On the Audio Tools contextual tab, which tab will control how the audio file appears, if it appears, on the slide itself?
otez555 [7]

Answer:

<h2>B. Playback</h2>

Explanation:

Playback is the act of reproducing recorded sound; “he was allowed to hear the playback of his testimony”. The part of a tape recorder that reproduces the recorded material.

On the audio tools contextual tab, “playback” will control how the audio file appears, if it appears, on the slide itself.

Therefore, the correct answer is b. playback.

5 0
3 years ago
Read 2 more answers
What do character formats do for your document's message? A. Set how text aligns within a document B. Provide organization C. Pr
Phoenix [80]
<span>What do character formats do for your document's message? A. Set how text aligns within a document</span>
6 0
3 years ago
Read 2 more answers
Write a Java program that calculates and prints the monthly pay check for an employee. The net pay is calculated after taking th
ycow [4]

Answer:

  import java.util.Scanner;

public class salary{

    public static void main(String []args){

       

       System.out.println("Enter the monthly pay: ");

       Scanner scn = new Scanner(System.in);

       double salary = scn.nextDouble();

       double result = salary-(salary*0.15*0.035*0.0575*0.0275*0.05)-75;

       

        System.out.println("The net salary is: "+result);

    }

}

Explanation:

first import the Scanner class for taking the input from user.

then, create the main function and print the message for enter the salary from user.   scn.nextDouble() store the value enter by user into the result.

after that, calculate the net salary by calculating the deduction amount and then subtract with salary.

finally, print the result on the screen.

8 0
4 years ago
Select the correct answer.
sashaice [31]

Answer:

A. Project Manager

Explanation:

3 0
4 years ago
Read 2 more answers
Other questions:
  • Jax needs to write a block of code that will organize a list of items alphabetically. Which function should he use? append() pri
    12·1 answer
  • What appears in the document after you have inserted a video?
    14·2 answers
  • Write 2-3 lines about the Basic operations of computer
    5·1 answer
  • How can a System Administrator quickly determine which user profiles, page layouts, and record types include certain fields? Uni
    14·1 answer
  • The private field, which is known as the property‘s __________, holds any data that is assigned to the property.a. private datab.
    9·1 answer
  • Explain why this scenario could put an organization in jeopardy of losing some of its workforce.
    12·1 answer
  • A Development team begins work on a new software application and decides to involve the client’s IT experts to ensure that secur
    12·1 answer
  • How does the technology affect you daily living? Give situations where you use technology and how it helped you.​
    5·1 answer
  • Which of the following is one of the tools used by a Python IDE that helps prevent syntax errors?
    9·1 answer
  • Carl wants to add two new characters to the extraterrestrial battleship game he's
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!