Check fibonacci series >>
Input type: Integer(number)
Input: 10
Output: 0 1 1 2 3 5 8 13 21 34
Constraints:
number>5 and number<=20
If Input number given by user is space, character or empty display "INVALID INPUT".
CODE in C:
#include<stdio.h>
int main()
{
int n1=0,n2=1,n3,i,number;
printf("Enter the number of elements:");
scanf("%d",&number);
if(number<=5 || number>20){
printf("INVALID INPUT");
}
else{
printf("\n%d %d",n1,n2);
for(i=2;i<number;++i){
n3=n1+n2;
printf(" %d",n3);
n1=n2;
n2=n3;
}
}
return 0;
}
OUTPUT :
Enter the number of elements:10
0 1 1 2 3 5 8 13 21 34
Comments
Post a Comment