Skip to content
Snippets Groups Projects
Commit 5b16ef47 authored by Alexandra Zaharia's avatar Alexandra Zaharia
Browse files

Ajouté exercices procedure_calling_procedure

parent f0c4afae
No related branches found
No related tags found
No related merge requests found
#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() {
int i;
vector<int> tab = {2, 4, 5, 8};
f(tab, 2, 3);
for (i = 0; i < tab.size(); i++)
cout << tab[i] << " ";
cout << endl;
return 0;
}
\ No newline at end of file
#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() {
int i;
vector<int> tab = {3, 1, 2, 6};
f(tab, 1, 3);
for (i = 0; i < tab.size(); i++)
cout << tab[i] << " ";
cout << endl;
return 0;
}
\ No newline at end of file
#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, bool &c, int &d) {
if (a == b || t[a] == t[b]) c = false;
else {
if (t[a] < t[b]) {
c = true;
d = g(t[b] - t[a]);
} else {
c = false;
d = g(t[a] - t[b]);
}
}
}
int main() {
int i;
vector<int> tab = {2, 4, 5, 8};
bool b;
int r = -1;
int x = 2;
int y = 3;
f(tab, x, y, b, r);
cout << tab[x] << (b ? " < " : " >= ") << tab[y] <<
", r = " << r << endl;
return 0;
}
\ No newline at end of file
#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, bool &c, int &d) {
if (a == b || t[a] == t[b]) c = false;
else {
if (t[a] < t[b]) {
c = true;
d = g(t[b] - t[a]);
} else {
c = false;
d = g(t[a] - t[b]);
}
}
}
int main() {
int i;
vector<int> tab = {3, 1, 2, 6};
bool b;
int r = -1;
int x = 0;
int y = 2;
f(tab, x, y, b, r);
cout << tab[x] << (b ? " < " : " >= ") << tab[y] <<
", r = " << r << endl;
return 0;
}
\ No newline at end of file
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