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
Diano4ka-milaya [45]
3 years ago
8

[This is on Edhesive (coding and programming)]

Computers and Technology
2 answers:
Ghella [55]3 years ago
6 0

Answer:

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

egoroff_w [7]3 years ago
6 0

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

Answer (Question 1):

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

Explanation (Question 1):

<u>Line 1 : </u>

Prompt user for input an integer.  In Python we can easily use <em>input </em>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 <em>int()</em> to convert the value from string to integer.

<u>Line 3 - 4:</u>

Create a for-loop to loop though the code in Line 4 for three times using the <em>range() </em>function. The <em>range(1, 4) </em>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 <em>print()</em> function.

Answer (Question 2):

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

Explanation (Question 2):

<u>Line 1 - 2 :</u>

Create a <em>counter</em> variable and a <em>sum</em> variable and initialize them with 3 and 0, respectively.

<u>Line 4:</u>

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

<u>Line 5:</u>

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

<u>Line 6:</u>

Every time when a decimal number is input, the number is added to the <em>sum</em> variable.

<u>Line 7:</u>

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.

<u>Line 9</u>

Display the sum.

You might be interested in
Write a recursive function called digit_count() that takes a positive integer as a parameter and returns the number of digits in
Gelneren [198K]

Using the computational knowledge in python it is possible to write a code that Write a recursive function called digit_count()

<h3>What is a function in Python?</h3>

In Python, a function is a sequence of commands that performs some task and that has a name. Its main purpose is to help us organize programs into chunks that correspond to how we envision a solution to the problem.

<h3>Writting the code in python:</h3>

<em>def countDigits(n):</em>

<em>   if n< 10:</em>

<em>      return 1</em>

<em>   else:</em>

<em>       return 1 + countDigits(n / 10)</em>

See more about python at brainly.com/question/13437928

#SPJ1

8 0
2 years ago
In Online Data Extraction data is extracteddirectly from the ------ system itself.o Hosto Destinationo Sourceo Terminal
barxatty [35]

Answer:

system itself.

Explanation:

In Online Data Extraction data is extracted directly from the system itself.

4 0
3 years ago
Write a program with 2 separate functions which compute the GCD (Greatest Common Denominator) and the LCM (Lowest Common Multipl
Maru [420]

Answer:

The program written in Python is as follows

def GCD(num1, num2):

    small = num1

    if num1 > num2:

         small = num2

    for i in range(1, small+1):

         if((num1 % i == 0) and (num2 % i == 0)):

              gcd = i

    print("The GCD is "+ str(gcd))

def LCM(num1,num2):

    big = num2  

    if num1 > num2:

         big = num1

    while(True):

         if((big % num1 == 0) and (big % num2 == 0)):

              lcm = big

              break

         big = big+1

     print("The LCM is "+ str(lcm))

 print("Enter two numbers: ")

num1 = int(input(": "))

num2 = int(input(": "))

GCD(num1, num2)

LCM(num1, num2)

Explanation:

This line defines the GCD function

def GCD(num1, num2):

This line initializes variable small to num1

    small = num1

This line checks if num2 is less than num1, if yes: num2 is assigned to variable small

<em>     if num1 > num2: </em>

<em>          small = num2 </em>

The following iteration determines the GCD of num1 and num2

<em>     for i in range(1, small+1): </em>

<em>          if((num1 % i == 0) and (num2 % i == 0)): </em>

<em>               gcd = i </em>

This line prints the GCD

    print("The GCD is "+ str(gcd))

   

This line defines the LCM function

def LCM(num1,num2):

This line initializes variable big to num2

    big = num2  

This line checks if num1 is greater than num2, if yes: num1 is assigned to variable big

<em>     if num1 > num2: </em>

<em>          big = num1 </em>

The following iteration continues while the LCM has not been gotten.

    while(True):

This if statement determines the LCM using modulo operator

<em>          if((big % num1 == 0) and (big % num2 == 0)): </em>

<em>               lcm = big </em>

<em>               break </em>

<em>          big = big+1 </em>

This line prints the LCM of the two numbers

     print("The LCM is "+ str(lcm))

The main starts here

This line prompts user for two numbers

print("Enter two numbers: ")

The next two lines get user inputs

num1 = int(input(": "))

num2 = int(input(": "))

This calls the GCD function

GCD(num1, num2)

This calls the LCM function

LCM(num1, num2)

<em></em>

<em>See attachment for more structured program</em>

Download txt
5 0
2 years ago
What to do when microsoft word is eating your words?
Aloiza [94]
Update it so it wont do that
4 0
3 years ago
I have been trying to use brainly recently but i cant because everytime i watch an ad to get an answer, its an interactive ad, s
Troyanec [42]

Answer:

remove ads

Explanation:

by buying a no ad pack

5 0
2 years ago
Other questions:
  • What is a valence orbit?
    13·2 answers
  • How do you open Microsoft Excel 2013 with Windows 8?
    13·1 answer
  • 1 Point
    14·1 answer
  • Without entering into the internet cloud or intranet cloud, how many icons in the topology represent endpoint devices (only one
    6·1 answer
  • What is the CSS property used to style text as all lowercase or uppercase?
    14·2 answers
  • Write the algorithm for finding the perimeter of a rectangle using English like form step by step
    10·1 answer
  • Class C Airspace inner ring begins at the __________ and extends vertically (by definition) to MSL charted values that generally
    5·1 answer
  • Can somebody tell me the Minecraft command to clear an entire world and destroy every block if u Dunno please don’t answer &gt;-
    13·1 answer
  • Define a query that uses the Natural Join command to join three tables to produce useful information.
    14·1 answer
  • Select the correct answer from each drop-down menu.
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!