Computer Science, asked by hhujggf, 10 months ago

Write a program to find the sum of all natural numbers from 1 to n.

Answers

Answered by Anonymous
9

import java.util.*;

public class Natural

{

public static void main(String args[])

{

Scanner in = new Scanner(System.in);

int a,n,s=0;

System.out.println("Enter the value of n");

n=in.nextInt();

for(a=1;a<=n;a++)

s=s+a;

System.out.println("The sum of natural numbers up to" + n+" = "+s);

}

}

Similar questions