- #include <stdio.h>
- #include <conio.h>
-
- // la taille d'un tableau
- #define SIZE_TAB(tab) (sizeof((tab))/sizeof(((tab)[0])))
- // affiche un tableau
- void PrintTab(int *tab,int nbElem)
- {
- printf("{%d",*tab);
- while(--nbElem)
- printf(",%d",*(++tab));
- printf("}");
- }
- // le minimun d'un tableau
- int MinTab(int *tab,int nbElem)
- {
- int curMin = *tab;
- while(--nbElem)
- if(*(++tab) < curMin)
- curMin = *tab;
- return curMin;
- }
- // le maximun d'un tableau
- int MaxTab(int *tab,int nbElem)
- {
- int curMax = *tab;
- while(--nbElem)
- if(*(++tab) > curMax)
- curMax = *tab;
- return curMax;
- }
- // fait la somme de tous les elements
- int SumTab(int *tab,int nbElem)
- {
- int s = *tab;
- while(--nbElem)
- s += *(++tab);
- return s;
- }
- // ============== MAIN ==============
- int main(int argc,char **argv)
- {
- int tab[] = {1,9,-5,54,-100};
- int size;
- int min,max,sum;
-
- // initialisation :
- size = SIZE_TAB(tab);
- // calculs :
- min = MinTab(tab,size);
- max = MaxTab(tab,size);
- sum = SumTab(tab,size);
- // affichage :
- printf("Voici un tableau : ");
- PrintTab(tab,size); // on affiche le tableau
- printf("\n"); // on saute une ligne
- printf("Son minimum est %4d.\n",min);
- printf("Son maximun est %4d.\n",max);
- printf("Sa somme est %4d.\n",sum);
- // on attend la frappe d'une touche :
- getch();
- return 0;
- }
#include <stdio.h>
#include <conio.h>
// la taille d'un tableau
#define SIZE_TAB(tab) (sizeof((tab))/sizeof(((tab)[0])))
// affiche un tableau
void PrintTab(int *tab,int nbElem)
{
printf("{%d",*tab);
while(--nbElem)
printf(",%d",*(++tab));
printf("}");
}
// le minimun d'un tableau
int MinTab(int *tab,int nbElem)
{
int curMin = *tab;
while(--nbElem)
if(*(++tab) < curMin)
curMin = *tab;
return curMin;
}
// le maximun d'un tableau
int MaxTab(int *tab,int nbElem)
{
int curMax = *tab;
while(--nbElem)
if(*(++tab) > curMax)
curMax = *tab;
return curMax;
}
// fait la somme de tous les elements
int SumTab(int *tab,int nbElem)
{
int s = *tab;
while(--nbElem)
s += *(++tab);
return s;
}
// ============== MAIN ==============
int main(int argc,char **argv)
{
int tab[] = {1,9,-5,54,-100};
int size;
int min,max,sum;
// initialisation :
size = SIZE_TAB(tab);
// calculs :
min = MinTab(tab,size);
max = MaxTab(tab,size);
sum = SumTab(tab,size);
// affichage :
printf("Voici un tableau : ");
PrintTab(tab,size); // on affiche le tableau
printf("\n"); // on saute une ligne
printf("Son minimum est %4d.\n",min);
printf("Son maximun est %4d.\n",max);
printf("Sa somme est %4d.\n",sum);
// on attend la frappe d'une touche :
getch();
return 0;
}