# 121a - TP1 29-01-21
#
```cpp
// exo 1
//Pierre
bool estDiviseur(int a, int b){
return a % b == 0;
};
// pourquoi not au lieu de ==0 ?
// exo1.2
bool estPremier(int a){
for ( int i = 2 ; i < a ; i++ ) {
if ( estDiviseur(a, i) == true ) {
return false ;
}
}
return true ;
}
//
bool estPremier(int n){
for(int i=0;i<=n;i++){
if(estDiviseur(n,i)==true and (i!=1 or i!=n)){
return false;
}
}
return true;
}
bool estPremier(int a){
for(int i = 2; i < a; i++){
if(estDiviseur(a,i)){
return false;
}
}
return true;
}
void premiersBornes(int n) {
for ( int i = 2 ; i <= n ; i++){
if (estPremier(i)==true){
cout << i << endl ;
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////'/'
int main(){
cout<< "qu'elle est votre entier n ?" << endl;
cin >> n;
premiersBornes(n);
}
// exo1.6
void premiersPremiers(int n){
int compteur = 0 ;
int i = 2 ;
while (compteur < n){
if (estPremier(i)==true){
cout << i << endl ;
compteur++ ;
}
i++;
}
}
//exo 1.7
int main(){
int n ;
cout << " valeur de n : " ;
cin >> n ;
premiersPremiers(n) ;
}
// -------------------
// exo 2
void lectureVB (float min, float max){
float a;
cout<<"entrer une valeur a comprise entre "<< min<< " et "<<max<< endl;
cin>>a;
while(a<=max & a>= min){
cout<<"entrer une valeur a comprise entre "<< min<< " et "<<max<< endl;
cin>>a;
}
}
int main(){
lecturevb(0,23);
return 0;
}
float lectureVB(float a,float b){
float n;
if(a>b){
float c = a;
a = b;
b = c;
}
cout << "Entrer un réel :" << endl;
do{
cout << "Il doit etre compris entre "<< a << " et " << b << endl;
cin >> n;
if(n < a or n > b){
cout << "Valeur incorrect." << endl;
}
}while(n < a or n > b);
return n;
}
float lectureVB(float a, float b){
float c ;
do{
cout << " Entrez une valeur entre " << a << " et "<< b<< " : " << endl ;
cin >> c ;
if ( c < a or c > b ){
cout << "erreur" << endl ;
}
}while ( c < a or c > b );
return c ;
}
// exo 3
double factorielle(int n){
double res = 1;
if(n<0){
cout << "Valeur incorrect"<< endl;
return 0;
}
for(int i = 1, i <= n, i++){
res = res * i;
}
return res;
}
double puissance(double a, int n){
double res = 1;
if(n<0){
cout << "Valeur incorrect"<< endl;
return 0;
}
for(int i = 0, i < n, i++){
res = res * a;
}
return res;
}
double puissance(double n, int x){
double p = 1 ;
for ( int i = 1 ; i <= x ; i++ ){
p = p * n ;
}
return p ;
}
double calcul(int a, int b, double x){
double res = 0.;
for ( int i = a ; i <= b ; i++ ){
res += puissance(x,i) / factorielle(i);
}
return res;
}
float sum_opti(int a, int b, float x)
{
float pui_x;
int fac;
pui_x = puissance(x, a);
fac = fact(a);
float sum = pui_x / fac;
for (int i = a+1; i <= b; i++) {
pui_x *= x;
fac *= i;
sum += pui_x / (float)fac;
}
return sum;
}
double calcul(int a, int b, double x){
double res = 0.;
double fac = 1.;
double pui = 1.;
for ( int i = a ; i <= b ; i++ ){
pui = pui * a;
fac = fac * i;
res += pui / fac;
}
return res;
} je corrige
```