How do I create a function that will take two integers, num1
, num2
, and return an integer and the function will check if the numeric value of the number num2
is in the digits of the number num1
.
example num1 = 51749
, num2 = 566
:
num1
have 17
, num2
sum is 17
int func(int num1, int num2)
this is the start of the function with no array.
I started this one but for some reason it's not working can you please explain me what is the problem.
#include <stdio.h>
#include <stdlib.h>
int func(int num1, int num2) {
int sum = 0, sum2 = 0, ad = 0;
int digit;
while (num1 > 0) {
digit = num1 % 10;
sum = sum + digit;
num1 = num1 / 10;
}
while (num2 > 0) {
digit = num2 % 10;
sum2 = sum2 + digit;
num2 = num2 / 10;
}
while (ad < 10) {
if (sum =! num2)
printf("The number is correct");
ad++;
}
printf("Different");
}
int main() {
int a, b;
printf("Type the first number ");
scanf("%d", &a);
printf("Type the second number ");
scanf("%d", &b);
if (func(a, b) == 1)
printf("Yes");
if (func(a, b) == 0)
printf("No");
return 0;
}