Vous êtes sur la page 1sur 2

Université Sultan Moulay Slimane Département d’Informatique

FST – Beni Mellal Module : Alg & prog 2


Filière : MIPC+GE/GM S3

TP N°: 1
Solution de TP N°:1

Exercice 1 :
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
main()
{
float a,b,c,x,y,det;

printf("Entrer trois reels a!=0,b et c:\n ");


scanf("%f%f%f",&a,&b,&c);
det=pow(b,2)-4*a*c;
if(det<0) printf("Solution: pas de solution dans IR\n");
else
if(det==0){
x=-b/(2*a);
printf("Solution: %f\n",x);
}
else {
x=(-b-sqrt(det))/(2*a);
y=(-b+sqrt(det))/(2*a);
printf("Solution: %f et %f \n",x,y);
}
system("pause");
}
Exercice 2 :
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
main()
{
float A=1,B,a;

printf("Donner un reel positif");


scanf("%f",&a);
do{
B=A;
A=0.5*(B+a/B);
}while(fabs(A-B)>=0.001);
printf("Racine carree de %f est %f\n",a,A);
system("pause");
}

2018/2019
Université Sultan Moulay Slimane Département d’Informatique
FST – Beni Mellal Module : Alg & prog 2
Filière : MIPC+GE/GM S3

Exercice 3 :

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
main()
{
float eap=2,eav,p=2,fact=1;

do{
eav=eap;
fact=fact*p;
eap=eav+(1/fact);
p++;
}while(fabs(eap-eav)>=0.01 && p<100);
printf("Constante d Euler = %f\n",eap);
system("pause");
}

2018/2019

Vous aimerez peut-être aussi