40 lines
731 B
C
40 lines
731 B
C
|
#include<stdio.h>
|
||
|
#include<stdlib.h>
|
||
|
|
||
|
int prime(int value) {
|
||
|
for (int diviseur = 2; diviseur < value; diviseur++) {
|
||
|
if (value == 1 ) {
|
||
|
return 0;
|
||
|
} else if (value % diviseur == 0 && diviseur != value) {
|
||
|
return 0;
|
||
|
} else if (value == 2) return 1;
|
||
|
}
|
||
|
|
||
|
return 1;
|
||
|
}
|
||
|
|
||
|
int main(int argc, char * argv[]) {
|
||
|
int value, remainder;
|
||
|
|
||
|
printf("Veuillez donner un entier naturel : ");
|
||
|
scanf("%d", &value);
|
||
|
remainder = value;
|
||
|
|
||
|
printf("%d = ", value);
|
||
|
|
||
|
while (!prime(remainder)) {
|
||
|
int factor;
|
||
|
|
||
|
for (int i = 2; i < remainder; i++) {
|
||
|
if (prime(i) && remainder % i == 0) {
|
||
|
factor = i;
|
||
|
remainder = remainder / factor;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
printf("%d*", factor);
|
||
|
}
|
||
|
printf("%d\n", remainder);
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|