Write a program to find sum of odd numbers between 1 and 10
Answers
Answered by
3
Step1: Count the total odd numbers
1: exist in between 1 to 10. Here it is 5
Step2: Multiply 5×5 = 25
2: So the sum of all odd numbers from 1 to 10 is 25.
You can also calculate all odd numbers between 1 to n numbers from this trick
I hope u understand this
Thanks
Answered by
6
Answer:
import java.util.*;
class SumOfNum
{
Public static void main(string args[])
{
int sum=0;
for(int i=1;i<=10;i++)
{
if(i%2!=0)
{
Sum=sum+i;
}
}
System.out.println("The sum of 10 odd numbers are:"+sum);
}
}
Similar questions
Math,
3 months ago
Math,
3 months ago
Math,
3 months ago
CBSE BOARD XII,
6 months ago
Political Science,
6 months ago
Math,
10 months ago
Math,
10 months ago