Advertisement
Guest User

Untitled

a guest
May 24th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. //zadanie 6
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. #define MAX_DOUBLE 100
  6. #define MIN_DOUBLE -100
  7.  
  8. void printing_tab(double **tab, int line, int column){
  9. for(int i=0; i<line; i++){
  10. for(int j=0; j<column; j++){
  11. printf("%lf \t", tab[i][j]);
  12. }
  13. puts("\n");
  14. }
  15. }
  16.  
  17. void swap(int *a, int *b) {
  18. int temp = *a;
  19. *a = *b;
  20. *b = temp;
  21. }
  22.  
  23. double fRand(double min, double max){
  24. double f = RAND_MAX / (max-min);
  25. return min + (rand() / f);
  26. }
  27.  
  28. int main() {
  29.  
  30. double **tab;
  31. int i, j, line, column;
  32.  
  33. printf("Prosze podac liczbe wierszy macierzy:\n");
  34. scanf("%d", &line);
  35. printf("Prosze podac liczbe kolumn macierzy:\n");
  36. scanf("%d", &column);
  37.  
  38. tab = (double**)malloc(line*sizeof(double*));
  39. for(i=0; i<line; i++) {
  40. tab[i]=(double*)malloc(column*sizeof(double));
  41. }
  42.  
  43. srand(time(NULL));
  44. for(i=0; i<line; i++){
  45. for(j=0; j<column; j++)
  46. tab[i][j]=fRand(MIN_DOUBLE, MAX_DOUBLE);
  47. }
  48. printf("%lf",tab[1][1]);
  49.  
  50. printing_tab(tab, line, column);
  51.  
  52. int what_to_swap;
  53. printf("Jesli chcesz zaminic ze soba\n wiersze, wybierz 1,\n jesli kolumny, wybierz 2\n");
  54. scanf("%d", &what_to_swap);
  55.  
  56. int z1, z2;
  57. if(what_to_swap==1){
  58. printf("Prosze podac numery wierszy, ktore maja zostac ze soba zamienione:\n");
  59. scanf("%d %d", &z1, &z2);
  60. for(j=0; j<column; j++){
  61. swap(&tab[z1-1][j], &tab[z2-1][j]);
  62. }
  63. } else if(what_to_swap==2){
  64. printf("Prosze podac numery kolumn, ktore maja zostac ze soba zamienione:\n");
  65. scanf("%d %d", &z1, &z2);
  66. for(j=0; j<line; j++){
  67. swap(&tab[j][z1-1], &tab[j][z2-1]);
  68. }
  69. }else {
  70. printf("Prosze wybrac poprawna wartosc\n");
  71. exit(0);
  72. }
  73.  
  74. printing_tab(tab, line, column);
  75.  
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement