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
| #include "stdio.h"
#include "stdlib.h"
float moyenne(short int *t, short int taille);
short int somme(short int *t,short int taille);
void plusPetit (short int *t, short int taille);
void plusGrand (short int *t, short int taille);
main()
{ int i=1;
short int taille=20;
short int t[20]={12,52,32,56,89,1,12,85,9,15,63,48,32,12,85,65,52,87,90,20};
while (i!=7){
printf("\n1. Affichage de la moyenne");
printf("\n2. Affichage de la somme");
printf("\n3. Affichage du plus petit nombre et de sa position");
printf("\n4. Affichage du plus grand nombre et de sa position");
printf("\n5. Affichage du nombre de doublons");
printf("\n6. Affichage de doublons une seule fois");
printf("\n7. Quitter");
printf("\n");
scanf("%d",&i);
getc(stdin);
switch(i)
{
case 1 : {printf("\nMoyenne = %3.3f",moyenne(t,taille)); break;}
case 2 : {printf("\nSomme = %d",somme(t,taille)); break;};
case 3: {plusPetit(t, taille); break;}
case 5: {NBdoublons(t,taille); break;}
case 5: {doublons(t,taille); break;}
case 7 : { getc(stdin); exit(1); break;}
default:;
}
getc(stdin);
}
return 0;
}
short int somme(short int *t, short int taille)
{int i;
short int s=0;
for(i=0;i<taille;i++) s+=t[i];
return(s);
}
float moyenne(short int *t,short int taille)
{ return((float)somme(t,taille)/(float)taille); }
void plusPetit (short int*t, short int taille)
{
int i, pos=0, plusPetit=999;
for(i=0; i<taille; i++)
{
if(t[i]<plusPetit)
{
plusPetit=t[i];
pos=i;
}
}
printf("Le plus petit = %d et a la position: %d", plusPetit, pos+1);
}
void plusGrand (short int*t, short int taille)
{
int i, pos=0, plusGrand=-999;
for(i=0; i<taille; i++)
{
if(t[i]>plusGrand)
{
plusGrand=t[i];
pos=i;
}
}
printf("Le plus Grand nombre = %d et a la position: %d", plusGrand, pos+1);
}
} |
Partager