Skip to content
Snippets Groups Projects
Commit 2e2b6c52 authored by Adrien Rougny's avatar Adrien Rougny
Browse files

maj progs procedure*

parent 33c41162
No related branches found
No related tags found
No related merge requests found
Showing
with 410 additions and 0 deletions
#include <iostream>
#include <vector>
using namespace std;
int g(int n) {
int i, r = 0;
for (i = 1; i <=n; i++)
r += i;
return r;
}
void f(vector<int> &t, int a, int b) {
int c;
if (a < t.size() && b < t.size()) {
c = g(t[a]);
t[a] = g(t[b]);
t[b] = c;
}
}
int main() {
vector<int> tab = {2, 4, 5, 8};
f(tab, 2, 3);
cout << tab[3] << endl;
return 0;
}
#include <iostream>
using namespace std;
void g(int i) {
i = i*2;
}
void f(int &i) {
i = i+3;
g(i);
}
int main() {
int i;
cin >> i;
f(i);
cout << i << endl;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int g(int n) {
int i, r = 0;
for (i = 1; i <=n; i++)
r += i;
return r;
}
void f(vector<int> &t, int a, int b) {
int c;
if (a < t.size() && b < t.size()) {
c = g(t[a]);
t[a] = g(t[b]);
t[b] = c;
}
}
int main() {
vector<int> tab = {3, 1, 2, 6};
f(tab, 1, 3);
cout << tab[1] << endl;
return 0;
}
#include <iostream>
using namespace std;
void g(int &i, int j) {
i = i+j;
}
void f(int i, int &j) {
i = i+3;
g(i, j);
}
int main() {
int i;
int j;
cin >> i;
j = i+5;
f(i, j);
cout << i << endl;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int g(int n) {
return (n + 1) * (n - 1);
}
void f(vector<int> t, int a, int b, int &c) {
if (t[a] < t[b]) c = g(t[b] - t[a]);
else c = g(t[a] - t[b]);
}
int main() {
vector<int> tab = {2, 4, 5, 8};
int r = -1;
int x = 2;
int y = 3;
f(tab, x, y, r);
cout << r << endl;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
int g(int n) {
return (n + 1) * (n - 1);
}
void f(vector<int> t, int a, int b, int &c) {
if (t[a] < t[b]) c = g(t[b] - t[a]);
else c = g(t[a] - t[b]);
}
int main() {
vector<int> tab = {3, 1, 2, 6};
int r = -1;
int x = 0;
int y = 2;
f(tab, x, y, r);
cout << r << endl;
return 0;
}
#include <iostream>
#include <vector>
using namespace std;
void blourg(vector<int> t, int v, int i, bool &b) {
i=-1;
b=false;
for( int j=0; j<t.size();j++) {
if(t[j] == v) {
i=j;
b=true;
}
}
}
int main() {
bool toto;
vector<int> tab = {4, 10, 13, 7, 5, 6};
int s = 0;
blourg(tab,2,s,toto);
if(toto) cout << s << endl;
else cout << "blourg" << endl;
}
#include <iostream>
#include <vector>
using namespace std;
void blourg(vector<int> t, int v, int &i, bool &b) {
i=-1;b=false;
for( int j=0; j<t.size();j++)
if(t[j] == v)
{i=j; b=true;}
}
int main() {bool toto;
vector<int> tab = {4, 10, 13, 7, 5, 6};
int s = 0;
blourg(tab,5,s,toto);
if(toto) cout << s << endl;
else cout << "blourg" << endl;
}
#include <iostream>
#include <vector>
using namespace std;
void blourg(vector<int> t, int v, int i, bool &b) {
i=-1;b=false;
for( int j=0; j<t.size();j++)
if(t[j] == v)
{i=j; b=true;}
}
int main() {bool toto;
vector<int> tab = {4, 10, 13, 7, 5, 6};
int s = 0;
blourg(tab,5,s,toto);
if(toto) cout << s << endl;
else cout << "blourg" << endl;
}
#include <iostream>
#include <vector>
using namespace std;
void blourg(vector<int> t, int v, int &i, bool &b) {
i=-1;b=false;
for( int j=0; j<t.size();j++)
if(t[j] == v)
{i=j; b=true;}
}
int main() {bool toto;
vector<int> tab = {4, 10, 13, 7, 5, 6};
int s = 0;
blourg(tab,5,s,toto);
if(toto) cout << s << endl;
else cout << "blourg" << endl;
}
#include <iostream>
using namespace std;
void Pascal(int &acc, int n) {
acc = 0;
for (int i = n; i > 0; i--)
acc += i;
}
int main() {
int somme;
Pascal(somme, 8);
cout << "La somme est de : " << somme << endl;
return 0;
}
#include <iostream>
#include <math.h>
using namespace std;
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;
}
int main() {
if (foo(21))
cout << "Oui" << endl;
else
cout << "Non" << endl;
return 0;
}
#include <iostream>
using namespace std;
void Blaise(int &acc, int n) {
acc = n * (n+1) / 2;
}
int main() {
int prod;
Blaise(prod, 8);
cout << "Le produit retourne : " << prod << endl;
return 0;
}
#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;
}
//============================================================================
// Name : testCpp.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
void decrement(int n) {
n=n-1;
}
int main() {
int a = 5;
decrement(a);
cout << a << endl;
}
//============================================================================
// Name : testCpp.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
void increment(int n) {
n=n+1;
}
int main() {
int a = 5;
increment(a);
cout << a << endl;
}
//============================================================================
// Name :
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
void decrement(int &n) {
n=n-1;
}
int main() {
int a = 5;
decrement(a);
cout << a << endl;
}
//============================================================================
// Name :
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
using namespace std;
void increment(int &n) {
n=n+1;
}
int main() {
int a = 5;
increment(a);
cout << a << endl;
}
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