Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim.**/ #include <stdio.h> int main() { int rw, clm, i, j, cndtn = 0, n = 0, m = 0; scanf("%d%d", &rw, &clm); int ara[rw][clm]; for(i=0; i<rw; i++) for(j=0; j<clm; j++) scanf("%d", &ara[i][j]); for(i=1; i<rw-1; i++) { for(j=1; j<clm-1; j++) { if(ara[i][j]==42) if(ara[i-1][j-1]==7 && ara[i-1][j]==7 && ara[i-1][j+1]==7) if(ara[i][j-1]==7 && ara[i][j+1]==7) if(ara[i+1][j-1]==7 && ara[i+1][j]==7 && ara[i+1][j+1]==7) { cndtn = 1; n = i+1; m = j+1; } } } printf("%d %d\n", n, m); return 0; }
cndtn = 1;
ReplyDeletewhy this statement..
int n,m,i,j,a,b,c=0,p=0,q=0;
ReplyDeletecin>>n>>m;
int ara[n][m];
for(a=1;a<=n;a++)
{
for(b=1;b<=m;b++)
cin>>ara[a][b];
}
for(i=2;i<=n-1;i++)
{
for(j=2;j<=m-1;j++)
{
if(ara[i][j]==42)
{
if(ara[i-1][j-1]==7&&ara[i-1][j]==7&&ara[i-1][j+1]==7)
{
if(ara[i][j+1]==7&&ara[i][j-1]==7)
{
if(ara[i+1][j-1]==7&&ara[i+1][j]==7&&ara[i+1][j+1]==7)
p=i;
q=j;
}
}
}
}
}
cout<<p<<" "<<q<<endl;
why i got run time error??
would you please help me...
thanks in advance...