Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- unsigned selectdigit(unsigned n)
- {
- if(n==0)
- return 0;
- else if(n%10>=5)
- return n%10+selectdigit(n/10)*10;
- else
- selectdigit(n/10);
- }
- unsigned selectdigit1(unsigned n, unsigned pos)
- {
- if(n==0)
- return 0;
- else if(pos%2==0)
- return n%10+selectdigit1(n/10, pos+1)*10;
- else
- selectdigit1(n/10, pos+1);
- }
- int main()
- {
- printf("%d \n", selectdigit(2156));
- printf("%d", selectdigit1(3156, 0));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement