Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. int main()
  2. {
  3.  
  4. FILE* in = fopen("3.txt", "r");
  5. int no_of_rows = 0;
  6. int no_of_cols = 0;
  7. int nz = 0;
  8.  
  9. fscanf(in, "%d %d %d", &no_of_rows, &no_of_cols, &nz);
  10.  
  11.  
  12. printf("no of rows: %dn", no_of_rows);
  13. printf("no of cols: %dn", no_of_cols);
  14. printf("nz values: %dn", nz);
  15.  
  16. int* i_idx = (int*)malloc(nz * sizeof(int));
  17. int* j_idx = (int*)malloc(nz * sizeof(int));
  18. double* a = (double*)malloc(nz * sizeof(double));
  19. int i = 0;
  20.  
  21. for (i = 0; i < nz; i++)
  22. {
  23. fscanf(in, "%d %d %lgn", &i_idx[i], &j_idx[i], &a[i]);
  24. i_idx[i]--; /* adjust from 1-based to 0-based */
  25. j_idx[i]--;
  26. }
  27.  
  28. //double =
  29.  
  30. for (i = 0; i < nz; i++)
  31. printf("%d %d %20.19gn", i_idx[i], j_idx[i], a[i]);
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement