Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int main()
- { int A[100][100],i,j,m,n;
- int B[100][100];
- 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+2;i++)
- for(j=0;j<m+2;j++)
- B[i][j]=0;
- for(i=0;i<n;i++)
- for(j=0;j<m;j++)
- B[i+1][j+1]=A[i][j];
- for(i=1;i<=n;i++)
- for(j=1;j<=m;j++)
- {
- if(B[i][j]==0)
- A[i][j]=B[i][j+1]+B[i][j-1]+B[i-1][j]+B[i+1][j]+B[i-1][j-1]+B[i-1][j+1]+B[i+1][j+1]+B[i+1][j-1];
- }
- for(i=1;i<=n;i++) {
- printf("\n");
- for(j=1;j<=m;j++){
- if(B[i][j]==1)
- printf("* ");
- else
- printf("%d ",A[i][j]);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement