Write a C++ program without using any loop (if, for, while
etc) to print numbers from 1 to 100 and 100 to 1;
Answer Posted / shubham gupta
#include<stdio.h>
void fun(int n)
{
static int i=1,j;
j=printf("%d\n",i); // when i=100 printf will return 4
// bcoz of 3 difits of 100 and 1 '\n' character
switch(j)
{
case 4:
exit(0);
default: i++;
fun(n) ;
}
}
int main()
{
int n;
n=100;
fun(n);
}
| Is This Answer Correct ? | 0 Yes | 6 No |
Post New Answer View All Answers
Explain what are the __date__ and __time__ preprocessor commands?
How is a null pointer different from a dangling pointer?
How do you initialize pointer variables?
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?
Explain pointers in c programming?
What is time complexity c?
What is a structure in c language. how to initialise a structure in c?
What is wrong with this program statement?
how can f be used for both float and double arguments in printf? Are not they different types?
Explain the use of fflush() function?
Where are c variables stored in memory?
What is the use of typedef in structure in c?
c program to compute AREA under integral
In C language what is a 'dangling pointer'?
What is wrong with this initialization?