在devc++中调试可运行。
#include
#include
#define ROW 3
int fun( int tmp[ROW][ROW], int r, int c )//r为行c为列
{
if ( r>=ROW||c>=ROW )
{
return -1;
}
int a[4][2]={{-1,0},{1,0},{0,-1},{0,1}};//左右上下
int i=0;
int sum=0;
for( i=0; i<4; i++ )
{
if ( r+a[i][0]<0 || c+a[i][1]<0 || r+a[i][0]>=ROW || c+a[i][1]>=ROW )
{
continue;
}
printf("tmp[%d][%d]=%d\n",r+a[i][0],c+a[i][1],tmp[r+a[i][0]][c+a[i][1]]);
sum+= tmp[r+a[i][0]][c+a[i][1]];
}
return sum;
}
main()
{
int tmp[ROW][ROW];
int i,j;
int r;
i = 0;
for ( i=0; i
for ( j=0; j
printf( "tmp[%d][%d]=", i, j );
scanf( "%d", &tmp[i][j] );
}
}
for ( i=0; i
for ( j=0; j
printf( "%5d ", tmp[i][j] );
}
printf("\n");
}
if( (r = fun( tmp, 1, 2 ))!=-1 )
printf("result is: %d\n", r );
system("PAUSE");
}
#include
#include
#define STRLEN 100
int Substr( char desstr[STRLEN], char str[STRLEN], int start, int count )//目的串,源串,开始位置,数量
{
int i;
int j;
for ( i=0,j=start-1; i
if ( i>=STRLEN-1 || j>=STRLEN )
{
return -1;
}
desstr[i] = str[j];
}
desstr[i] = '\0';
return 0;
}
main()
{
char a[STRLEN]="i'm not super man, but i do super things!";
char b[STRLEN];
if ( Substr(b,a,5,10) != -1 )
{
printf("b is:%s",b);
}
system("PAUSE");
}
没人管你