jeudi 22 juin 2017

Control statement

#include <stdio.h>

void main()
{
    char al;
    char n1[10], n2[10], n3[10];
    scanf("%s", &n1[10]);
    scanf("%s", &n2[10]);
    scanf("%s", &n3[10]);
    scanf("%s", &al[10]);
    if (((n1[0] || n2[0] || n3[0]) == al) && ((n1[0] && n2[0] && n3[0]) != '@') && ((n1[0] && n2[0] && n3[0]) != ' '))
        printf("yes\n");
    else
        printf("no\n");
}

This is my code. Here I've enter three words and a character. The operation intended is to check whether the first letter of at least any one of the three words matches with the character entered. If it does, the output is to be displayed 'yes' else 'no'.

But the code does not satisfy the purpose. There are no syntax errors. I guess there's a problem with multiple checking conditions given within the if statement. It displays no in the place of yes, while the output rarely proves to be yes even when the conditions are met. Where could I've possibly gone wrong?

For more clarity, I'll add the question and the same input & output below,

In the gifts store, Tintu finds a lot of fancy articles with letters inscribed in it. She decides to select gifts for her friends such that the first letter of their names is inscribed in the gift articles.

There is a hifi-scanner device in the gifts shop that would illuminate the articles that contain the letters fed as input. There is another interfacing device that would pick the 1st letters of all names entered by the user. Suddenly the device started malfunctioning and Nisha the owner of the shop is very tensed. Tintu is a very close friend of Nisha and she offers to help her in fixing this issue. She starts rewriting the program to be embedded in the scanner like device. Can you help her out?

TestCase

Input 1

MAHIRL
CHITRA
DEVI
C

Output 1

yes

Input 2

MAHIRL
CHITRA
DEVI
A

Output 2

no

Input 3

JON SNOW
ARYA STARK
HODOR
S

Output 3

no

Input 4

@ON SNOW
ARYA STARK
HODOR
@

Output 4

no

Aucun commentaire:

Enregistrer un commentaire