C program to print fibonacci series of n numbers.

#include<stdio.h>
#include<conio.h>
void main(){
int n,a,b,c,i;
clrscr();
printf("How many numbers do you want in fibonacci series\n");
scanf("%d",&n);
printf("Enter intial numbers a and b of fibonacci series\n");
scanf("%d%d",&a,&b);
printf("Fibonacci series of %d numbers is -\n",n);
if (n>0) {
if (n==1) printf("%d",a);
else {
if (n==2) printf("%d %d",a,b);
else {
printf("%d %d",a,b);
for (i=1;i<=n-2;i++){
c=a+b;
printf(" %d",c);
a=b;
b=c;
}}}}
else printf("Wrong input\nTry again!!\n");
getch();
}

No comments:

Post a Comment