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!!!)
Answer Posted / 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 |
Post New Answer View All Answers
what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9
What oops means?
What is the scope of local variable in c?
how logic is used
How will you divide two numbers in a MACRO?
What does s c mean in text?
Difference between Function to pointer and pointer to function
Can static variables be declared in a header file?
Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..
What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
Which is more efficient, a switch statement or an if else chain?
Give differences between - new and malloc() , delete and free() ?
What is a wrapper function in c?
what is the format specifier for printing a pointer value?
Explain the use of keyword 'register' with respect to variables.