Ask Question
21 August, 05:28

Write an algorithm which gets a number N, and prints all the natural numbers less than or equal N. 3.

+3
Answers (1)
  1. 21 August, 09:18
    0
    Algorithm:

    1. Create a variable N.

    2. Read the value of N from user.

    3. for i=1 to N.

    3.1 Print value of i.

    4. end program.

    Implementation in C++:

    #include

    using namespace std;

    / / main function

    int main ()

    {

    / / variable

    int N;

    cout<<"Enter value of N:";

    / / read the value of N

    cin>>N;

    cout<<"Natural number from 1 to "<
    for (int i=1; i<=N; i++)

    {

    / / print the numbers

    cout<
    }

    return 0;

    }

    Output:

    Enter value of N:6

    Natural number from 1 to 6 are:1 2 3 4 5 6
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write an algorithm which gets a number N, and prints all the natural numbers less than or equal N. 3. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers