Révisions

This commit is contained in:
2022-01-25 12:00:33 +01:00
parent c30ba3ccdf
commit 64944874bc
14 changed files with 492 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#include <stdio.h>
#include <stdlib.h>
unsigned long int factorielle(unsigned long int n) {
if (n > 1) {
return n * factorielle(n-1);
} else return 1UL;
}
int main(int argc, char *argv[]) {
unsigned long int l;
int n = 1;
printf("%d\n", sizeof(l));
while (factorielle(n+1) >= factorielle(n)) n++;
l = factorielle(n);
printf("valeur de n = %d, valeur de %d! = %lu\n", n, n, l);
return EXIT_SUCCESS;
}

View File

@@ -0,0 +1,34 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
if (argc < 2) {
puts("Veuillez préciser une expression arithmétique...");
return EXIT_FAILURE;
}
char* result = (char*)calloc(strlen(argv[1])+1, sizeof(char));
int length = 0, nb_ouvrante = 0, nb_fermante = 0;
for (int i = 0; i < strlen(argv[1]); i++) {
if (argv[1][i] == '(' || argv[1][i] == ')') {
result[length] = argv[1][i];
length++;
if (argv[1][i] == '(') nb_ouvrante++;
else nb_fermante++;
}
}
int equite = 0;
for (int i = 0; i < strlen(result); i++) {
if (result[i] == '(') equite++;
else equite--;
if (equite < 0) break;
}
printf("%s %s %s\n", result, nb_ouvrante == nb_fermante ? "OK" : "NOK", equite == 0 ? "valide" : "non valide");
return EXIT_SUCCESS;
}

17
Révisions/CM/taille.c Normal file
View File

@@ -0,0 +1,17 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
struct stat buffer;
if (argc < 2) {
puts("Veuillez préciser un fichier.");
return EXIT_FAILURE;
}
stat(argv[1], &buffer);
printf("La taille de %s est de %d octets.\n", argv[1], buffer.st_size);
return EXIT_SUCCESS;
}