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

what is the c source code for the below output? 10 10 10 10 10 10 10 10 10 10 9 9 7 6 6 6 6 6 6 9 7 5 9 7 3 2 2 5 9 7 3 1 5 9 7 3 5 9 7 4 4 4 4 5 9 7 8 8 8 8 8 8 8 8 9

1422


What oops means?

570


What is the scope of local variable in c?

567


how logic is used

1490


How will you divide two numbers in a MACRO?

694






What does s c mean in text?

600


Difference between Function to pointer and pointer to function

621


Can static variables be declared in a header file?

606


Describe the complexity of Binary search, Quicksort and various other sorting and searching techniques..

638


What is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

613


Which is more efficient, a switch statement or an if else chain?

568


Give differences between - new and malloc() , delete and free() ?

601


What is a wrapper function in c?

572


what is the format specifier for printing a pointer value?

606


Explain the use of keyword 'register' with respect to variables.

584