Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What is the use of a static variable in c?

1057


what will be the output for the following main() { printf("hi" "hello"); }

10988


What is the general form of #line preprocessor?

991


What happens if a header file is included twice?

1034


How can I remove the trailing spaces from a string?

1066


hi send me sample aptitude papers of cts?

2163


How do we open a binary file in Read/Write mode in C?

1238


How are Structure passing and returning implemented by the complier?

1163


Is main is user defined function?

1139


Differentiate between the = symbol and == symbol?

1293


Is main an identifier in c?

1141


how do you write a function that takes a variable number of arguments? What is the prototype of printf () function?

1933


how to count no of words,characters,lines in a paragraph.

4423


Explain the difference between exit() and _exit() function?

1165


What are conditional operators in C?

1092