I'm printing the following pattern using loops:
1 12 123 1234 12345
Why is the following code displaying some random values before displaying the pattern? It works fine when I do so using recursion to some random function func(int a, int b)
and passing values (1, 1) from main
to this function.
int a=1,b=1;
int main(int a, int b)
{
if(a>5)
return 0;
else if(b<a)
{
printf("%d",b);
main(a,++b);
}
else if(b==a)
{
printf("%d ",b);
main(++a,1);
}
}