h
5. Write a program using while loop accept a number from the user and
print the sum of the numbers in the range. Example if you input 10 the it
should print( 1+2+3...+10=55) 55 as answer.
Answers
Answered by
2
Answer:
If it is Java programming...then... program is like this...
int i=1,s=0;
while(i<=10)
while(i<=10){
s=s+i;
}
System.out.println(s);
if it is QBASIC.... program will be same but only a small change u have to do..
I=1
S=0
FOR I=1 TO 10
S=S+1
NEXT I
PRINT S
Answered by
1
Question:-
Write a program using while loop accept a number from the user and
print the sum of the numbers in the range.
Program:-
import java.util.*;
class Number
{
public static void main()
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a number: ");
int n=sc.nextInt();
int s=0;
for(int i=1;i<=n;i++)
s+=i;
System.out.println("Sum is: "+s);
}
}
Similar questions