Vote Up 0 Vote Down

print 1 to N natural numbers

Print 1 to N natural numbers (order is important) by using single variable like for example int i; by using any loops in c/c++/java. Please help. ..
flag

Answers


Vote Up 0 Vote Down
#include
int n;
void rec()
{
if(n==1)
{printf("%d",n);
return;}
else
{n--;
rec();
printf("%d",++n);}
}
int main(void)
{
scanf("%d",&n);
rec();
return 0;
}
flag | link |
Vote Up 0 Vote Down
#include<stdio.h>

int main()

{ static int i=0;

if(++i!=101)

{

printf("\n%d",i);

main();

}

return 0;

}</stdio.h>
flag | link |
Vote Up 0 Vote Down
scanf("%d", &n);
while(n--) {
printf("%d", n + 1 );
}
flag | link |

Your Answer

Login before answering

Login with facebook