find the sum of 10 numbers in for loop
Answers
Answered by
1
First 10 numbers means that we need to start from 1 and go to 10. So, the loop variable of ‘for’ loop will start from 1 and go to 10 (10 will be included).
Below, I am giving an example of how to write the for loop. The syntax will be bit different depending on the language used.
int sum=0;
int i=1;
for(i=1; i <= 10 ; i++) // the value of i will be from 1 to 10
{
sum=sum+i; //each number will get added to the variable ‘sum’
}. I thinking this one is the answer
System.out.println(sum); // here the ‘sum’ variable will give the sum of 10 numbers
Similar questions