Langage de programmation1
COMPTE RENDU DU : TP N°5
Nom et prénom :
Mrad Ahdi
Classe :
GE1 S4
EXERCICE 1 :
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main ()
{int bol=1;
int c,k;
srand(time(0));
cout<<"attention vous avez au maximum 20 tentative pour trouver le nombre mustre "<<endl;
do
k= rand() % 501;
cout << "Entier aleatoire entre 0 et 500 : "<<endl;
for(int i=0;i<20 ; i++)
cout<<"entree " <<i+1<<" tentative"<<endl;
cin>>c;
if (c>k)
cout<<"moins"<<endl;
else if (c<k)
cout<<"plus"<<endl;
else
{cout<<"trouve.felicictation!vous avez trouve le nombre mystre "<<endl<<"vous avez besion
de "<<i+1<<" de tentative "<<endl ;
break; }
cout << "le nombre mystere est "<<k<<endl;
cout<<"tu veux jouez une autre fois "<<endl;
cin>>bol;
while (bol==1);
return 0;
}
Excution :
Exercice 2 -1 :
Excution 2-1:
Exercice 2 -2 :
Excution2-2 :
Exercice 3 :
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std ;
float moyenne_1 (int a, int b , int c )
float m1;
m1=(a+b+c)/3.0;
return m1 ;
float moyenne_2 (float a, float b , float c )
float m2;
m2=(a+b+c)/3.0;
return m2 ;
float moyenne_3(int a, int b )
float m3;
m3=(a+b)/2.0;
return m3 ;
int main ()
float a,b,c;
int x,y,z;
cout<< "saisir le reel a :"<<endl;
cin>>a;
cout<< "saisir le reel b :"<<endl;
cin>>b;
cout<< "saisir le reel c :"<<endl;
cin>>c;
cout<< "saisir l'entier x :"<<endl;
cin>>x;
cout<< "saisir l'entier y :"<<endl;
cin>>y;
cout<< "saisir l'entier z :"<<endl;
cin>>z;
cout<<"le moyenne 1 est: "<<moyenne_1(a,b,c)<<endl;
cout<<"le moyenne 2 est: "<<moyenne_2(x,y,z)<<endl;
cout<<"le moyenne 3 est: "<<moyenne_3(x,y)<<endl;
return 0;
Excution 3 :
Exercice 4 :
#include<iostream>
#include<cstdlib>
#include<cmath>
using namespace std;
float racine(float x, bool &test)
float r;
if (x >= 1 && x <= 5)
r = sqrt((x - 1) * (5 - x));
test = true;
else
test = false;
return r;
int main() {
float x;
bool test;
cout << "Entrez une valeur pour x : ";
cin >> x;
if (racine(x, test))
cout << "La racine carree est : " << racine(x, test) << endl;
else
cout << "Le resultat est incorrect." << endl;
return 0;
Excution 4 :