Advertisement
Guest User

Untitled

a guest
May 25th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main ()
  5. {
  6. int m, n, i=0, j, k;
  7. double *matr;
  8. FILE *out;
  9. FILE *in;
  10. double a;
  11. in=fopen("input.txt", "r");
  12. if (in==0)
  13. {
  14. return -1;
  15. }
  16. if (fscanf(in, "%d %d", &n, &m)!=2)
  17. {
  18. fclose (in);
  19. return -1;
  20. }
  21. matr=(double*)malloc(n*m*sizeof(double));
  22. while(fscanf(in, "%lf", &a)==1)
  23. {
  24.  
  25. if(i>m*n)
  26. {
  27. free (matr);
  28. fclose (in);
  29. return -1;
  30. }
  31. matr[i]=a;
  32. i++;
  33. }
  34. if (i<m*n) return -1;
  35. function (matr, n, m);
  36. out=fopen("output.txt", "w");
  37. if (out==0)
  38. {
  39. free(matr);
  40. return -1;
  41. }
  42. for (j=0; j<n; j++)
  43. {
  44. for (k=0; k<m; k++)
  45. {
  46. fprintf (out, "%f ", matr[j*n+k]);
  47. }
  48. fprintf(out, "\n");
  49. }
  50. fclose (out);
  51. free(matr);
  52. return 0;
  53. }
  54.  
  55. //void function(matr, n, m);
  56. //{
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement