Skip to content
Snippets Groups Projects
Commit 037486ec authored by mathias.catala's avatar mathias.catala
Browse files

"updares"

parent 27e5a7ca
No related branches found
No related tags found
No related merge requests found
File moved
......@@ -2,7 +2,7 @@ import scala.io.StdIn._
object Main{
def main(args: Array[String]): Unit = {
var pincorrect = Array("a","b","c","d","e")
var pin=""
var pin= ""
var continuer = true
var montantinitial = 1200.0
......
File added
......@@ -17,5 +17,4 @@ int main(){
printf("\nvaleurs apres a :%d",a);
printf("\nvaleurs apres b :%d",b);
}
\ No newline at end of file
File added
......@@ -12,43 +12,41 @@ int get_max(int n, const int* tab) {
}
int **dilatation(int m, int n, const int** tab) {
int **res = (int**) malloc(m * sizeof(int*));
int **res = malloc(m * sizeof(int*));
for (int i = 0; i < m; i++) {
res[i] = (int*) malloc(n * sizeof(int));
res[i] = malloc(n * sizeof(int));
for (int j = 0; j < n; j++) {
int max[5];
int k = 0;
int k = 0; // Start k from 1
max[k] = tab[i][j];
k += 1;
if (i > 0) {
max[k++] = tab[i-1][j];
max[k++] = tab[i - 1][j]; // Use tab[i-1][j] for the top element
}
if (i < m-1) {
max[k++] = tab[i+1][j];
if (i < m - 1) {
max[k++] = tab[i + 1][j]; // Use tab[i+1][j] for the bottom element
}
if (j > 0) {
max[k++] = tab[i][j-1];
max[k++] = tab[i][j - 1]; // Use tab[i][j-1] for the left element
}
if (j < n-1) {
max[k++] = tab[i][j+1];
if (j < n - 1) {
max[k++] = tab[i][j + 1]; // Use tab[i][j+1] for the right element
}
res[i][j] = get_max(k, max);
}
}
return res;
return res; // Do not free(res) here
}
void print_tab(int m, int n, const int** tab) {
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++)
{
int debug = tab[i][j];
for (int j = 0; j < n; j++) {
printf("%d ", tab[i][j]);
}
printf("\n");
......@@ -57,22 +55,18 @@ void print_tab(int m, int n, const int** tab) {
}
int **init_array(int m, int n) {
int **res = (int**) malloc(m * sizeof(int*));
int **res = malloc(m * sizeof(int*));
int k = 1;
for (int i = 0; i < m; i++)
{
res[i] = (int*) malloc(n * sizeof(int));
for (int j = 0; j < n; j++)
{
for (int i = 0; i < m; i++) {
res[i] = malloc(n * sizeof(int));
for (int j = 0; j < n; j++) {
res[i][j] = k++;
}
}
return res;
return res; // Do not free(res) here
}
int main() {
int m = 5, n = 5;
int **tab = init_array(m, n);
......@@ -80,5 +74,15 @@ int main() {
int** res = dilatation(m, n, (const int **)tab);
print_tab(m, n, (const int**) res);
print_tab(m, n, (const int**)res);
// Free memory
for (int i = 0; i < m; i++) {
free(tab[i]);
free(res[i]);
}
free(tab);
free(res);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment