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
Write a factorial program using C.
difference between native and cross compilers
What are two dimensional arrays alternatively called as?
How can type-insensitive macros be created?
What type of function is main ()?
What's the best way of making my program efficient?
GIven a sequence of characters. How will you convert the lower case characters to upper case characters. ( Try using bit vector - sol given in the C lib -> typec.h)
When the macros gets expanded?
Are pointers really faster than arrays?
What is cohesion and coupling in c?
Can a function argument have default value?
Write a program to identify if a given binary tree is balanced or not.
What is wrong with this statement? Myname = 'robin';
write a program to concatenation the string using switch case?
Can you please explain the scope of static variables?