Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- #include <ctype.h>
- #include <time.h>
- #pragma warning(disable:4996 6031)
- int a[128][128] = { 0 };
- int main(){
- int m, n, i, j, dx, dy;
- memset(a, -1, sizeof(a));
- scanf("%d%d", &m, &n);
- for(i = 1; i <= m; i++){
- for(j = 1; j <= n; j++){
- scanf("%d", &(a[i][j]));
- }
- }
- for(i = 1; i <= m; i++){
- for(j = 1; j <= n; j++){
- int cnt = 0;
- double sum = 0;
- for(dx = -1; dx <= 1; dx++){
- for(dy = -1; dy <= 1; dy++){
- if(a[i + dx][j + dy] != -1){
- sum += a[i + dx][j + dy];
- cnt += 1;
- }
- }
- }
- printf("%3d ", (int)round(sum / cnt));
- }
- putchar('\n');
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement