Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100 and 100 to 1 (Do not use 200 print statements!!!)
Answers were Sorted based on User's Feedback
Answer / jane
#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;
}
| Is This Answer Correct ? | 7 Yes | 5 No |
What are the different types of control structures?
List the difference between a "copy constructor" and a "assignment operator"?
What is "Duff's Device"?
What is oops c?
Why is conio.h not required when we save a file as .c and use clrscr() or getch() ?
what are the languages used in c#?
Why is structure important for a child?
Why n++ execute faster than n+1 ?
What is meant by inheritance?
Difference between fopen() and open()?
Explain how are portions of a program disabled in demo versions?
Why do we use & in c?