Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- void dane(int n, int m, int t[][m])
- {
- for(int i=0; i<m; i++)
- {
- for(int j=0; j<n; j++)
- {
- t[i][j] = rand() % 10;
- }
- }
- }
- void drukuj(int n, int m, int t[][m])
- {
- printf("Twoja tablica to:\n\n");
- for (int i = 0; i < n; i++ )
- {
- for (int j = 0; j < m; j++ )
- {
- if(j==m-1) printf("%d\n", t[i][j]);
- else printf("%d\t", t[i][j]);
- }
- }
- }
- double srednia(int n, int m, int t[][m], int lw, int pw, int gk, int dk)
- {
- double suma = 0;
- double y=0;
- for (int i = gk; i<=dk; i++)
- {
- for (int j = lw; j<=pw; j++)
- {
- suma=suma+t[i][j];
- y++;
- }
- }
- double sr=1.0*suma/y;
- return sr;
- }
- int main()
- {
- srand(time(NULL));
- int N, M, LW, PW, GK, DK;
- N = 5;
- M = 5;
- int T[N][M];
- dane(N,M,T);
- drukuj(N,M,T);
- printf("\nPodaj zakres wierszy, w którym chcesz policzyć średnią (od 1 do %d)\n",M);
- printf("Podaj lewy wiersz: ");
- scanf("%d",&LW);
- LW--;
- printf("Podaj prawy wiersz: ");
- scanf("%d",&PW);
- PW--;
- printf("\nPodaj zakres kolumn, w którym chcesz policzyć średnią (od 1 do %d)\n",N);
- printf("Podaj górną kolumnę: ");
- scanf("%d",&GK);
- GK--;
- printf("Podaj dolną kolumnę: ");
- scanf("%d",&DK);
- DK--;
- 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));
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement