Answer to Question #282732 in C for sunny

Question #282732
  1. Input two integers in one single line. The first inputted integer must be within 0-9 only.
  2. Using loops, identify if the first inputted integer (0-9) is present in the second inputted integer. If it is found, print "Yes". Otherwise, print "No".

Input


1. The digit to be found

2. The integer to be searched

Output


The first line will contain a message prompt to input the digit to be found.

The second line will contain a message prompt to input the integer.

The last line contains the appropriate string.

Enter·the·digit·(0·-·9):·1
Enter·the·integer:·231214238
Yes

Test Case 2

Expected Output

Enter the digit (0 - 9): 0
Enter the integer: 123456
No









1
Expert's answer
2021-12-27T08:39:02-0500
#include <stdio.h>


int main() {
    int d, num;


    printf("Enter the digit (0 - 9): ");
    scanf("%d", &d);


    printf("Enter the integer: ");
    scanf("%d", &num);


    if (d == 0 && num == 0) {
        printf("Yes\n");
        return 0;
    }
    
    while (num > 0) {
        if (num%10 == d) {
            printf("Yes\n");
            return 0;
        }
        num /= 10;    
    }


    printf("No\n");
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS