Given as input n and m, print the number of digits that are common in n and m. For example, if m = 123 and n = 133, then output = 2
Given as input n and m, print the number of digits that are common in n and m. For example, if m = 123 and n = 133, then output = 2
1 Answers
#include<stdio.h> #include<conio.h> int main() { int n, m, r, count=0; int freq1[10] = {0}; int freq2[10] = {0}; printf("Enter n: "); scanf("%d", &n); printf("Enter m: "); scanf("%d", &m); while(n>0) { freq1[n%10]++; n = n/10; } while(m>0) { freq2[m%10]++; m = m/10; } for (int i = 0; i<10; i++) { if(freq1[i] > 0 & freq2[i]>0) { count++; } } printf("\n Count: %d", count); return 0; }