#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char nombrechoisi, nombremystere, min, max, nombredejoueur, nouvellepartie;
srand(time(NULL));
while ( nouvellepartie != 2)
{
printf("Combien de joueurs?");
scanf("%d",&nombredejoueur);
if (nombredejoueur == 1)
{
printf("nombre entre? ");
scanf("%d",&min);
printf("et? ");
scanf("%d",&max);
nombremystere = (rand() % (max - min + 1)) + min;
}
else if (nombredejoueur == 2)
{
printf("choisissez un nombre\n");
scanf("%d",&nombremystere);
}
do
{
printf("%d", nombremystere);
printf("Quel est le nombre?");
scanf("%d",&nombrechoisi);
if (nombrechoisi < nombremystere)
{
printf("plus grand\n");
}
else if (nombrechoisi > nombremystere)
{
printf("plus petit\n");
}
} while(nombrechoisi != nombremystere);
printf("Voulez-vous refaire une partie?");
scanf("%d",&nouvellepartie);
}
return 0;
}
----------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int nombre, alea, max, min;
nombre = 0;
printf("l'ordinateur doit trouver le nombre:\n");
scanf("%d", &alea);
printf("l'ordinateur doit chercher %d entre:\n", alea);
scanf("%d", &min);
printf("et?");
scanf("%d", &max);
printf("\n\n\n\n");
while (nombre != alea)
{
printf("%d\n",nombre);
nombre = (min+max)/2;
if (nombre < alea)
{
min = nombre;
}
else if (nombre > alea)
{
max = nombre;
}
}
printf("nombre = %d", nombre);
}
----------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
int *multitableau(int tableau1[],int tableau2[],int taille)
{
int i=0,xy[taille];
while (i<taille)
{
xy[i]=tableau1[i]*tableau2[i];
i++;
}
return xy;
}
int *difference(int tableau[],int taille,int x)
{
int i=0;
while (i<taille)
{
tableau[i]=tableau[i]-x;
i++;
}
return tableau;
}
void affichetableau (int tableau[],int taille)
{
int i=0;
while(i<taille)
{
printf("%d\n",tableau[i]);
i++;
}
}
int total (int tableau[],int taille)
{
int i=0,x=0;
while(i<taille)
{
x=x+tableau[i];
i++;
}
return x;
}
int moyenne (int tableau[],int taille)
{
int i=0,moyx=0;
while(i<taille)
{
moyx=moyx+tableau[i];
i++;
}
return moyx/taille;
}
int main(int argc, char *argv[])
{
int taille,i=0;
printf("Combien d'annee a traiter?");
scanf("%d",&taille);
int annee[taille];
int chiffredaffaire[taille];
while (i<taille)
{
annee[i]=i+1;
i++;
}
i=0;
while ( i < taille)
{
printf ("CA no %d ",i+1);
scanf("%d",&chiffredaffaire[i]);
i++;
}
i=0;
affichetableau(annee,taille);
printf("x=%d\n",total(annee,taille));
printf("moyx=%d\n\n",moyenne(annee,taille));
affichetableau(chiffredaffaire,taille);
printf("y=%d\n",total(chiffredaffaire,taille));
printf("moyy=%d\n\n",moyenne(chiffredaffaire,taille));
int *X=difference(annee,taille,moyenne(annee,taille));
affichetableau(X,taille);
printf("X=%d\n",total(X,taille));
printf("moyX=%d\n\n",moyenne(X,taille));
int *Y=difference(chiffredaffaire,taille,moyenne(chiffredaffaire,taille));
affichetableau(Y,taille);
printf("Y=%d\n",total(Y,taille));
printf("moyY=%d\n\n",moyenne(Y,taille));
int *XY=multitableau(annee,chiffredaffaire,taille);
affichetableau(XY,taille);
system("PAUSE");
return 0;
}