Advertisement
Archangelpl

Untitled

Jun 20th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. #pragma warning (disable: 4996)
  2. #include "stdafx.h"
  3. #include <stdlib.h>
  4. #include<stdio.h>
  5.  
  6. FILE *fd;
  7. FILE *fp;
  8.  
  9. int main()
  10. {
  11.  
  12. double **A, *x, *y;
  13. int n, m;
  14. if (!(fd = fopen("dane.txt", "r")))
  15. {
  16. printf("Blad wczytywania danych");
  17. exit(0);
  18. }
  19. fp = fopen("zapis.txt", "w");
  20.  
  21.  
  22. fscanf(fd, "%d", &n);
  23. fscanf(fd, "%d", &m);
  24.  
  25. printf("Wypis Macierzy A: \n");
  26. A = malloc(m * sizeof(double));
  27. x = malloc(m * sizeof(double));
  28. y = malloc(m * sizeof(double));
  29. for (int i = 0; i < n;i++)
  30. {
  31.  
  32. A[i] = malloc(n * sizeof(double));
  33. for (int j = 0;j < m;j++)
  34. {
  35. fscanf(fd, "%lf", &A[i][j]);
  36. printf("%lf ", A[i][j]);
  37. }
  38. printf("\n");
  39.  
  40. }
  41.  
  42. fprintf(fp, "Wektor x:\n");
  43. printf("---------------------------------------------------\nWektor x:\n");
  44. for (int i = 0; i < m; i++)
  45. {
  46. x[i] = A[0][i];
  47. printf("%lf ", x[i]);
  48. fprintf(fp, "%lf ", x[i]);
  49. }
  50. printf("\n---------------------------------------------------\nWektor y:\n");
  51. fprintf(fp, "\nWektor y:\n");
  52. for (int i = 0; i < m; i++)
  53. {
  54. y[i] = A[n-1][i];
  55. printf("%lf ", y[i]);
  56. fprintf(fp, "%lf ", y[i]);
  57. }
  58.  
  59. printf("\n");
  60. fclose(fp);
  61. fclose(fd);
  62. return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement