Advertisement
Guest User

Untitled

a guest
Apr 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. void dane(int n, int m, int t[][m])
  6. {
  7. for(int i=0; i<m; i++)
  8. {
  9. for(int j=0; j<n; j++)
  10. {
  11. t[i][j] = rand() % 10;
  12. }
  13. }
  14. }
  15.  
  16. void drukuj(int n, int m, int t[][m])
  17. {
  18. printf("Twoja tablica to:\n\n");
  19. for (int i = 0; i < n; i++ )
  20. {
  21. for (int j = 0; j < m; j++ )
  22. {
  23. if(j==m-1) printf("%d\n", t[i][j]);
  24. else printf("%d\t", t[i][j]);
  25. }
  26. }
  27. }
  28.  
  29. double srednia(int n, int m, int t[][m], int lw, int pw, int gk, int dk)
  30. {
  31. double suma = 0;
  32. double y=0;
  33. for (int i = gk; i<=dk; i++)
  34. {
  35. for (int j = lw; j<=pw; j++)
  36. {
  37. suma=suma+t[i][j];
  38. y++;
  39. }
  40. }
  41. double sr=1.0*suma/y;
  42. return sr;
  43. }
  44.  
  45. int main()
  46. {
  47. srand(time(NULL));
  48. int N, M, LW, PW, GK, DK;
  49. N = 5;
  50. M = 5;
  51. int T[N][M];
  52. dane(N,M,T);
  53. drukuj(N,M,T);
  54. printf("\nPodaj zakres wierszy, w którym chcesz policzyć średnią (od 1 do %d)\n",M);
  55. printf("Podaj lewy wiersz: ");
  56. scanf("%d",&LW);
  57. LW--;
  58. printf("Podaj prawy wiersz: ");
  59. scanf("%d",&PW);
  60. PW--;
  61. printf("\nPodaj zakres kolumn, w którym chcesz policzyć średnią (od 1 do %d)\n",N);
  62. printf("Podaj górną kolumnę: ");
  63. scanf("%d",&GK);
  64. GK--;
  65. printf("Podaj dolną kolumnę: ");
  66. scanf("%d",&DK);
  67. DK--;
  68. printf("\nSrednia w obszarze (%d,%d) - (%d,%d) wynosi: %.2f",LW+1,GK+1,PW+1,DK+1,srednia(N,M,T,LW,PW,GK,DK));
  69. return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement