Write a program to calculate sum of 1
st 10 natural number.
Answers
Answered by
0
Answer:
In java -
public class SumOfNaturalNumber1
{
public static void main(String[] args)
{
int i, num = 10, sum = 0;
//executes until the condition returns true
for(i = 1; i <= num; ++i)
{
//adding the value of i into sum variable
sum = sum + i;
}
//prints the sum
System.out.println("Sum of First 10 Natural Numbers is = " + sum);
}
}
Similar questions