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;   

}
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: