Computer Science, asked by Akshit15062005, 5 months ago

WAP to create a list of 20 numbers find the sum of list and print it along with the list properly.​

Answers

Answered by Shilajit790Ghosh
0

Answer:

//To find the sum of any 20 numbers

import java.util.*;

class Sum_Twenty

{

public static void main (String args[])

{

Scanner sc = new Scanner (System.in)

int n, sum=0, i;

System.out.println("Enter any twenty numbers");

for (i=1;i<=20;i++)

{

n = sc.nextInt();

System.out.println(n)

sum=sum+n;

}

System.out.print("The sum of the entered 20 numbers is " + sum);

}

}

Hope it helps!!

Answered by Equestriadash
7

l = eval(input("Enter 20 elements that you want to be added: "))

print()

print("Your list of numbers: ", l)

s = 0

for i in l:

 s = s + i

print()

print(s, "is the sum of all the elements in the list.")

Once the user inputs 20 numbers, a loop is started.

The range given is the list, which means it includes all the numbers in the list.

The changing variable 'i', takes up all the values and adds it to a sum variable.

Attachments:
Similar questions