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 does s c mean on snapchat?
Why is C language being considered a middle level language?
What is static memory allocation?
What is the purpose of void in c?
How can you return multiple values from a function?
How can a process change an environment variable in its caller?
Why is c called a structured programming language?
What is the difference between malloc() and calloc()?
What happens if header file is included twice?
what is diffrence between linear and binary search in array respect to operators?what kind of operator can be used in both seach methods?
What is the difference between variable declaration and variable definition in c?
How do you print only part of a string?
When should the register modifier be used? Does it really help?
What is an lvalue?
What are the __date__ and __time__ preprocessor commands?