33 lines
648 B
C
33 lines
648 B
C
|
#include<stdio.h>
|
||
|
#include<stdlib.h>
|
||
|
|
||
|
int main(int argc, char * argv[]) {
|
||
|
printf("Veuillez donner un entier naturel : ");
|
||
|
int entier, result;
|
||
|
result = scanf("%d", &entier);
|
||
|
|
||
|
if (entier < 0) {
|
||
|
printf("L'entier doit être supérieur ou égal à 0.\n");
|
||
|
return EXIT_FAILURE;
|
||
|
}
|
||
|
|
||
|
if (result == 1) {
|
||
|
int remainder = entier % 3;
|
||
|
int triple;
|
||
|
if (remainder == 0) {
|
||
|
triple = entier;
|
||
|
} else if (remainder == 1) {
|
||
|
triple = entier - 1;
|
||
|
} else {
|
||
|
triple = entier + 1;
|
||
|
}
|
||
|
|
||
|
printf("Le multiple de trois le plus proche est %d.\n", triple);
|
||
|
} else {
|
||
|
printf("Format invalide.\n");
|
||
|
return EXIT_FAILURE;
|
||
|
}
|
||
|
return EXIT_SUCCESS;
|
||
|
}
|
||
|
|