Write a program to calculate the sum of frist 100 number .( i.e. 1 to 100).
Answers
Answer:
sorry I only know till 18
Answer:
If you’re looking for a generic way to do it, a for or while loop would both work with relative ease.
with a for loop, you’d create a generic variable (e.g. “sum”), then set the loop to iterate for a variable i, initially valued at 1, until i is more than 100, adding i to sum and 1 to i each iteration.
for a while loop, you’d do the same thing, but iterate while i is less than or equal to 100.
Examples (syntax will vary)
int sum;
for (int i=1; i<=100; 1++){
sum += i;}
or
int sum;
int i=1;
while (i<=100){
sum += i; }
Explanation:
ex:
public class Sum {
public static void main(String[] args){
int sum=0;
for(int i=10; i<=100; i=i+2){
sum = sum + i;
}
System.out.println(sum);
}
}
you have too prepare for class 11th C.S Exam on 25th.
Right