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;

}
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: