All pastes #2095754 Raw Edit

Untitled

public c v1 · immutable
#2095754 ·published 2011-11-25 10:50 UTC
rendered paste body
#include<stdio.h>#include<stdlib.h>int main(){    int a[100][100],b[100][100];    int i,j,m,n;    scanf("%d %d",&n,&m);    for (i=0;i<n;i++)        for(j=0;j<m;j++)            scanf("%d",&a[i][j]);      for (i=0;i<n;i++)        {            for (j=0;j<m;j++)            {                if ((i+j)%2==0)                    {                        if (j==0 && i==0) b[i][j]=a[1][1];                            else  if(j==m-1 && i==0) b[i][j]=a[1][j-1];                                else if (i==n-1 && j==0) b[i][j]=a[n-1][j+1];                                    else if (i==n-1 && j==m-1) b[i][j]=a[i-1][j-1];                                        else if (j==0) b[i][j]=a[i-1][j+1]+a[i+1][j+1];                                           else if (i==0) b[i][j]=a[i+1][j-1]+a[i+1][j+1];                                              else if (i==n-1) b[i][j]=a[i-1][j-1]+a[i-1][j+1];                                                else if (j==m-1) b[i][j]=a[i-1][j-1]+a[i+1][j-1];                                                 else  b[i][j]=a[i-1][j-1]+a[i-1][j+1]+a[i+1][j-1]+a[i+1][j+1];                    }                else                    {                         if (j==0 && i==0) b[i][j]=a[0][1]+a[1][0];                            else if (j==m-1 && i==0) b[i][j]=a[0][j-1]+a[i+1][j];                                else if  (i==n-1 && j==0) b[i][j]=a[i-1][j]+a[i][j+1];                                    else if  (i==n-1 && j==m-1) b[i][j]=a[i-1][j]+a[i][j-1];                                        else if  (j==0) b[i][j]=a[i-1][j]+a[i+1][j]+a[i+1][j+1];                                           else if (i==0) b[i][j]=a[i][j-1]+a[i][j+1]+a[i+1][j];                                              else if (i==n-1) b[i][j]=a[i][j-1]+a[i][j+1]+a[i-1][j];                                                else if (j==m-1) b[i][j]=a[i-1][j]+a[i+1][j]+a[i-1][j-1];                                                    else  b[i][j]=a[i-1][j]+a[i+1][j]+a[i][j-1]+a[i][j+1];                    }            }        }       for (i=0;i<n;i++)                    {                        printf("\n");                        for (j=0;j<m;j++)                           printf("%d\t",b[i][j]);                           printf("\n");                    }    return 0;}