Ask Question

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

+3
Answers (1)
  1. 15 January, 20:00
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers