write an algorithm to generate and print the first N natural numbers
Answers
Answered by
3
Java::
import java.util.Scanner;
public class Brainly {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
for(int i = 1; i <= x; i++) {
System.out.println(i);
}
}
}
Logic::
==> We imported scanner class for input.
==> Then we ran a for loop from 1[since natural numbers start from 1] until the input.
==> Inside the loop we printed the variable i using println method.
Sample I/O ::
Input::
5
Output::
1
2
3
4
5
I hope that my answer helps you....
Similar questions
Physics,
5 hours ago
Physics,
5 hours ago
English,
9 hours ago
Science,
9 hours ago
Computer Science,
8 months ago