From 29b1510128e9456ec2304064867f9183717058b0 Mon Sep 17 00:00:00 2001 From: kmazouzi Date: Fri, 1 Apr 2016 09:43:53 +0200 Subject: [PATCH] MAJ after first lab --- lab1/pi_mpi.c | 4 ++-- lab2/factorial.c | 11 +++++------ lab2/leak.c | 13 ------------- lab2/printArray.c | 11 +++-------- 4 files changed, 10 insertions(+), 29 deletions(-) delete mode 100644 lab2/leak.c diff --git a/lab1/pi_mpi.c b/lab1/pi_mpi.c index 442258e..2f2be47 100644 --- a/lab1/pi_mpi.c +++ b/lab1/pi_mpi.c @@ -23,7 +23,7 @@ int main (int argc, char** argv) { if(argc==2) { - n = atoll(argv[1]); + n = atol(argv[1]); } printf("MPI version with process = %d\n", size); @@ -31,7 +31,7 @@ int main (int argc, char** argv) } - MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Bcast(&n, 1, MPI_LONG, 0, MPI_COMM_WORLD); h = 1.0/n; diff --git a/lab2/factorial.c b/lab2/factorial.c index 3cf7143..d56217d 100644 --- a/lab2/factorial.c +++ b/lab2/factorial.c @@ -1,13 +1,12 @@ #include - int main() { - int i, num, j; + int i, num, fact; printf ("Enter the number: "); scanf ("%d", &num ); + fact=1; + for (i=1; i<=num; i++) + fact=fact*i; - for (i=1; i -#include -void f(void) -{ - int* x = (int*)malloc(10 * sizeof(int)); - x[9] = 2; -} // problem: memory leak -- x not freed -int main(int argc, char * argv[]) -{ - f(); - printf("GOOD END \n"); - return 0; -} diff --git a/lab2/printArray.c b/lab2/printArray.c index 9aa121f..9e9f9c8 100644 --- a/lab2/printArray.c +++ b/lab2/printArray.c @@ -1,21 +1,16 @@ #include -// print an array of integers, all on one line. void printIntArray(int *a, int n) { - int i; // i is a "local variable" inside printIntArray + int i; - // A loop that prints every value in the array for (i=0; 1