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

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

1316


Explain pointer. What are function pointers in C?

1086


How are portions of a program disabled in demo versions?

1298


When would you use a pointer to a function?

1052


How can I rethow can I return a sequence of random numbers which dont repeat at all?

1192


What are the similarities between c and c++?

1079


What is time complexity c?

1001


Can two or more operators such as and be combined in a single line of program code?

1375


What do you mean by Recursion Function?

1130


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.

1066


What is variable in c example?

1079


What is static and volatile in c?

1226


Explain what is the difference between text files and binary files?

1161


What is a 'null pointer assignment' error? Explain what are bus errors, memory faults, and core dumps?

1248


How can I get back to the interactive keyboard if stdin is redirected?

1192