summaryrefslogtreecommitdiff
path: root/sem_3/Programm/TP2/exo11/exo11.c
blob: e0567c2d5b742d1c903cf8637362c2f9a5141034 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <stdlib.h>
#include <stdio.h>

int puiss (int x, int y) {
  return ( y == 0 ? 1 : x * ( puiss(x, y-1)));
}

int main (int argc, char** argv) {
  int ordre =1; int cp = atoi(argv[1]); int bc = cp;
  while (cp / 10!= 0) {
    ordre ++;
    cp = cp /10;
  }
  printf("%d\n", ordre);
  cp = bc;
  char nbchar[ordre];
  for ( int i = 0; i < ordre; i ++) {
    nbchar[i] = cp / puiss(10, ordre -i-1) + 48;
    cp = cp % puiss(10,ordre-i -1);
  }
  printf("%s\n", nbchar);
  return 0;
}