Write a program to print numbers from 1 to 100 without using loops and conditional statements?

Method (Using recursion)

void main()
{

static int i=1;

printf(“%d”,i++);

(i<100) && main();

}

Method1 (Using recursion)

void printUp(int startNumber, int endNumber)
{
if (startNumber > endNumber)
return;

printf(“[%d]\n”, startNumber++);
printUp(startNumber, endNumber);
}

Method2 (Using goto)

void printUp(int startNumber, int endNumber)
{
start:

if (startNumber > endNumber)
{
goto end;
}
else
{
printf(“[%d]\n”, startNumber++);
goto start;
}

end:
return;

Advertisements

4 thoughts on “Write a program to print numbers from 1 to 100 without using loops and conditional statements?

  1. Nandhithaa says:

    Hi sir
    all ur posts are really very useful
    y don u start tutorial for beginners and professionals so all will be benefited

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s