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 is the best way to comment out a section of code that contains comments?
What does int main () mean?
What is a nested formula?
main() { inta=10,b=20; a>=5?b=100:b=200; printf("%d ",b); }
sir, i cannot find the way how to write aprogram by using array on queue
How can a string be converted to a number?
Explain logical errors? Compare with syntax errors.
difference between semaphores and mutex?
12345 1234 123 12 1
In C language, a variable name cannot contain?
a c variable cannot start with a) an alphabet b) a number c) a special symbol d) both b and c above
How do you prevent buffer overflows in C?