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
dmitriy555 [2]
3 years ago
6

a) Write a program that prompts for an integer—let’s call it X—and then finds the sum of X consecutive integers starting at 1. T

hat is, if X=5, you will find the sum of 1+2+3+4+5=15.b) Modify your program by enclosing your loop in another loop so that you can find consecutive sums. For example , if 5 is entered, you will find five sum of consecutive numbers:1 = 11+2 = 31+2+3 =61+2+3+4 =101+2+3+4+5 =15Print only each sum, not the arithmetic expression.
Computers and Technology
1 answer:
Alex73 [517]3 years ago
7 0

Answer:

<u>Solution a</u>

  1. n = int(input("Enter an integer: "))
  2. sum = 0
  3. for x in range(1, n+1):
  4.    sum += x  
  5. print(sum)

<u>Solution b</u>

  1. n = int(input("Enter an integer: "))
  2. for a in range(1, n + 1):
  3.    sum = 0
  4.    for x in range(1, a+1):
  5.        sum += x
  6.    print(sum)

Explanation:

Solution code is written in Python 3.

<u>Solution a</u>

First get the user input for an integer (Line 1).

Create a variable sum and initialize it with zero value (Line 3).

Create a for loop to traverse through the number from 1 to integer n (inclusive) and sum up the current number x (Line 5-6).

Print the sum to terminal (Line 8).

<u>Solution b</u>

Create an outer for loop that traverse through the number from 1 to integer n (inclusive) (Line 3).

Create an inner loop that traverse through the number from 1 to current a value from the outer loop and sum up the current x value (Line 5-6).

Print the sum to terminal (Line 7) and proceed to next iteration and reset the sum to zero (Line 4).

You might be interested in
What do want in future (computer enginner )<br>​
Debora [2.8K]
I wish to be a professor or maybe a singer/rapper and if they fail, then I wanna be a model

✨hope this helps✨

✨SammySilkWorm waz here✨

Here is my modeling shot

6 0
3 years ago
Read 2 more answers
The _____ feature will allow users to view nonprinting formatting marks to aid in editing a document. View Alignment Show/Hide I
Annette [7]

The __Show/Hide Insert___ feature will allow users to view non printing formatting marks to aid in editing a document.

The answer is D. Show/Hide Insert

Let me know if this is correct

5 0
3 years ago
If a person sends email from a school computer or a business computer, should that message be considered private?
mars1129 [50]

Answer:

yes

Explanation:

6 0
3 years ago
Read 2 more answers
Can i put a verizon sim card in a tmobile phone
scZoUnD [109]
Yes you can physically, but that doesnt mean that it will work. hope this helps. _eagle
4 0
3 years ago
Write an algorithm for a method (say is Descending) that accepts an integer arrays (say A) as input parameter, and returns a boo
Neko [114]

Answer:

Check the explanation

Explanation:

Algorithm for determining if the array passed as argument is in descending order or not.

1. Start

2. A = {1, 2, 3, 4};

3. Call function by passing array and it's size.

   isDescending(A, A.length);

4. Loop from 1 to size - 1 (inclusive)

5.     check if element at (i-1)th index is greater than element at (i)th index or not

6.     if at any point the above expression is executed to true value then return false

7.     if the above if statement is not executed then loop will terminate it self

8. Now return true.

// Java Implementation:

public static boolean isDescending(int[] arr, int size) {

   for (int i = 1; i < size; i++) {

       if (arr[i-1] > arr[i]) {

           return false;

       }

   }

   return true;

}

4 0
4 years ago
Other questions:
  • You have been tracking your exercise routine, which involves running, lifting weights, yoga, and stretching. You want to see wha
    15·2 answers
  • Teachers in most school districts are paid on a schedule that provides a salary based on their number of years of teaching exper
    10·1 answer
  • Why is it a mistake to put e-mail address of people who don't know each other in the "to:" field
    9·2 answers
  • When a crash results in property damages of any amount, the driver must notify:
    10·1 answer
  • When you use cloud computing, what do you need to access your files and applications?
    12·1 answer
  • In the context of wireless signal propagation, the phenomenon that occurs when an electromagnetic wave encounters an obstruction
    14·1 answer
  • 1, and
    9·1 answer
  • Select the correct answer. Why is it important to identify your audience while making a presentation? A. It helps you define the
    9·2 answers
  • 1 Type the correct answer in the box. Spell all words correctly. Which skill type refers to the ability to interact and communic
    6·1 answer
  • Why should you log into your online or mobile app account with the travel charge card vendor?.
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!