EmbLogic's Blog

How to prints 1 to 100 without using loop and without using recursion!

Please explain how to prints 1 to 100 without using loop and without using recursion!!.

3 Responses to How to prints 1 to 100 without using loop and without using recursion!

  1. Rahul says:

    I’m not sure what you’re getting at. But without the loop or recursion its a huge code.

    If you simply want to print numbers 1-100 then you can just print them one by one.

  2. vibhor garg says:

    #include

    void printNos(unsigned int n)
    {
    if(n > 0)
    {
    printNos(n-1);
    printf(“%d “, n);
    }
    return;
    }

    int main()
    {
    printNos(100);
    getchar();
    return 0;
    }

  3. Rahul says:

    void printNos(unsigned int n)
    {
    if(n > 0)
    {
    printNos(n-1);
    printf(“%u “, n);
    }
    return;
    }

    int main()
    {
    printNos(100);
    getchar();
    return 0;
    }

    This is the correct code. When using unsigned integer you use the correct specifier. The specifier for unsigned integer is “%u” and for signed integer is “%d”.

    This is still not the answer to the question as the OP wants none of the methods. This code is showing recursion. The fuction printNos is calling itself until its stack gets cleared at the last condition failing( 0>0).

    Here is the output
    http://codepad.org/77JdYHc4

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>