Computer Science, asked by sayalisalunkhe252002, 5 months ago

write a program to calculate sum of 1 to 10 numbers using while ?​

Answers

Answered by jai696
1

\huge\red{\mid{\fbox{\tt{Using\: Python\: 3}}\mid}}

counter = 1

_sum = 0

while counter < 11:

_sum += counter

counter += 1

print("sum", _sum)

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Answered by anindyaadhikari13
1

Required Answer:-

Question:

  • Write a program to calculate sum of 1 to 10 using while loop.

Solution:

Here is the code for the problem.

In python.

s,i=0,1

while i<=10:

s,i=s+i,i+1

print("Sum is: ",s)

In Java.

public class Sum {

public static void main(String[] args) {

int s=0, i=1;

while(i<=10)

s+=i++;

System.out.println("Sum is: "+s);

}

}

After each iteration, value of i is added to s. Sum of first 10 numbers is stored in s. It is now displayed on the screen.

Output is attached for verification.

Attachments:
Similar questions