Computer Science, asked by murugan8824, 9 hours ago

write an algorithm to generate and print the first N natural numbers​

Answers

Answered by purveshKolhe
3

\huge{\green{\boxed{\blue{\mathfrak{ answer :: }}}}}

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