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 |
Difference between Shallow copy and Deep copy?
Explain how can you restore a redirected standard stream?
i want the code for printing the output as follows 4 4 3 3 2 2 1 1 0 1 1 2 2 3 3 4 4
Design a program using an array that searches a number if it is found on the list of the given input numbers and locate its exact location in the list.
How do you list a file’s date and time?
What is external and internal variables What is dynamic memory allocation what is storage classes in C
Is r written in c?
Differentiate between declaring a variable and defining a variable?
program to find the ASCII value of a number
What is "Hungarian Notation"?
Explain how do I determine whether a character is numeric, alphabetic, and so on?
Can I use base-2 constants (something like 0b101010)? Is there a printf format for binary?