Home  Interview Questions  Certifications  Aptitude Questions  Tutorials  Placement Papers  Search  Resume  Soft Skills  Video  Forum  Blog

Technical Interview Questions

Visual Basic Interview Question
ASP .NET Interview Questions
C++ Interview Questions
C Interview Questions

Programming Source Codes
C/C++ Source Codes
C# Source Codes

Aptitude Interview Questions
C/C++ Aptitude Questions
C Aptitude Questions

C Tutorial
C++ Tutorial

Soft Skills
Communication Skills
Leadership Skills




C/C++ Source Codes

factorial using recursion and iteration/loops in C language


int fib_rec(int n) {
if (n == 0)
return 0;
else if (n == 1)
return 1;
return (fib_rec(n - 1) + fib_rec(n - 2));

int fib_loop(int n) {
int a, b, sum;
a = b = sum = 0;
b = 1;
if (n <= 0)
return 0;
else if(n == 1 '' n == 2)
return 1;
while(n > 1) {
sum = a + b;
a = b;
b = sum;
return sum;

int main() {
int i, n = 37;
printf("the fib upto %d using recursion is: \n",n);
for(i = 0; i < n; i++)
printf("%d, ",fib_loop(i));

printf("\nthe fib upto %d using loop is: \n",n);
for(i = 0; i < n; i++)
printf("%d, ",fib_rec(i));

return 0;

<<<----- Return to C/C++ Source Code Questions Page.

Have a Question ? post your questions here. It will be answered as soon as possible.

Check Object Oriented Interview Questions for more Object Oriented Interview Questions with answers

Check Data Structure Interview Questions for more data structure interview questions with answers