InstructionsAsk the user to input an integer. Print out the next three consecutive numbers.Sample RunEnter an integer: 4567

7 answers
Question:

Instructions Ask the user to input an integer. Print out the next three consecutive numbers.
Sample Run
Enter an integer: 4
5
6
7

Answers

a = float(input("Enter an integer: "))

print(a + 1)

print (a + 2)

print (a + 3)

Explanation:

Takes any number user inputs, and next three numbers that come out are what the given number is plus one, then two, then three.

For example :

Enter an integer: 4

5

6

7

Codes are given below:

Explanation:

Since the language is not specified, I am writing it in c++

#include <iostream>

 using namespace std;

 int main()    //Start of main function

{

 int number;  

  cout << "Enter your number"<<endl;

  cin >> number;     //this will take your number as an input

  cout <<"The next three numbers are: " << number + 1 << endl; //this will write the next number to your input input

  cout << number + 2 << endl;

  cout << number + 3 << endl;  

   return 0;

}   //End of main function

Codes are given below:

Explanation:

Since the language is not specified, I am writing it in c++

1) Ask the user to input an integer. Print out the next three consecutive numbers.

#include <iostream>

 using namespace std;

 int main()    //Start of main function

{

  int number;  

   cout << "Enter your number<<endl;

  cin >> number;     //this will take your number as an input

 

  cout <<"The next three numbers are: " << number + 1 << endl;

  cout << number + 2 << endl;

   cout << number + 3 << endl;  

  return 0;

}   //End of main function

2) Write a program that accepts three decimal numbers as input and outputs their sum.

#include <iostream>

 using namespace std;

 int main()    //Start of main function

{

  int number1, number2, number3;  

   cout << "Enter your three numbers<<endl;

  cin >> number1 >> number2>> number3 ;     //this will take your three number as an input

 

  cout <<"The sum of three numbers are: " << number1 + number2+ number3 <<  endl;  

  return 0;

}   //End of main function

Explanation:

n = int(input("Enter Number : "))

print(n+1,n+2,n+3)

I've included my code in the picture below. Best of luck.


[tex]Ask the user to input an integer. Print out the next three consecutive numbers. Sample Run Enter an[/tex]

num = int(input("Enter an integer: "))

i = 1

while i <= 3:

   print(num+i)

   i += 1

I've written my code in python 3+. I hope this helps!

The code is written using Python language as it is one of the programming languages introduced by the Edhesive courses.

Answer (Question 1):

num = int(input("Input an integer: "))for i in range(1, 4):    print(num + i)

Explanation (Question 1):

Line 1 :

Prompt user for input an integer.  In Python we can easily use input method to ask user for an input.

However the default data type of the input is a string and therefore we need to enclose our input value within int() to convert the value from string to integer.

Line 3 - 4:

Create a for-loop to loop though the code in Line 4 for three times using the range() function. The range(1, 4) will return a list of numbers, [1, 2, 3] .

In each round of the loops, one number from the list will be taken sequentially and total up with the input number, num and display using print() function.

Answer (Question 2):

counter = 3sum = 0while (counter > 0):    num = float(input("Enter a decimal number: "))    sum += num    counter = counter - 1print("The sum is " + str(sum))

Explanation (Question 2):

Line 1 - 2 :

Create a counter variable and a sum variable and initialize them with 3 and 0, respectively.

Line 4:

Create a while loop and set a condition while counter is bigger than zero, the loop should keep running the code from Line 5-7.

Line 5:

Use input function again to prompt user for a decimal number. This time we need to use float function to convert the input value from string to decimal data type.

Line 6:

Every time when a decimal number is input, the number is added to the sum variable.

Line 7:

Decrement the counter variable by 1. This step is important to ensure the while loop will only be repeated for three times and each loop will only accept one input value from user.

Line 9

Display the sum.

Similar Solved Works

4 answers

Why did the feudalism system emerged during the middle ages?

Why did the feudalism system emerged during the middle ages?...
2 answers

Write the proper word equation to express the following chemical reaction: 4fe (s) + 3sn(no3)4 (aq)

Write the proper word equation to express the following chemical reaction: 4fe (s) + 3sn(no3)4 (aq) arrow 4fe(no3)3 (aq) + 3sn (s)....
10 answers

A can of hormel chili with beans is 11 cm tall and 7 cm across A. How much chili does the can hold? B. What is the area of the

A can of hormel chili with beans is 11 cm tall and 7 cm across A. How much chili does the can hold? B. What is the area of the can’s label? C. How much metal was used to construct the can? Please help me solve this with the explanation please because I don’t understand...
3 answers

In an attempt to preserve their culture and seek religious refuge, separatists from holland established

In an attempt to preserve their culture and seek religious refuge, separatists from holland established what colony?...
10 answers

Organisms inherit specific traits and characteristics from their parents. Albinism is an inherited disorder

Organisms inherit specific traits and characteristics from their parents. Albinism is an inherited disorder that occurs when an organism is unable to produce or distribute melanin. Melanin is a substance in the body that helps determine skin color, hair color, and eye color. Which of the following i...
10 answers

53: 31 which percentage of american adults do not exercise on a regular basis? a. 40% b. 50% c. 55% d. 60%

53: 31 which percentage of american adults do not exercise on a regular basis? a. 40% b. 50% c. 55% d. 60%...
3 answers

What texts or books must boys study for the exams?

What texts or books must boys study for the exams?...
3 answers

What type of salt will affect temperature most?

What type of salt will affect temperature most?...
3 answers

El precio de dos camisetas y de dos latas de refresco es de 44 euros. Elprecio de una camiseta y tres latas es de 30 euros. Si se quiere

El precio de dos camisetas y de dos latas de refresco es de 44 euros. El precio de una camiseta y tres latas es de 30 euros. Si se quiere conocer cuántos euros cuesta una camiseta (x) y una lata de refresco (y), ¿qué opción muestra el sistema de ecuaciones que posibilita dar respuesta a la preg...
10 answers

Write a free verse poem about the sea

Write a free verse poem about the sea...
9 answers

Identify the percent of changes as an increase or decrease. $24 to $18

Identify the percent of changes as an increase or decrease. $24 to $18...
4 answers

Vì sao học thuyết chủ nghĩa Mác – Lênin khẳng định : “Giai cấp công nhân là giai cấp đại diện cho lực

Vì sao học thuyết chủ nghĩa Mác – Lênin khẳng định : “Giai cấp công nhân là giai cấp đại diện cho lực lượng sản xuất tiên tiến”....
4 answers

Which of the following kinds of muscle is voluntary? a. smooth b. cardiac c. skeletal d. visceral

Which of the following kinds of muscle is voluntary? a. smooth b. cardiac c. skeletal d. visceral...
3 answers

How does jack convince lady bracknell to agree to allow him marry her daughter, gwendolen? by professing

How does jack convince lady bracknell to agree to allow him marry her daughter, gwendolen? by professing his love for gwendolen and promising to buy a house for her by making her consent a condition for his consent to cecily’s marriage by threatening to file a legal case against her and take her ...
7 answers

What is the mass of 2.5 mol of ca, which has a molar mass of g/mol

What is the mass of 2.5 mol of ca, which has a molar mass of g/mol...
3 answers

Every fourth visitor to a museum gets a free bumper sticker. every tenth visitor to that museum gets

Every fourth visitor to a museum gets a free bumper sticker. every tenth visitor to that museum gets a free key chain. which ordered visitor will be the first one to get both the bumper sticker and the chain?...
3 answers

2 A sailboat on a lake sails 40. meters north and then sails 40. meters due east. Compared to its starting

2 A sailboat on a lake sails 40. meters north and then sails 40. meters due east. Compared to its starting position, the new position of the sailboat is (1) 40. m due east (3) 57 m northeast (2) 40. m due north (4) 80. m northeast...
4 answers

:-) :-) :-) :-) :-) :-) :-) :-) :-)The question is in the picture below Please help

:-) :-) :-) :-) :-) :-) :-) :-) :-) The question is in the picture below Please help [tex]:-) :-) :-) :-) :-) :-) :-) :-) :-) The question is in the picture below Please help[/tex]...
6 answers

When did the alec meet the stallion ?​

When did the alec meet the stallion ?​...
8 answers

Select all that apply.The two major cities of the Indus Valley civilization were .Mohenjo-DaroHyksosNew

Select all that apply. The two major cities of the Indus Valley civilization were . Mohenjo-Daro Hyksos New Delhi Harappa...

-- 0.019256--