Untitled

 avatar
unknown
c_cpp
2 years ago
491 B
6
Indexable
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[]) {
  int value = 0;
  int reversed_value = 0;

  if (argc != 2) return 1;

  value = atoi(argv[1]);

  printf("%d ->\n", value);

  int digits = 1;
  while (pow(10, digits) < value) {
    digits++;
  }

  for (int e = 1; e <= digits ; e++) {
    int d = value % 10;
    value -= d;
    value /= 10;

    reversed_value += d * pow(10, digits - e);
  }

  printf("%d\n", reversed_value);

  return 0;
}
Editor is loading...