Patrick and Johnny started to play card game - IV. In this game, Patrick and Johnny have to pick one card each. Based on the card number picked by Patrick and Johnny, they have to pick few more cards which are between Patrick's and Johnny's cards and arrange those cards in an order starting from Patrick's card to Johnny's card. Both are confused on which card they have to pick and in which order they have to arrange.
They approach you and ask for your help.
Can you please help them with the program to print all card numbers between the cards picked by Patrick and Johnny(using for loop)?
Input Format:
Input consists of 2 integers.
The first integer corresponds to the card number picked up by Patrick.
The second integer corresponds to the card number picked up by Johnny.
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
Enter the card number picked up by Johnny:
4
Patrick and Johnny must pick and arrange cards in below order
10
9
8
7
6
5
4
Sample Input and Output 2:
Enter the card number picked up by Patrick:
4
Enter the card number picked up by Johnny:
10
Patrick and Johnny must pick and arrange cards in below order
4
5
6
7
8
9
10
Program Code:
#include<stdio.h>
int main()
{
int p, j, i;
printf("Enter the card number picked up by Patrick:\n");
scanf("%d", &p);
printf("Enter the card number picked up by Johnny:\n");
scanf("%d", &j);
printf("Patrick and Johnny must pick and arrange cards in below order\n");
if(p<j)
{
for(i=p;i<=j;i++)
{
printf("%d\n", i);
}
}
else
{
for(i=p;i>=j;i--)
{
printf("%d\n", i);
}
}
return 0;
}
Post A Comment:
0 comments: