Patrick started to play a card game - X. In this game, Patrick has to pick one card with card number 'n'. Based on the card number picked by Patrick, he has to pick 'n' cards and arrange those 'n' cards in Fibonacci series. He is confused on which card he has to pick and in which order he has to arrange.
He approaches you and asks for your help.
Can you please help him with the program to print all card numbers that Patrick has to pick and arrange(using the while loop)?
Input Format:
Input consists of an integer.
The input consists of an integer n, which corresponds to the card number picked up by Patrick.
Output Format:
Refer Sample Input and Output for formatting specifications.
[All text in bold corresponds to the input and the rest corresponds to output]
Sample Input and Output 1:
Enter the card number picked up by Patrick:
10
Patrick must pick and arrange cards in below order
1 1 2 3 5 8 13 21 34 55
Sample Input and Output 2:
Enter the card number picked up by Patrick:
4
Patrick must pick and arrange cards in below order
1 1 2 3
Program Code:
#include <stdio.h>
int main()
{
int i, n, t1 = 1, t2 = 1, nextTerm;
printf("Enter the card number picked up by Patrick:\n");
scanf("%d", &n);
printf("Patrick must pick and arrange cards in below order\n");
i = 1;
while(i <= n)
{
printf("%d ", t1);
nextTerm = t1 + t2;
t1 = t2;
t2 = nextTerm;
++i;
}
return 0;
}
Post A Comment:
0 comments: