Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int prevrti(int broj, int power) {
- if(broj == 0) {
- return 0;
- }
- return ((broj % 10) * power) + prevrti(broj / 10, power / 10);
- // 3 * 100 + prevrti(12) = 321
- // 2 * 10 + prevrti(1) = 21
- // 1 * 1 + prevrti(0)
- }
- int kolku_cifri(int broj) {
- if(broj == 0) {
- return 0;
- }
- return kolku_cifri(broj / 10) + 1;
- }
- int power(int i) {
- if(i == 0) {
- return 1;
- }
- return power(i - 1) * 10;
- }
- int main() {
- int N;
- scanf("%d", &N);
- int P = power(kolku_cifri(N) - 1);
- printf("%d\n", prevrti(N, P));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement