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
Write a code to remove duplicates in a string.
List out few of the applications that make use of Multilinked Structures?
I have seen function declarations that look like this
What are the salient features of c languages?
What is main return c?
What is #include stdio h and #include conio h?
What is mean by data types in c?
What is binary tree in c?
What is the use of in c?
When c language was developed?
What are formal parameters?
what will be the output for the following main() { printf("hi" "hello"); }
Is main an identifier in c?
If a five digit number is input through the keyboard, write a program to print a new number by adding one to each of its digits.For example if the number that is input is 12391 then the output should be displayed as 23402
What would be an example of a structure analogous to structure c?