15 Novembre

This commit is contained in:
Adrian POURCHOT 2022-11-15 11:20:58 +01:00
parent b2789803aa
commit 2fe948b2ab
5 changed files with 129 additions and 0 deletions

View File

@ -0,0 +1,47 @@
/* fichier debogueur1.c : exemple a deboguer */
#include <stdio.h>
#include <stdlib.h>
/* fonction principale */
int main(void) {
int i=-1, j=0, n, k, mem[100];
/* invite */
printf("Calcul de C(n, k) :\n");
/* saisie de n */
printf("Entrez n : ");
scanf("%d", &n);
while((n>100)||(n<1)) {
printf("n doit être compris entre 1 et 100 !\n");
printf("Entrez n : ");
scanf("%d", &n);
}
/* saisie de k */
printf("Entrez k : ");
scanf("%d", &k);
while((k>n)||(k<1)) {
printf("k doit être compris entre 1 et %d !\n", n);
printf("Entrez k : ");
scanf("%d", &k);
}
/* calculs... */
while (i<n) {
if(j<1) {
*(mem+(j=i++)+1) = 1;
} else {
*(mem+j--) += *(mem+j);
}
}
/* affichage du resultat */
printf("C(%d, %d) = %d\n", n, k, mem[k-1]);
return EXIT_SUCCESS;
}
/* fin du fichier debogueur1.c */

View File

@ -0,0 +1,17 @@
int main(void) {
int a = 1, b = 2, c = 3;
int *p, *q;
p=&a;
q=&c;
*p=(*q)++;
p=q;
q=&b;
*p-=*q;
++*q;
*p*=*q;
a=++*q**p;
p=&a;
*q=*p/(*q);
return 0;
}

View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
int i;
int j;
int k;
int tab[10];
srand(time(NULL));
for (i=0;i<10;i++){
tab[i]=((rand()%101)-50);
} printf("+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+\n");
for (i=0;i<10;i++){
printf("| %3d ",tab[i]);
} printf("|\n+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+\n");
printf("Voici le tableaux inverse:\n+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+\n");
i=9;
for(j=0;j<5;j++){
k=tab[j];
tab[j]=tab[i];
tab[i]=k;
i--;
}
for (i=0;i<10;i++){
printf("| %3d ",tab[i]);
} printf("|\n+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+\n");
return 0;
}

View File

@ -0,0 +1,16 @@
#include <stdlib.h>
#include <stdio.h>
int somme(int n, int m) {
return n+m;
}
int main(void) {
int valeur;
int* p = calloc(1,4);
printf("Entrez un entier : ");
scanf("%d", p);
printf("Le double vaut %d\n", somme(*p, *p));
return EXIT_SUCCESS;
}

View File

@ -0,0 +1,20 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
void envers(const char texte[]) {
int position;
for(position = strlen(texte)-1; position >= 0; position--) {
printf("%c", texte[position]);
}
printf("\n");
}
int main(int argc, char** argv) {
if (argc < 2) {
printf("usage : %s <texte>\n", argv[0]);
return EXIT_FAILURE;
}
envers(argv[1]);
return EXIT_SUCCESS;
}