Sponsored Links

Interview Questions



INTERVIEW QUESTIONS C BRANCHES & LOOPS IN C DETAILS

Question: How to print 1 to 100 without using any conditional loop?

Answer: By using recursive function.

Category Branches & Loops in C Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.3) By 8129 users
Added on 6/4/2013
Views 75239
Rate it!

Question: How to print 1 to 100 without using any conditional loop?

Answer:

By using recursive function. Source: CoolInterview.com

Answered by: kiran | Date: 6/5/2008 | Contact kiran Contact kiran

Recursion is solution of this problem.

DisplayInfo(Int val = 1)
{
Printf("%d ", val);
if(val == 100)
return;
else
DisplayInfo(++val);
} Source: CoolInterview.com

Answered by: Paresh | Date: 6/7/2008 | Contact Paresh Contact Paresh

for(i=1;i<=100;i++)
{
printf(/n"%d",i);
} Source: CoolInterview.com

Answered by: amitabh ranjan | Date: 6/9/2008 | Contact amitabh ranjan Contact amitabh ranjan

DisplayInfo(Int val = 1)
{
Printf("%d ", val);
if(val == 100)
return;
else
DisplayInfo(++val);
} Source: CoolInterview.com

Answered by: Saktipada Upadhyaya | Date: 6/13/2008 | Contact Saktipada Upadhyaya Contact Saktipada Upadhyaya

int a=1;
l:if(a<=100)
{
printf("%d",a);
goto a;
} Source: CoolInterview.com

Answered by: mani krishna | Date: 6/14/2008 | Contact mani krishna Contact mani krishna

U all have used condition in one way or another.
To solve this problem we have to
use 'asm' keyword.
google 'asm' to find out more details about asm.
thanks Source: CoolInterview.com

Answered by: om prakash mishra | Date: 6/16/2008 | Contact om prakash mishra Contact om prakash mishra

Reply amitabh u cant tell answers without observing the questions ok don't do again in future otherwise it will light bad on freshers. Source: CoolInterview.com

Answered by: suresh | Date: 6/16/2008 | Contact suresh Contact suresh

Display(Int val = 1)
{
Printf("%d ", val);
while(val == 100)
{
return;
}
Display(val++);
} Source: CoolInterview.com

Answered by: kovendan venkat | Date: 6/23/2008 | Contact kovendan venkat Contact kovendan venkat

Display(Int val = 1)
{
Printf("%d ", val);
while(val == 100)
{
return;
}
Display(val++);
} Source: CoolInterview.com

Answered by: karan | Date: 7/1/2008 | Contact karan Contact karan

#include<stdio.h>
#include<conio.h>
void main()
{
int a=1;
clrscr();
SHOW:
if(a>100)
{
}
else
{
printf("%d
",a);
a+=2;
goto SHOW;
}
getch();
} Source: CoolInterview.com

Answered by: Sourabh | Date: 7/10/2008 | Contact Sourabh Contact Sourabh

void main()
{
unsigned int i=100;
back:printf("%d
",i);
i--;
getch();
} Source: CoolInterview.com

Answered by: amol bhosale | Date: 7/12/2008 | Contact amol bhosale Contact amol bhosale

main()
{
static int i=1;
if(i<=100)
{
printf("%d",i++);
main();
}
} Source: CoolInterview.com

Answered by: venkat | Date: 7/14/2008 | Contact venkat Contact venkat

main()
{
static int i=1;
if(i<=100)
{
printf("%d",i++);
main();
}
}
Source: CoolInterview.com

Answered by: balakrishnan | Date: 7/28/2008 | Contact balakrishnan Contact balakrishnan

fun(int a)
{
printf(a);
a++;
}

main()
{

a=(a>100)?func(a):1;
}
Source: CoolInterview.com

Answered by: vidya | Date: 8/3/2008 | Contact vidya Contact vidya

#include<stdio.h>

int print(int i)
{
printf(" %d ",i^1?print(i-1):i);
return i+1;
}
int main()
{
print(100);
return 0;
}
Source: CoolInterview.com

Answered by: pawan pant | Date: 8/4/2008 | Contact pawan pant Contact pawan pant

//in java;
k=1;
void disp(int k)
{
System.out.println(k);
if(k==100)
return void;
else
disp(++k);
} Source: CoolInterview.com

Answered by: Prem Prakash Shani | Date: 8/26/2008 | Contact Prem Prakash Shani Contact Prem Prakash Shani

simple!
int main()
{
printf("1 to 100");
return 0;
}

Source: CoolInterview.com

Answered by: B.N.V.R.Ganesh | Date: 8/30/2008 | Contact B.N.V.R.Ganesh Contact B.N.V.R.Ganesh

void main()
{
int a=1,b;
b=sum(a);
printf("%d",a);
printf("%d",b);
getch();
}
int sum(int a1)
{
if(a1<=100)
sum(a1+1);
}
Source: CoolInterview.com

Answered by: VAIBHAV | Date: 10/8/2008 | Contact VAIBHAV Contact VAIBHAV

#include "stdafx.h"
#include "stdio.h"

void printnumber(int num)
{
num++;
printf("%d
",num);
if(num < 100)
printnumber(num);
}

void main()
{
int var = 0;
printnumber(var);
}

execute this with vc++ compiler. Source: CoolInterview.com

Answered by: sushil pant | Date: 4/30/2009 | Contact sushil pant Contact sushil pant

This is an open question with no bounds defined. However, the following one of the ways of doing it:

int foo(void)
{
int i = 1;

loop:
if(i <= 100)
{
printf("i
");
}
else
{
return;
}
goto loop;
}
Source: CoolInterview.com

Answered by: Ravi A Joshi | Date: 6/28/2009 | Contact Ravi A Joshi Contact Ravi A Joshi

# include <assert.h>
# include <stdio.h>
#include<iostream.h>
#include<conio.h>
main()
{
int n=1,r;

label:
printf("%d ", n);
assert(n!=100);
n++;
goto label;
} Source: CoolInterview.com

Answered by: girija prasad duggaraju | Date: 8/1/2009 | Contact girija prasad duggaraju Contact girija prasad duggaraju

main()
{
int i =100;

back:
printf ("%d", i);
i --;
if(i == 0)
goto end;
goto back;

end:
exit()
} Source: CoolInterview.com

Answered by: purna | Date: 8/18/2009 | Contact purna Contact purna

#include<stdio.h>
#include<conio.h>
int i=1;
void main()
{
if(i<101)
{
printf("%d ",i);
main();
}
else
{
printf(" bye");
}
getch();

} Source: CoolInterview.com

Answered by: khushmeet singh | Date: 9/2/2009 | Contact khushmeet singh Contact khushmeet singh

int disp(int i)
{
printf(" i = %d
", i);
return (i ^ 100) && disp(++i);
}

int main(void)
{
disp(1);
} Source: CoolInterview.com

Answered by: vibi | Date: 9/11/2009 | Contact vibi Contact vibi

int getsum(int n)
{
int sum=0;
if(n==0)
return(sum);
else
sum=sum+n+getsum(n-1);
return(sum);
} Source: CoolInterview.com

Answered by: santosh kumar mallick | Date: 9/29/2009 | Contact santosh kumar mallick Contact santosh kumar mallick

void main()
{
int i;
if(i<=100)
i++
cout<<i:} Source: CoolInterview.com

Answered by: anil kumar pasem | Date: 10/12/2009 | Contact anil kumar pasem Contact anil kumar pasem

#include<conio.h>
#include<stdio.h>
void main()
{ int a;
clrscr();
for(;;){
if(a==100){break;}
else{
printf("
%d",a);}
}getch();
} Source: CoolInterview.com

Answered by: Yash Chauhan | Date: 12/2/2009 | Contact Yash Chauhan Contact Yash Chauhan

#include<stdio.h>
#include<cono.h>
main()
{
int i;
i=1;
clrscr();
while(i<=100)
{
printf("%d
",i);
i++;
}
getch(); Source: CoolInterview.com

Answered by: dileep singh | Date: 12/4/2009 | Contact dileep singh Contact dileep singh

void main()
{
int i;
clrscr()
for(i=1;i<=100;i++)
printf("%d",i);
}
Source: CoolInterview.com

Answered by: rajashekar | Date: 12/5/2009 | Contact rajashekar Contact rajashekar

This can be solved by using TERENARY operators.
void main()
{
int i=1;
clrscr();
n:
i<=100?printf("%d",i):(exit(0));
i++;
goto n;
getch();
}
Source: CoolInterview.com

Answered by: deepak | Date: 12/16/2009 | Contact deepak Contact deepak

main()
{
static int a=1;
printf("%d ",a++);
if(a>100)
{
getch();
exit(0);
}
else
main()
} Source: CoolInterview.com

Answered by: RAJU SAHANI | Date: 2/20/2010 | Contact RAJU SAHANI Contact RAJU SAHANI

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
top:
printf("%3d",i);
if(i<100)
{
i++;
goto top;
}
getch();
} Source: CoolInterview.com

Answered by: venkataesh chowdary | Date: 4/27/2010 | Contact venkataesh chowdary Contact venkataesh chowdary

#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
top:
prinf("%d",i);
if(i<100)
{
i++;
goto top:
}
getch();
}
Source: CoolInterview.com

Answered by: venkatesh annamaeni | Date: 4/28/2010 | Contact venkatesh annamaeni Contact venkatesh annamaeni

#include<stdio.h>
#include<conio.h>
int n=1;
int func(int n)
{
if(n <= 100)
{
printf("%5d",n);
func(n+1);
}
else
return 1;
}
void main()
{
func(n);
getch();
} Source: CoolInterview.com

Answered by: VAMSI KRISHNA | Date: 5/31/2010 | Contact VAMSI KRISHNA Contact VAMSI KRISHNA

See Guys all are wrong.
U guys are using loops again.
Here is the correct answer


#include<stdio.h>
#include<conio.h>
int i=1;
void main()
{
i<=100 ? printf("%d
",i) : getch(); //conditional operator
i++;
main(); //recursive calling of main() function
} Source: CoolInterview.com

Answered by: Gopinath Allanku | Date: 7/4/2010 | Contact Gopinath Allanku Contact Gopinath Allanku

#-----------
#-----------

func(int x)
{
printf("%d",x++);
x<100?func(x):printf("print complete");
}

void main()
{
int x=0;
func(x);
} Source: CoolInterview.com

Answered by: RAJENDRA PRASAD | Date: 7/20/2010 | Contact RAJENDRA PRASAD Contact RAJENDRA PRASAD

Hello folks,

I guess this code snippet is compact and understandable:-

void display(int i){
if( i==101 ) //Not 100, to print 100 as value
return 1;
printf("%d ", i);
display(i+1);
} Source: CoolInterview.com

Answered by: Cleonjoys | Date: 8/2/2010 | Contact Cleonjoys Contact Cleonjoys

#include<stdio.h>
#include<conio.h>
int main(){
void show(int);
show(100);
getch();
return 0;
}
void show(int i)
{
if(i==0)
return;
printf("%d",i);
show(i-1);
} Source: CoolInterview.com

Answered by: subhayu mustafi | Date: 8/30/2010 | Contact subhayu mustafi Contact subhayu mustafi


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
How to decide even and odd values without decision making loops?
View Answer
Nesting of loops in C may continue upto how many levels?
View Answer
if "condition"
printf("Hello");
else
printf("World")

what should be the condition,
so the output will be HelloWorld.
printf("Hello");
else
printf("World")

what should be the c - Branches & Loops in C Interview Questions & Answers"> View Answer
C Program to print the following series:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
View Answer
fibbonaci series program

View Answer
why n++ executes faster than n+1?


View Answer
main()
{
float me = 1.1;
double you = 1.1;
if(me==you)
printf("I love U");
else
printf("I hate U");
}


else
View Answer
x) main()
{
printf("%x",-1<<4);
}


}


- Branches & Loops in C Interview Questions & Answers"> View Answer
How to find entered number is EVEN or ODD without using conditional statement(not using if.. else,if.. , else if..,while, do... while...., for....)

View Answer
Can include files be nested?
View Answer
Is NULL always defined as 0?
View Answer
Which expression always return true? Which always return false?
View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Branches & Loops in C Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2025 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions