hozer

PointersUraLab1

May 29th, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.68 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdio.h>
  4.  
  5. int main()
  6. {
  7.     float **x, *b;
  8.     int n, i, j;
  9.  
  10.     printf("input n: "); scanf("%d", &n);
  11.     x = (float**) malloc(sizeof(float*) * n);
  12.     b = (float*) malloc(sizeof(float*) * n);
  13.     for (i = 0; i < n; i++)
  14.         *(x+i) = (float*) malloc(sizeof(float) * n);
  15.  
  16.     printf("input array: ");
  17.     for (i = 0; i < n; i++)
  18.         for (j = 0; j < n; j++)
  19.             scanf("%f", *(x+i)+j);
  20.  
  21.     for (i = 0; i < n; i++)
  22.     {
  23.         float ser = 0.0;
  24.         for (j = 0; j < n; j++)
  25.             ser += *(*(x+i)+j);
  26.         *(b+i) = ser / n;
  27.     }
  28.  
  29.     for (i = 0; i < n; i++)
  30.         printf("%f ", *(b+i));
  31.  
  32.     for (i = 0; i < n; i++)
  33.         free(*(x+i));
  34.     free(x);
  35.     free(b);
  36.  
  37.     _getch();
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment