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


Please Help Members By Posting Answers For Below Questions

Write a factorial program using C.

643


difference between native and cross compilers

1671


What are two dimensional arrays alternatively called as?

657


How can type-insensitive macros be created?

695


What type of function is main ()?

583






What's the best way of making my program efficient?

624


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)

678


When the macros gets expanded?

784


Are pointers really faster than arrays?

560


What is cohesion and coupling in c?

587


Can a function argument have default value?

672


Write a program to identify if a given binary tree is balanced or not.

682


What is wrong with this statement? Myname = 'robin';

816


write a program to concatenation the string using switch case?

1558


Can you please explain the scope of static variables?

597