// cours du 14/12/2002 : strucures repetitives / selection simple
#include "stdio.h"
void exercice_1()
{
int tab[10];
int i;
float produit;
int somme;
printf("\n **EXERCICE 1 **:");
printf("\nboucle for pour charger le tableau:");
for (i=0;i<=9;i++)
{
printf("\n Element %i : ",(i+1));
scanf("%d",&tab[i]);
};
printf("\nboucle for :");
for (i=0;i<=9;i++)
{
printf("\n Element %i : %i",i,tab[i]);
};
printf("\nboucle while :");
i=0;
while (i<=9)
{
printf("\n Element %i : %i",i,tab[i]);
i++;
};
printf("\nboucle do :");
i=0;
do
{
printf("\n Element %i : %i",i,tab[i]);
i++;
}
while (i<=9);
printf("");
produit=1;
for (i=0;i<=9;i++)
{
printf("\n produit X tab i = %f %i",produit,tab[i]);
produit=produit *tab[i];
};
printf("\n produit = %f",produit);
printf("");
somme=0;
for (i=0;i<=9;i++)
{
somme=somme+tab[i];
};
printf("\n somme = %f",somme);
printf("\n moyenne = %f",(float)somme /10.0);
printf("");
};
void exercice_2()
{
int tab[12]= {10,11,12,13,14,15,16,17,18,19,20,21};
int i,min,max;
min=32568;
max=-32568;
printf("\n **EXERCICE 2 **:");
printf("\n:");
for (i=0;i<=11;i++)
{
if (tab[i]<min) {min=tab[i];};
if (tab[i]>max) {max=tab[i];};
};
printf("\nmin= %i - max= %i",min,max);
printf("");
};
void exercice_3()
{
int tab[12]= {-10,11,12,0,-14,15,16,0,18,19,20,-21};
int i,neg=0,nul=0,pos=0;
printf("\n **EXERCICE 3 **:");
printf("\n:");
for (i=0;i<=11;i++)
{
if (tab[i]<0) {neg++;};
if (tab[i]>0) {pos++;};
if (tab[i]==0) {nul++;};
};
printf("\nnegatif= %i - nul= %i - positif= %i",neg,nul,pos);
printf("");
};
void exercice_4()
{
int tab[8]= {10,11,12,13,14,15,16,17};
int tabsym[8];
int i,j=7;
printf("\n **EXERCICE 4 **:");
printf("\n:");
for (i=0;i<=7;i++)
{
tabsym[j]=tab[i];
j=j-1;
};
printf("\n tableau permuté");
for (i=0;i<=7;i++)
{
printf("\nelement %i avant:%i apres:%i",i,tab[i],tabsym[i]);
};
printf("\n");
};
void exercice_5()
{
int tab[8]= {11,10,12,14,13,15,17,16};
int tabtri[8];
int i,j=7;
printf("\n **EXERCICE 5 **:");
printf("\n:");
for (i=0;i<=7;i++)
{
tabtri[j]=tab[i];
j--;
};
printf("\n");
};
void main()
{ printf("debut du programme");
exercice_1();
exercice_2();
exercice_3();
exercice_4();
printf("fin du programme");
}