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 / om

#include<stdio.h>
void print_1_to_100(int n);
void print_100_to_1(int n);

int main()
{
print_1_to_100(1);
return 0;
}

void print_1_to_100(int n)
{
printf("%d\t",n);
(n/100)? print_100_to_1(n) :print_1_to_100(n+1);
}


void print_100_to_1(int n)
{
printf("%d\t",n);
(n-1)? print_100_to_1(n-1) :1;
return;
}

//SAMPLE OUTPUT
1 2 3 4 ....100 100 99 98 ...2 1

Is This Answer Correct ?    52 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why c is called a mid level programming language?

1065


What does a function declared as pascal do differently?

1118


Why is c so powerful?

1111


Explain spaghetti programming?

1242


Where static variables are stored in memory in c?

993


Explain what are multibyte characters?

1180


What is strcmp in c?

1112


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

1081


What are the uses of a pointer?

1150


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

1323


What is a MAC Address?

1052


How many types of operator or there in c?

1087


What are all different types of pointers in c?

1005


Explain the difference between ++u and u++?

1128


What is dangling pointer in c?

1212