Click here to Skip to main content
15,906,624 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Two two digit numbers will be given. You would say which digits are in both the numbers. If there is no such digit, print n.

Input: The first line will contain a number equal to the value of that number, the following lines will contain two two-digit numbers. The two numbers are separated by a space line.

Output: For each line print the matching digits between the two numbers given in that line. If more than one different number matches then print in ascending order and if no match is found then print n.



12 25

33 33

74 86

90 90

65 56

Output :






Questions: I can't understand this problem. How will I solve it?

What I have tried:

#include <stdio.h>

int main()
    int i,j,m,n,t;
    while(t--) {
        int count = 0;
        scanf("%d %d",&m,&n);
        if(m == n) {
            //What will be the condition? 
        else {

    return 0;
Updated 14-Sep-22 5:25am
k5054 13-Sep-22 16:52pm    
This is a fairly straight forward problem, with a fairly clear description of what you need to do. Where are you having problems? What don't you understand?
Lara Thomas 13-Sep-22 17:02pm    
I understand all of things. But I can't understand process. first I will take an array or two integer like int m,n; then I will go to the next part where I compare two number. Now this is my prblm where I can't understand. How will I compare two number ?

I can't understand this problem. How will I solve it?

Reread carefully the requirement.
In 12 and 25, how many times digit 0 ? digit 1 ? digit 2 ? ...
Digit 0 1 2 3 4 5 6 7 8 9
Times 0 1 2 0 0 1 0 0 0 0

Which digit was found more than 1 times ?

You have to create an algorithm/program that will answer the question.
Share this answer
CPallini 14-Sep-22 1:54am    
Patrice T 14-Sep-22 2:49am    
Thank you
Patrice T 14-Sep-22 2:51am    
Did you missed something ? *****
CPallini 14-Sep-22 2:56am    
Sorry, fixed now.
Patrice T 14-Sep-22 3:01am    
I see, thanks
How can I compare two numbers ?
The task I would understand in such a way that all inputs are read from a file. Here not the numbers, but the digits of the two numbers are to be compared. So it would be obvious to declare an array with minimum 4 digits and then check if there are matching digits. Since there can be several digits, these should be output in ascending order. It would therefore make sense to first collect all digits and then output them in the desired order. To process all lines in this way you need a loop that processes all lines. Your program so far contains still little for the solution, here a suggestion for starting:

FILE *fp = fopen("input.txt", "r");
if (fp == NULL) {
	return -1;

char arr[13];

// read first line
fgets(arr, sizeof(arr-1), fp);

int rows = atoi(arr);

if (rows <= 0) {
	return -2;

int ch;

// skip one line
while ((ch = fgetc(fp)) != '\n');

// TODO: Read and process all lines of the file 


If the two numbers are read in with scanf("%d %d", ..), you would have to calculate the digits for each number, so it would probably be easier to work directly with the digits from the text file.
Share this answer
I was looking at a kind of similar issue and I think you can not compare two numbers like this

if(m == n) {
  //What will be the condition? 

you need probably to split each number into an array of digits and then check if the array has duplicates and if so output duplicates in ascending order otherwise output "n". Something like this I believe.

Look into solution on this website as well. I hope it will help you.
Share this answer
I also got this solution. Thank you guys for your helping.


int main()
    int t, j;
    for(j=1; j<=t; j++){
    char num[6];
    if(num[1]==num[3] || num[1]==num[4]){
        printf("%c", num[1]);
        if(num[0]==num[3] || num[0]==num[4]){
                printf("%c", num[0]);}
    else if(num[0]==num[3] || num[0]==num[4]){
        printf("%c", num[0]);
    return 0;
Share this answer
Patrice T 14-Sep-22 3:18am    
Accept your solution if it solve the question.
You can also accept solutions that were useful, it reward helpers.
merano99 14-Sep-22 11:27am    
This solution is still missing the detail that the same digits should be sorted.
Note: The solution is relatively limited and works only if both numbers have exactly 2 digits and are separated by exactly one space. At least this would be just enough for the given example. Also additional characters like letters instead of numbers would be processed unnoticed, was that intentional?
Since C11, gets() is replaced by gets_s(). The gets() function does not perform bounds checking. Some newer Compiler dont support it. Here if your input is to long your Program will crash.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900