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
How to write a multi-statement macro?
What is floating point constants?
What does the function toupper() do?
why do some people write if(0 == x) instead of if(x == 0)?
Explain what does the function toupper() do?
How can I find out if there are characters available for reading?
How to establish connection with oracle database software from c language?
What are data types in c language?
How can I handle floating-point exceptions gracefully?
what are # pragma staments?
What is a scope resolution operator in c?
How do you redirect a standard stream?
What is c definition?
simple program of graphics and their output display
What is sizeof return in c?