Write a C++ program without using any loop (if, for, while
etc) to print numbers from 1 to 100 and 100 to 1;
Answers were Sorted based on User's Feedback
Answer / harpreet kaur
we can create our own header file having a function to
print nos with loop and then use that header file in new
prog with the functoin defined in it.
Is This Answer Correct ? | 30 Yes | 37 No |
Answer / ravi sagar
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i;
int j=100;
int c=0;
printf("1 to 100 then 99 to 1");
for(i=1;i<=100;i++;)
{ if (c==0)
{
printf("%d",i);
if(i==100)
{
c=1;
}
}
if(c==1)
{
j--;
printf("%d",j);
if(j==0)
{
break;
}
}
}
Is This Answer Correct ? | 4 Yes | 11 No |
We can do that by recursive call.....
void fun(int no ){
int t;
printf("%d ",no);
if( no != 100 ){
t=no+1;
fun(t);
}
printf("%d ",no);
}
int main(){
fun(1);
return 0;
}
Is This Answer Correct ? | 17 Yes | 27 No |
Answer / solairaja
void main()
{
int i;
V:
printf("%d",i++);
goto V;
}
Is This Answer Correct ? | 3 Yes | 17 No |
Answer / pur
main()
{
int i =100;
start:
if( i == 0)
goto end;
printf(" %d ",i)
i--;
goto start;
end:
printf(" end of the program");
}
Is This Answer Correct ? | 20 Yes | 47 No |
Answer / gandhi priyank
goto statment is also right because goto statement is not a
loop
e.g.
void main()
{
j:
printf("type your text here");
goto j;
}
Is This Answer Correct ? | 10 Yes | 42 No |
Answer / balaji.k
#include<stdio.h>
#include<conio.h>
void main()
{
clescr();
int i,chl,start;
printf("enter the number from 1 to 100\n");
scanf("%d",ch);
else
go to start
start=1 to 100;
else
go end
exit(0);
}
Is This Answer Correct ? | 3 Yes | 37 No |
Answer / govind
#include<conio.h>
#include<stdio.h>
void main()
{
int i;
clrscr();
printf("\n the value of the 100 to 0 \n");
for(i=100;i>0;i--)
{
if(i==0)
{
goto start;
}
printf(" %d\t",i);
}
printf("\nthe value of the 0 to 100 \n ");
start:
if(i==100)
{
goto end;
}
printf("%d\t",i);
i++;
goto start;
end :
printf("End of the program");
getch();
}
Is This Answer Correct ? | 6 Yes | 67 No |
Find the O/p of the following struct node { char *name; int num; }; int main() { struct node s1={"Harry",1331}; struct node s2=s1; if(s1==s2) printf("Same"); else printf("Diff"); }
What is the purpose of void in c?
What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.
what will be the output for the following program? main() { char ch = 'k'; char c; printf("%c",c); }
Describe the modifier in c?
How can I use a preprocessorif expression to ?
# define prod(a,b)=a*b main() { int x=2; int y=3; printf("%d",prod(x+2,y-10)); } the output of the program is a.8 b.6 c.7 d.none
what is difference between ANSI structure and C99 Structure?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
Write a program that takes a 5 digit number and calculates 2 power that number and prints it
Hai,I have done with my bachelor of commerce and planing to ms,please suggest me how to convince vo for shifting from commerce to computers. Visa on 8 DEC 2014 Npu university
What is the difference between #include and #include 'file' ?