Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. int same_num_odd_digits(unsigned long n1, unsigned long n2);
  6. int main ()
  7. {
  8. unsigned long a,b;
  9. printf("Please enter 2 unsigned long nums : \n");
  10. scanf("%lu%lu",&a,&b);
  11.  
  12.  
  13. int c = same_num_odd_digits(a,b);
  14. if (c == 0)
  15. {
  16. printf("%lu and %lu have the same num of odd digits\n",a,b);
  17. return 0;
  18. }
  19. printf("%lu and %lu do NOT have the same num of odd digits\n",a,b);
  20. return 0;
  21. }
  22. int same_num_odd_digits(unsigned long n1, unsigned long n2)
  23. {
  24. if ((n1 == 0) && (n2 == 0))
  25. return 0;
  26. if (n1 != 0)
  27. {
  28. if (n1 % 10 % 2 != 0)
  29. {
  30. return 1 + same_num_odd_digits(n1/10,n2);
  31. }
  32. else
  33. same_num_odd_digits(n1/10,n2);
  34. }
  35. if (n2 != 0)
  36. {
  37. if (n2 % 10 % 2 != 0)
  38. {
  39. return -1 + same_num_odd_digits(n1,n2/10);
  40. }
  41. else
  42. same_num_odd_digits(n1,n2/10);
  43. }
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement