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 type is sizeof?

573


What is the explanation for prototype function in c?

556


What is #define used for in c?

601


The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?

649


What is null character in c?

676






What is union and structure?

561


What's the difference between constant char *p and char * constant p?

646


What is the difference between fread buffer() and fwrite buffer()?

661


Which is better malloc or calloc?

643


What is difference between scanf and gets?

601


What is the total generic pointer type?

714


write a sorting prgm to sort 50 nos and sum them and also remove all the occurrences of 15 and print it?

1665


At a shop of marbles, packs of marbles are prepared. Packets are named A, B, C, D, E …….. All packets are kept in a VERTICAL SHELF in random order. Any numbers of packets with these names could be kept in that shelf as in this example: bottom of shelf ---> [AAAJKRDFDEWAAYFYYKK]-----Top of shelf. All these packets are to be loaded on cars. The cars are lined in order, so that the packet could be loaded on them. The cars are also named [A, B, C, D, E,………….]. Each Car will load the packet with the same alphabet. So, for example, car ‘A’ will load all the packets with name ‘A’. Each particular car will come at the loading point only once. The cars will come at the loading point in alphabetical order. So, car ‘B’ will come and take all the packets with name ‘B’ from the shelf, then car ‘C’ will come. No matter how deep in the shelf any packet ‘B’ is, all of the ‘B’ packets will be displaced before the ‘C’ car arrives. For that purpose, some additional shelves are provided. The packets which are after the packet B, are kept in those shelves. Any one of these shelves contains only packets, having the same name. For example, if any particular shelf is used and if a packet with name X is in it, then only the packets having names X will be kept in it. That shelf will look like [XXXXXXX]. If any shelf is used once, then it could be used again only if it is vacant. Packets from the initial shelf could be unloaded from top only. Write a program that finds the minimum total number of shelves, including the initial one required for this loading process.

1725


Why is c not oop?

529


What are linker error?

604