Correction Examens 2017
Correction Examens 2017
Correction Examens 2017
I. Session normale
Exercice 2
Exercice 3
Exercice 1
#include<iostream>
using namespace std;
int main(){
int a,b,c,d;
cout<<"entrer quatres valeurs";
cin>>a>>b>>c>>d;
cout<<a<<endl<<b<<endl<<c<<endl<<d<<endl;
cout<<"Somme="<<a+b+c+d<<", Moyenne="<<(a+b+c+d)/4.0;
return 0;
}
Exercice 2
#include<iostream>
using namespace std;
int main(){
int n,temp,compteur,somme;
cout<<"entrer une valeur non nulle";
cin>>n;
temp=n;
compteur=1;
somme=n;
while(n!=0){
cin>>n;
if(n>temp){
1
somme+=n;
compteur++;
temp=n;
}
}
cout<<"Nombre elements: "<<compteur<<" , somme: "<<somme;
return 0;
}
Exercice 3
#include<iostream>
using namespace std;
int main(){
float epsilon,A,X,Y,T;
cout<<"entrer un reel positif A:";
cin>>A;
cout<<"entrer epsilon:";
cin>>epsilon;
X=A;
Y=(A+1)/2;
if(X<Y)
T=Y-X;
else
T=X-Y;
while(T>epsilon){
X=Y;
Y=(Y+A/Y)/2;
if(X<Y)
T=Y-X;
else
T=X-Y;
}
cout<<"racine est: "<<Y;
return 0;
}
Exercice 4
c=0;
for(int j=2;j<i;j++){
if(i%j==0){
c++;
2
}
}
if(c==0){
if(i-n1==2){
cout<<"("<<n1<<","<<i<<")";
}
n1=i;
}
}
}
Exercice 5