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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
| #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "ex10.h"
int main(int argc, char** argv) {
int tab[2][5];
srand(time(NULL));
init_tab(tab,2,5);
aff_tab(tab,2,5);
printf("\tLa somme: %d\n\tLe nombre des elements pos: %d\n\tLa somme des elements pos: %d , La somme des elements neg: %d\n\tLe max est: %d sa pos: tab[%d][%d]\n\tLe nombre d'occ:%d\n'",
som_tab(tab,2,5),pos_tab(tab,2,5),sp,sn,max_tab(tab,2,5),pos1,pos2,occ_tab(tab,2,5));
return 0;
}
void init_tab(const int *const A[nbl][nbc], int const nbl, int const nbc){
int i,j,som;
for(i=0,som=0;i<nbl;i++){
for(j=0;j<nbc;j++)
A[i][j]=rand()%2;
}
}
int aff_tab(const int *const A[nbl][nbc], int const nbl, int const nbc){
int i,j;
for(i=0;i<nbl;i++){
for(j=0;j<nbc;j++)
printf("\n\t |");
printf("%d",A[i][j]);
}
int som_tab(const* int const A[nbl][nbc], int const nbl,int const nbc){
int i,j,som;
for(i=0,som=0;i<nbl;i++){
for(j=0;j<nbc;j++)
som+=A[i][j];
}
return som;
}
int pos_tab(const* int const A[nbl][nbc], int const nbl,int const nbc){
int i,j,occ;
for(i=0,occ=0;i<nbl;i++){
for(j=0;j<nbc;j++){
if(A[i][j]>0)
occ++;
}
}
return occ;
}
int sompn_tab(const* int const A[nbl][nbc], int const nbl,int const nbc,int *sp,int *sn){
int i,j;
int *sp=0,*sn=0;
for(i=0;i<nbl;i++){
for(j=0;j<nbc;j++){
if(A[i][j]>0) (*sp)+=A[i][j];
else (*sn)+=A[i][j];
}
}
}
int max_tab(const* int const A[nbl][nbc], int const nbl,int const nbc){
int i,j;
int max=A[0][0];
for(i=0;i<nbl;i++){
for(j=0;j<nbc;j++){
if(A[i][j]>max)
max=A[i][j];
}
}
return max;
}
int pos_max(const* int const A[nbl][nbc], int const nbl,int const nbc, int *pos1, int *pos2){
int i,j;
int *pos1,*pos2;
for(i=0;i<nbl;i++){
for(j=0;j<nbc;j++){
if(A[i][j]>max_tab(A,nbl,nbc)){
*pos1=i;
*pos2=j;}
}
}
int occ_tab(const *int const A[nbl][nbc], int const nbl,int const nbc){
int i,j;
int comp=rand()%(nbl+1);
for(i=0,comp=0;i<nbl;i++){
for(j=0;j<nbc;j++){
if(A[i][j]==comp)
comp++;
}
}
return comp;
} |
Partager