Coriic

Macierz

Jan 20th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <time.h>
  3. #include <stdlib.h>
  4.  
  5. struct wezel{
  6. int x;
  7. int y;
  8. double wartosc;
  9. struct wezel *next;
  10. };
  11.  
  12. void macierz_rzadka(struct wezel **poczatek, double tab[10][10]){
  13. int i, j;
  14. struct wezel *tmp;
  15. for (i=0; i<3; ++i){
  16. for (j=0; j<3; ++j){
  17. if(tab[i][j] != 0){
  18. tmp=(struct wezel *)malloc(sizeof(struct wezel));
  19. tmp->x=j;
  20. tmp->y=i;
  21. tmp->wartosc=tab[i][j];
  22. tmp->next=*poczatek;
  23. *poczatek=tmp;
  24. }
  25. }
  26. }
  27. }
  28.  
  29. void wyswietl (struct wezel *poczatek){
  30. struct wezel *it;
  31. it=poczatek;
  32. while (it != NULL){
  33. printf("Element niezerowy\n");
  34. printf("Wiersz: %d\n", it->y);
  35. printf("Kolumna: %d\n", it->x);
  36. printf("Wartosc: %f\n", it->wartosc);
  37. it=it->next;
  38. }
  39. }
  40.  
  41. int main(void){
  42. double tab[10][10];
  43. struct wezel *poczatek;
  44. int zarodek, i, j;
  45. poczatek=NULL;
  46. zarodek=time(NULL);
  47. srand(zarodek);
  48. /*losowanie elementow macierzy*/
  49. for (i=0; i<3; ++i){
  50. for (j=0; j<3; ++j){
  51. tab[i][j]=rand()%100;
  52. }
  53. }
  54. macierz_rzadka(&poczatek, tab);
  55. wyswietl(poczatek);
  56. return 0;
  57. }
Add Comment
Please, Sign In to add comment