Advertisement
Guest User

Untitled

a guest
Feb 13th, 2013
519
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.75 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stddef.h>
  4. #include <stdalign.h>
  5.  
  6. struct Chunk {
  7.     float *speeds;
  8. };
  9.  
  10. #define N 1024
  11. #define M 512
  12.  
  13. int main(void)
  14. {
  15.     int jj, kk;
  16.     int nx;
  17.     static struct Chunk c[N];
  18.     float partial;
  19.     float out[N];
  20.     float *fp;
  21.    
  22.     for (jj = 0; jj < N; jj++) {
  23.         c[jj].speeds = malloc(M * sizeof(float));
  24.         for (kk = 0; kk < M; kk++) {
  25.             if (scanf("%f", &(c[jj].speeds[kk])) < 1)
  26.                 return -1;
  27.         }
  28.     }
  29.    
  30.     if (scanf("%d", &nx) < 1)
  31.         return -1;
  32.  
  33.     for (jj = 0; jj < nx; jj++) {
  34.         partial = 0.0f;
  35.         fp = c[jj].speeds;
  36.         for (kk = 0; kk < M; kk++)
  37.             partial += fp[kk];
  38.         out[jj] = partial;
  39.     }  
  40.  
  41.     for (jj = 0; jj < N; jj++) {
  42.         printf("%g\n", out[jj]);
  43.         free(c[jj].speeds);
  44.     }
  45.     return 0;
  46.    
  47.        
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement