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
Why c is procedure oriented?
Tell me is null always defined as 0(zero)?
What is a string?
Write a program to print ASCII code for a given digit.
How to explain the final year project as a fresher please answer with sample project
What is the auto keyword good for?
Explain what is a pragma?
What are different types of pointers?
What is the most efficient way to store flag values?
What is pass by reference in functions?
What is the use of a conditional inclusion statement in C?
What is c method?
What is the scope of an external variable in c?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
Why pointers are used?