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

What is bubble sort in c?

0 Answers  


What is a program?

0 Answers  


Can we include one C program into another C program if yes how?

7 Answers   Infosys,


When should a type cast be used?

0 Answers  


What is integer constants?

0 Answers  






How the C program can be compiled?

11 Answers   HP,


write a pgm to print 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1

3 Answers  


Is Exception handling possible in c language?

0 Answers   Wipro,


write a program to display the numbers in the following 4 4 3 3 2 2 1 1 0 1 1 2 2 3 3 4 4

1 Answers  


how to find out the inorder successor of a node in a tree??

2 Answers   TCS, Yahoo,


1. Write a c pgm to print 1 to 100 without using loops. 2. Write a c pgm for leap year 3. Write a c pgm fibbonacci series,factorial 4. Write a c pgm count no of lines , blanks, tabs in a para(File concept) 5. Write a c pgm to print the letter as per given condition i.e.. if u give 4 out put should b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 6.how do get the o/p in number from 1 to 100 in the screen without using control statement? 7. who do u print the word "hello world" without using "printf" statement? 8. write sql program to get the detail of student in a class? Definitions: structure union arrays linkedlist macros directives difference b/w pre processorsDiffrence: 1.Constructors and destructors 2.Structure and Union 3.Array and Lists 4.pre processor... 5. Privillages in C++ 6.structure and union 7.break and continue 8.while and dowhile Pgm..

3 Answers  


Explain the difference between getch() and getche() in c?

0 Answers  


Categories