Display sum of numbers from 50 to 80
Answers
Answered by
0
-----------Python Code---------
#Code to display sum of numbers from 50 to 80
#Code written by @swetank232894
s=0
for I in range(50,80+1):
s=s+I
print("Sum=",s)
•Python Output Attached
----------Java Code---------
package Coder;
public class Sum
{
public static void main (String ar [])
{int s=0;
for(int i=50;i<=80;i++)
{
s+=i;
}
System.out.println("Sum="+s);
}
}
•Java Output Attached
-------------QBASIC CODE--------
CLS
FOR I=50 TO 80
S=S+I
NEXT I
PRINT "SUM="+S
END
_____________________
Code Explaination:-
- The program runs a loop from 50 to 80
- in each iteration, variable s adds the value of i with it's previous value or in other words, calculates the sum
- When the loop terminates, the sum gets displayed.
____________________
Variable Description:-
- i :- loop variable
- s:- To calculate and store the sum
Attachments:
Similar questions