Write a C++ program without using any loop (if, for, while
etc) to print numbers from 1 to 100 and 100 to 1;

Answer Posted / om

#include<stdio.h>
void print_1_to_100(int n);
void print_100_to_1(int n);

int main()
{
print_1_to_100(1);
return 0;
}

void print_1_to_100(int n)
{
printf("%d\t",n);
(n/100)? print_100_to_1(n) :print_1_to_100(n+1);
}


void print_100_to_1(int n)
{
printf("%d\t",n);
(n-1)? print_100_to_1(n-1) :1;
return;
}

//SAMPLE OUTPUT
1 2 3 4 ....100 100 99 98 ...2 1

Is This Answer Correct ?    52 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is #error and use of it?

681


Explain the difference between call by value and call by reference in c language?

645


How can a number be converted to a string?

600


What is the difference between formatted&unformatted i/o functions?

614


Can static variables be declared in a header file?

614






When is a “switch” statement preferable over an “if” statement?

648


Explain the Difference between the New and Malloc keyword.

687


How can I make sure that my program is the only one accessing a file?

678


How can this be legal c?

651


Explain why can’t constant values be used to define an array’s initial size?

854


Explain is it valid to address one element beyond the end of an array?

731


Tell me when is a void pointer used?

647


What is difference between structure and union in c?

544


p*=(++q)++*--p when p=q=1 while(q<=6)

1266


What is the difference between ‘g’ and “g” in C?

2531