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
What is memory leak in c?
How do you sort filenames in a directory?
how many types of operators are include in c language a) 4 b) 6 c) 8 d) 12
using only #include
How to compare array with pointer in c?
Can we change the value of constant variable in c?
Explain how can I pad a string to a known length?
What is the value of uninitialized variable in c?
hello freinds next week my interview in reliance,nybody has an idea about it intervew questions..so tell
What are directives in c?
What is the usage of the pointer in c?
Explain how can I convert a string to a number?
How can I get random integers in a certain range?
What is the explanation for the dangling pointer in c?
in case any function return float value we must declare a) the function must be declared as 'float' in main() as well b) the function automatically returned float values c) function before declared 'float' keyword d) all the above