Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*program to check a fbonacci number with its position */
- #include <stdio.h>
- int main() {
- int n, first = 0, second = 1, third = 0, count = 3;
- printf("Enter a number: ");
- scanf("%d", &n);
- if (n == 0)
- printf("Yes, Position 1");
- else if (n == 1)
- printf("Yes, Position 2 and 3");
- else {
- while (third < n) {
- third = first + second;
- if (third == n) {
- printf("Yes, Position %d", count);
- break;
- }
- first = second;
- second = third;
- count++;
- }
- if (third > n)
- printf("No");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment