1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| #include <stdio.h>
#include <stdlib.h>
typedef struct {
int q[100];
char no[100];
}nouveautype;
void maj_tab_cumul(nouveautype,int,char,int);
int main(void) {
nouveautype table;
int i,qte1=10, qte2=9 , qte3=11, qte4=1;
char nro1='C', nro2='B' , nro3='D' , nro4='A';
maj_tab_cumul(table,5,nro1,qte1);
maj_tab_cumul(table,5,nro2,qte2);
maj_tab_cumul(table,5,nro3,qte3);
maj_tab_cumul(table,5,nro4,qte4);
for(i=0; i<5; i++) {
printf("%c %d",table.no[i],table.q[i]);
printf("\n");
}
getchar();
return EXIT_SUCCESS;
}
void maj_tab_cumul(nouveautype table,int dim,char nro,int qte) {
int i=0,j;
while (i < dim && table.no[i] < nro) {
i = i + 1 ;
}
if(i >= dim || table.no[i] > nro) {
dim=dim+1;
j=dim-1;
while(j > i) {
table.q[j]=table.q[j-1];
table.no[j]=table.no[j-1];
j=j-1;
}
table.no[i]=nro;
table.q[i]=0;
}
table.q[i]=table.q[i] + qte;
} |
Partager