Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int loopnum(int n);
  5.  
  6. int
  7. main(void)
  8. {
  9. int num;
  10. int sum = 0;
  11. int d = loopnum(num);
  12.  
  13. printf("Enter a number:n");
  14. scanf("%d", &num);
  15.  
  16. while(loopnum(num) > 0)
  17. {
  18. printf("d = %d", d);
  19. printf(",sum = %dn",sum);
  20.  
  21. }
  22.  
  23.  
  24. if(num % 9 == 0)
  25. {
  26. printf("n = %d is divisible by 9n", num);
  27. }
  28. else
  29. {
  30. printf("n = %d is not divisible by 9n", num);
  31. }
  32. return 0;
  33. }
  34.  
  35. int
  36. loopnum(int n)
  37. {
  38.  
  39. n = n % 10;
  40. n = n / 10;
  41.  
  42. return n;
  43.  
  44. }
  45.  
  46.  
  47. Enter a number:
  48. 9
  49. n = 9 is divisible by 9
  50.  
  51. The result of this code is suppose to output d = "the digit" ,sum =
  52. "digit + sum" and n = "digit" is divisible by 9. for example if I
  53. input 9. The output would be d = 9, sum = 9.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement