Compare View

switch
from
...
to
 
Commits (2)

Diff

Showing 6 changed files Side-by-side Diff

lab1/pi_mpi.c View file @ c7c188d
... ... @@ -23,7 +23,7 @@ int main (int argc, char** argv)
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 @@ int main (int argc, char** argv)
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 @ c7c188d
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/memory_access.c View file @ c7c188d
... ... @@ -0,0 +1,19 @@
  1 +
  2 +#include <stdlib.h>
  3 +#include <stdio.h>
  4 +#define DIM 100
  5 +int main(int argc, char *argv[])
  6 +{
  7 + //float *a;
  8 + int i;
  9 + float a[DIM];
  10 +// a = (float *) malloc( sizeof(float) * DIM );
  11 + for( i = 0; i < DIM; ++i) a[i] = 0.0;
  12 + // sup = k;
  13 + // k = a[i];
  14 + a[200] = 99.0;
  15 + printf("GOOD END \n");
  16 +// free(a);
  17 + return(EXIT_SUCCESS);
  18 +}
  19 +
lab2/memory_leak.c View file @ c7c188d
... ... @@ -0,0 +1,13 @@
  1 +#include <stdlib.h>
  2 +#include <stdio.h>
  3 +void f(void)
  4 +{
  5 + int* x = (int*)malloc(10 * sizeof(int));
  6 + x[9] = 2;
  7 +} // problem: memory leak -- x not freed
  8 +int main(int argc, char * argv[])
  9 +{
  10 + f();
  11 + printf("GOOD END \n");
  12 + return 0;
  13 +}
lab2/printArray.c View file @ c7c188d
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,5 +18,5 @@ int main()
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 }