Computer Science, asked by heartbeats96, 4 months ago

CARD GAME

Patrick and Johnny started to play a new game which is played with cards. Johnny decided to play card game –I. In this game, he has to pick one card. The number present in the card will determine whether he will be a winner or not.  In the game conducted during the past 3 years, the winner card numbers were 7126, 82417914, 7687 and 6657. Johnny is an expert in data mining and he could easily infer a pattern in the winner card numbers. In the entire card numbers listed here, the sum of the odd numbers is equal to the sum of the even numbers. So write an algorithm, draw flow chart and python program to help Johnny to be a winner using for loop.


Input Format:
Input consists of a single integer.
Output Format:
Output consists of a single line. Refer sample output for details.

 [All text in bold corresponds to input and the rest corresponds to output]

Sample Input and Output 1:
Enter the card picked up by Johnny:
143
Johnny will win the Card Game
 
Sample Input and Output 2:
Enter the card picked up by Johnny:
344
Johnny will not win the Card Game​

Answers

Answered by ananyadasari81
1

Answer:

Patrick and Johnny started to play a new game which is played with cards. Johnny decided to play card game –I. In this game, he has to pick one card. The number present in the card will determine whether he will be a winner or not. In the game conducted during the past 3 years, the winner card numbers were 7126, 82417914, 7687 and 6657. Johnny is an expert in data mining and he could easily infer a pattern in the winner card numbers. In the entire card numbers listed here, the sum of the odd numbers is equal to the sum of the even numbers.

So write a C program to help Johnny to be a winner using for loop.

Input Format:

Input consists of a single integer.

Output Format:

The output consists of a single line. Refer sample output for details.

[All text in bold corresponds to the input and the rest corresponds to output]

Sample Input and Output 1:

Enter the card picked up by Johnny:

143

Johnny will win the Card Game

Sample Input and Output 2:

Enter the card picked up by Johnny:

344

Johnny will not win the Card Game

Program Code:

#include<stdio.h>

int main()

{

int n, o=0, e=0, t;

printf("Enter the card picked up by Johnny:\n");

scanf("%d", &n);

for(;n>0;)

{

t=n%10;

n=n/10;

if(t%2==0)

e+=t;

else

o+=t;

}

if(o==e)

printf("Johnny will win the Card Game");

else

printf("Johnny will not win the Card Game");

return 0; }

Answered by sadiaanam
0

As per the question given,

Patrick and Johnny started to play a new game which is played with cards. Johnny decided to play a card game –I. In this game, he has to pick one card. The number present on the card will determine whether he will be a winner or not.  In the game conducted during the past 3 years, the winner card numbers were 7126, 82417914, 7687 and 6657. Johnny is an expert in data mining and he could easily infer a pattern in the winner card numbers. In the entire card numbers listed here, the sum of the odd numbers is equal to the sum of the even numbers. So write an algorithm, draw a flow chart and python program to help Johnny to be a winner using for loop.

Input Format:

Input consists of a single integer.

Output Format:

The output consists of a single line. Refer sample output for details.

[All text in bold corresponds to input and the rest corresponds to output]

Sample Input and Output 1:

Enter the card picked up by Johnny:

143

Johnny will win the Card Game

Sample Input and Output 2:

Enter the card picked up by Johnny:

344

Johnny will not win the Card Game

The Code for the Program is:

#include<stdio.h>

int main()

{

int n, o=0, e=0, t;

printf("Enter the card picked up by Johnny:\n");

scanf("%d", &n);

for(;n>0;)

{

t=n%10;

n=n/10;

if(t%2==0)

e+=t;

else

o+=t;

}

if(o==e)

printf("Johnny will win the Card Game");

else

printf("Johnny will not win the Card Game");

return 0; }

#SPJ3

Similar questions