Natural numbers : The whole numbers from 1 upwards: 1, 2, 3, and so on ...
Or from 0 upwards in some fields of mathematics: 0, 1, 2, 3 and so on ...
No negative numbers and no fractions.
import java.util.*;
class sum_of_natural_no
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int n,s=0;
System.out.println("Enter the 10 numbers");
for(int i=1;i<=10;i++)
{
n=sc.nextInt();
s=s+n;
}
System.out.println("Sum of 10 natural no:"+s);
}
}
Output:
Enter the 10 numbers
1
2
3
4
5
6
7
8
9
10
Sum of 10 natural no:55
Or from 0 upwards in some fields of mathematics: 0, 1, 2, 3 and so on ...
No negative numbers and no fractions.
import java.util.*;
class sum_of_natural_no
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int n,s=0;
System.out.println("Enter the 10 numbers");
for(int i=1;i<=10;i++)
{
n=sc.nextInt();
s=s+n;
}
System.out.println("Sum of 10 natural no:"+s);
}
}
Output:
Enter the 10 numbers
1
2
3
4
5
6
7
8
9
10
Sum of 10 natural no:55