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!!!)

Answers were Sorted based on User's Feedback



Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100..

Answer / sweetsmiracle17

plz provide answer

Is This Answer Correct ?    4 Yes 2 No

Write a C++ program without using any loop (if, for, while etc) to print prime numbers from 1 to 100..

Answer / 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

More C Interview Questions

int i=0,j; j=++i + ++i ++i; printf(" %d",j);

2 Answers   ME,


main() { int i = 10; printf(" %d %d %d ", ++i, i++, ++i); }

0 Answers   Wilco,


What is the function of this pointer?

0 Answers   Agilent, ZS Associates,


Find duplicates in a file containing 6 digit number (like uid) in O (n) time.

0 Answers   GrapeCity,


how to swap two integers 1 and 32767 without using third variable

11 Answers   Microsoft, TCS,


which is conditional construct a) if statement b) switch statement c) while/for d) goto

0 Answers  


write a program to concatenation the string using switch case?

0 Answers  


c program to print a name without using semicolon

9 Answers   TCS, Wipro,


implement general tree using link list

1 Answers   Wipro,


What is array of pointers to string?

0 Answers  


Function to find the given number is a power of 2 or not?

20 Answers   Motorola, nvidia,


Explain how can you be sure that a program follows the ansi c standard?

0 Answers  


Categories