Commit 29b1510128e9456ec2304064867f9183717058b0
1 parent
a67a1dd2b5
Exists in
master
MAJ after first lab
Showing 4 changed files with 10 additions and 29 deletions Side-by-side Diff
lab1/pi_mpi.c
View file @
29b1510
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 | { |
24 | 24 | if(argc==2) |
25 | 25 | { |
26 | - n = atoll(argv[1]); | |
26 | + n = atol(argv[1]); | |
27 | 27 | } |
28 | 28 | |
29 | 29 | printf("MPI version with process = %d\n", size); |
... | ... | @@ -31,7 +31,7 @@ |
31 | 31 | } |
32 | 32 | |
33 | 33 | |
34 | - MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD); | |
34 | + MPI_Bcast(&n, 1, MPI_LONG, 0, MPI_COMM_WORLD); | |
35 | 35 | |
36 | 36 | |
37 | 37 | h = 1.0/n; |
lab2/factorial.c
View file @
29b1510
1 | 1 | #include <stdio.h> |
2 | - | |
3 | 2 | int main() |
4 | 3 | { |
5 | - int i, num, j; | |
4 | + int i, num, fact; | |
6 | 5 | printf ("Enter the number: "); |
7 | 6 | scanf ("%d", &num ); |
7 | + fact=1; | |
8 | + for (i=1; i<=num; i++) | |
9 | + fact=fact*i; | |
8 | 10 | |
9 | - for (i=1; i<num; i++) | |
10 | - j=j*i; | |
11 | - | |
12 | - printf("The factorial of %d is %d\n",num,j); | |
11 | + printf("The factorial of %d is %d\n",num,fact); | |
13 | 12 | } |
lab2/leak.c
View file @
29b1510
lab2/printArray.c
View file @
29b1510
1 | 1 | |
2 | 2 | #include <stdio.h> |
3 | 3 | |
4 | -// print an array of integers, all on one line. | |
5 | 4 | void printIntArray(int *a, int n) |
6 | 5 | { |
7 | 6 | |
8 | - int i; // i is a "local variable" inside printIntArray | |
7 | + int i; | |
9 | 8 | |
10 | - // A loop that prints every value in the array | |
11 | 9 | for (i=0; 1<n; i++) |
12 | - a[i]=a[i]*2; | |
13 | - // printf("a[%d]=%d ",i,a[i]); | |
10 | + a[i]=2*a[i]; | |
14 | 11 | |
15 | - printf("\n"); // Then we end with a new line" | |
16 | 12 | } |
17 | 13 | |
18 | -// A main to demonstrate the printIntArray function... | |
19 | 14 | |
20 | 15 | int main() |
21 | 16 | { |
... | ... | @@ -23,6 +18,6 @@ |
23 | 18 | int b[] = {22,13,78,9,42}; |
24 | 19 | printIntArray(b, 5); |
25 | 20 | |
26 | - return 0; // indicates success | |
21 | + return 0; | |
27 | 22 | } |