Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Other Programming (https://www.askmehelpdesk.com/forumdisplay.php?f=437)
-   -   Algorithm (https://www.askmehelpdesk.com/showthread.php?t=771348)

  • Oct 15, 2013, 07:21 AM
    jercee
    Algorithm
    Write an algorithm to find the first 50 natural numbers
  • Oct 16, 2013, 03:52 PM
    Celine91
    A very simple c++ code can be :

    #include <iostream>
    using namespace std;
    int main()
    {

    for (int i =0; i<49; i ++)
    {
    cout<<i<<" ";
    }

    return 0;
    }

    --------------------------------------------------
    if you only want a general algorithm to read the first n natural numbers:

    1. Read n
    2. Initialize N = 0
    3. Calculate N = N+1
    4. If N> n-1, stop
    5. Write N

  • All times are GMT -7. The time now is 05:12 AM.