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
What is the use of a static variable in c?
what will be the output for the following main() { printf("hi" "hello"); }
What is the general form of #line preprocessor?
What happens if a header file is included twice?
How can I remove the trailing spaces from a string?
hi send me sample aptitude papers of cts?
How do we open a binary file in Read/Write mode in C?
How are Structure passing and returning implemented by the complier?
Is main is user defined function?
Differentiate between the = symbol and == symbol?
Is main an identifier in c?
how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?
how to count no of words,characters,lines in a paragraph.
Explain the difference between exit() and _exit() function?
What are conditional operators in C?