Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- int same_num_odd_digits(unsigned long n1, unsigned long n2);
- int main ()
- {
- unsigned long a,b;
- printf("Please enter 2 unsigned long nums : \n");
- scanf("%lu%lu",&a,&b);
- int c = same_num_odd_digits(a,b);
- if (c == 0)
- {
- printf("%lu and %lu have the same num of odd digits\n",a,b);
- return 0;
- }
- printf("%lu and %lu do NOT have the same num of odd digits\n",a,b);
- return 0;
- }
- int same_num_odd_digits(unsigned long n1, unsigned long n2)
- {
- if ((n1 == 0) && (n2 == 0))
- return 0;
- if (n1 != 0)
- {
- if (n1 % 10 % 2 != 0)
- {
- return 1 + same_num_odd_digits(n1/10,n2);
- }
- else
- same_num_odd_digits(n1/10,n2);
- }
- if (n2 != 0)
- {
- if (n2 % 10 % 2 != 0)
- {
- return -1 + same_num_odd_digits(n1,n2/10);
- }
- else
- same_num_odd_digits(n1,n2/10);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement