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

Explain #pragma statements.

593


Why is not a pointer null after calling free?

583


What is equivalent to ++i+++j?

633


Is c procedural or object oriented?

563


Explain how do you determine a file’s attributes?

584






What is the use of ?

609


What is the 'named constructor idiom'?

629


List the difference between a "copy constructor" and a "assignment operator"?

570


Device an algorithm for weiler-atherton polygon clipping, where the clipping window can be any specified polygon

5453


Explain how do you determine the length of a string value that was stored in a variable?

659


how can I convert a string to a number?

585


Why is c known as a mother language?

732


What is difference between array and structure in c?

565


difference between native and cross compilers

1659


Explain c preprocessor?

671