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
the process of defining something in terms of itself is called (or) in C it is possible for the functions to call themselves. A function called a) nested function b) void function c) recursive function d) indifinite function
Explain pointer. What are function pointers in C?
How are portions of a program disabled in demo versions?
When would you use a pointer to a function?
How can I rethow can I return a sequence of random numbers which dont repeat at all?
What are the similarities between c and c++?
What is time complexity c?
Can two or more operators such as and be combined in a single line of program code?
What do you mean by Recursion Function?
Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
What is variable in c example?
What is static and volatile in c?
Explain what is the difference between text files and binary files?
What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?
How can I get back to the interactive keyboard if stdin is redirected?