-
-
Save draganczukp/47a349dd77f0c3f5bf220a853b55308b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "main.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#define N 5 | |
#define M 5 | |
void wyswietl(int tab[][M], int size); | |
void min(int tab[][M], int size); | |
void max(int tab[][M], int size); | |
void find(int szukane, int tab[][M], int size, int *xi, int *yi); | |
void srednia(int tab[][M], int size); | |
int main(void) | |
{ | |
int tab[N][M]; | |
int x, y; | |
for(x = 0; x < N; x++){ | |
for(y = 0; y < M; y++){ | |
tab[x][y] = rand()%100; | |
} | |
} | |
tab[2][2] = 2; | |
wyswietl(tab, N); | |
return(0); | |
} | |
void wyswietl(int tab[][M], int size){ | |
int x, y; | |
int xi, yi; | |
for(x = 0; x < size; x++){ | |
for(y = 0; y < M; y++){ | |
printf("%dx%d@%ld -> %d\n", x, y, &tab[x][y], tab[x][y]); | |
} | |
} | |
/* min(tab,size); */ | |
/* max(tab,size); */ | |
/* find(2, tab, size, &xi, &yi); */ | |
/* printf("%d@%dx%d",2,xi,yi); */ | |
srednia(tab,size); | |
} | |
void min(int tab[][M], int size){ | |
int m, mx, my; | |
int x, y; | |
m = tab[0][0]; | |
mx = my = 0; | |
for(x = 0; x < size; x++){ | |
for(y = 0; y < M; y++){ | |
if(tab[x][y] < m){ | |
m = tab[x][y]; | |
mx = x; | |
my = y; | |
} | |
} | |
} | |
printf("Min: %dx%d->%d\n",mx,my,m); | |
} | |
void max(int tab[][M], int size){ | |
int m, mx, my; | |
int x, y; | |
m = tab[0][0]; | |
mx = my = 0; | |
for(x = 0; x < size; x++){ | |
for(y = 0; y < M; y++){ | |
if(tab[x][y] > m){ | |
m = tab[x][y]; | |
mx = x; | |
my = y; | |
} | |
} | |
} | |
printf("Max: %dx%d->%d\n",mx,my,m); | |
} | |
void srednia(int tab[][M], int size){ | |
int s,i; | |
int x, y; | |
s = i = 0; | |
for(x = 0; x < size; x++){ | |
for(y = 0; y < M; y++){ | |
s += tab[x][y]; | |
i++; | |
} | |
} | |
printf("Średnia: %f", ((float)s) / ((float)i)); | |
} | |
void find(int szukane, int tab[][M], int size, int *xi, int *yi){ | |
int x,y; | |
for(x = 0; x < size; x++){ | |
for(y = 0; y < M; y++){ | |
if(tab[x][y] == szukane){ | |
*xi = x; | |
*yi = y; | |
return; | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment