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
When is a null pointer used?
How can I call system when parameters (filenames, etc.) Of the executed command arent known until run time?
How can a number be converted to a string?
What is queue in c?
Are the variables argc and argv are local to main?
Q.1 write a program to create binary tree 1 to 16 numbers? Q.2 write a program to creat a binary search tree for the member that is given by user?
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
please give me some tips for the placement in the TCS.
What is wrong with this program statement?
What is the difference between a function and a method in c?
swap 2 numbers without using third variable?
a c code by using memory allocation for add ,multiply of sprase matrixes
Is c is a low level language?
How can I manipulate individual bits?
Is main is a keyword in c?