the program must accept two integers M and M as input. the program must print "YES"if an integer N is formed from the digit of M.else the program must print "NO" as the output
Answers
Answer:
#include <iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter the number";
cin>>a;
cout<<"Enter the number to be formed";
cin>>b;
int i=0,j=0,arr1[100],arr2[100]; //arr1 and arr2 for storing digits of both numbers
while(a>0)
{
int x=a%10; //taking digits each time
arr1[i]=x; //storing digits
a/=10;
i++;
}
while(b>0)
{
int y=b%10;
arr2[j]=y; //storing digits of number to be formed
b/=10;
j++;
}
int check=0; // a variable to check
for(int h=0;h<j;h++)
{
check=0; //setting value of check each time 0 so that each digit is checked
for(int k=0;k<i;k++)
{
if(arr2[h]==arr1[k]) //comparing each digit
check=1;
}
if(check==0) //if any digit is not found number can't be made break loop and print NO
{
cout<<"NO";
break;
}
}
if(check==1) //if check is 1 even for last digit all other are found so print YES
cout<<"YES";
return 0;
}
Explanation:
Logic is to seperate out digits of both numbers and check if number can be formed or not..
Hope it helps :-)
Mark it brainliest
Program in python:
m, n=int(input("enter M value : ")), int(inpit("enter N value : ")
possible = 0
m = str(m)
n = str(n)
for i in range(0,len(m)):
for j in range(0,len(n)):
if m[i] == n[i]:
possible = possible + 1
if possible == len(n):
print("YES")
else :
print("NO")
Output-1:
enter M value : 1234
enter N value : 12
YES
Output-2:
enter M value : 1234
enter N value : 12345
NO
Explanation:
>first i took 2 number as m and n
>then i converted them to string type
>and i used nested loop
>to check number n's digits are in number m or not
> so if n digits are all in m then "possible" count should be the length of n
> so if "possible" count is length of n then number n can be formed with digits of m
>at last i checked yhe condition and printed "YES" if true, "No" if false
----if you need the program in another language u can use this logic syntax may change but logic will not
first u have to specify in which program the code should be in