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


Please Help Members By Posting Answers For Below Questions

Why c is procedure oriented?

578


Tell me is null always defined as 0(zero)?

679


What is a string?

672


Write a program to print ASCII code for a given digit.

692


How to explain the final year project as a fresher please answer with sample project

474






What is the auto keyword good for?

631


Explain what is a pragma?

596


What are different types of pointers?

568


What is the most efficient way to store flag values?

692


What is pass by reference in functions?

328


What is the use of a conditional inclusion statement in C?

610


What is c method?

540


What is the scope of an external variable in c?

573


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

673


Why pointers are used?

635