Skip to content
Snippets Groups Projects
Commit afdf3e41 authored by Jean-Baptiste Priez's avatar Jean-Baptiste Priez
Browse files

JB: push and modify procedure math

parent 915367d9
No related branches found
No related tags found
No related merge requests found
......@@ -2,15 +2,18 @@
using namespace std;
void Blaise(int &acc, int n) {
acc = n * (n+1) / 2;
void Pascal(int &acc, int n) {
acc = 0;
for (int i = n; i > 0; i--)
acc += i;
return acc;
}
int main() {
int somme = 0;
Blaise(somme, 8);
cout << "Blaise dit que la somme est de : " << somme << endl;
int somme;
Pascal(somme, 8);
cout << "La somme est de : " << somme << endl;
return 0;
}
......@@ -4,22 +4,19 @@
using namespace std;
bool premier(int n) {
bool foo(int n) {
if (n % 2 == 0) return true;
for (int d = 3; floor(sqrt(n)+1); d=d+2)
if (n % d == 0)
return false;
return true;
for (int d = 3; floor(sqrt(n)+1); d=d+2)
if (n % d == 0)
return false;
return true;
}
int main() {
if (premier(21))
cout << "Prim" << endl;
if (foo(21))
cout << "Oui" << endl;
else
cout << "Pas Prim" << endl;
cout << "Non" << endl;
return 0;
}
......@@ -7,10 +7,10 @@ void Blaise(int &acc, int n) {
}
int main() {
int somme = 0;
int prod;
Blaise(somme, 8);
cout << "Blaise dit que la somme est de : " << somme << endl;
Blaise(prod, 8);
cout << "Le produit retourne : " << prod << endl;
return 0;
}
\ No newline at end of file
}
#include <iostream>
#include <math.h>
using namespace std;
bool foo(int n, int j) {
if (j == floor(sqrt(n) + 1))
return true;
else if (n % j == 0)
return false;
else
return foo(n, j+1);
}
int main() {
if (foo(13, 2))
cout << "Oui" << endl;
else
cout << "Non" << endl;
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment