Advertisement
dancidenis

lab6p2

Nov 9th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. unsigned selectdigit(unsigned n)
  4. {
  5. if(n==0)
  6. return 0;
  7. else if(n%10>=5)
  8. return n%10+selectdigit(n/10)*10;
  9. else
  10. selectdigit(n/10);
  11. }
  12.  
  13. unsigned selectdigit1(unsigned n, unsigned pos)
  14. {
  15. if(n==0)
  16. return 0;
  17. else if(pos%2==0)
  18. return n%10+selectdigit1(n/10, pos+1)*10;
  19. else
  20. selectdigit1(n/10, pos+1);
  21. }
  22.  
  23. int main()
  24. {
  25. printf("%d \n", selectdigit(2156));
  26. printf("%d", selectdigit1(3156, 0));
  27.  
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement