Please explain 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!!.
EmbLogic Research & Competency Development Labs
Phone: +91 9818467776, 8527567776, 9650467776
Email: info@emblogic.com
Copyright © EmbLogic Embedded Technologies Pvt. Ltd.
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.
#include
void printNos(unsigned int n)
{
if(n > 0)
{
printNos(n-1);
printf(“%d “, n);
}
return;
}
int main()
{
printNos(100);
getchar();
return 0;
}
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