have any body another way to do this.
I should write a recursive function that finds and returns the length of a connected curve by counting the 'X' letters. The curve is uniquely determined by any starting point (m, n) that is on a curve itself.
#include <stdio.h>
#define M 5
#define N 8
char FELD[M][N] = {
{'X','.','.','.','.','.','.','X'},
{'X','X','.','X','.','.','.','X'},
{'.','X','.','X','.','X','X','X'},
{'.','X','X','X','.','X','.','.'},
{'.','.','.','.','.','X','.','.'}
};
int arcno ( int m, int n){
if((m < 0)||(m >= M)||(n < 0)||(n >= N)||(FELD[m][n] != 'X'))
{
return 0 ;
}
return 1 + arcno (m-1, n) + arcno (m+1, n) + arcno (m, n-1) + arcno (m, n+1);
}
int main(){
int f = arcno(2, 3);
printf("arcno = %d \n\n", f);
for( int m = 0; m < M; m++) { for ( int n = 0; n < N; n++){
printf("%c",FELD[m][n]);} printf ( "\n" );}
return 0 ;
}
I should get 9 but why I get Process returned -1073741571 (0xC00000FD) execution time : 3.675 s
I got it ^_^ FELD[m][n] = 's';I just have to change the set characters FELD[m][n] = 'x';
int arcno ( int m, int n){
if((m < 0)||(m >= M)||(n < 0)||(n >= N)||(FELD[m][n] != 'X'))
{
return 0 ;
}
FELD[m][n] = 'x'; //<==========
return 1 + arcno (m-1, n) + arcno (m+1, n) + arcno (m, n-1) + arcno (m, n+1);
}
User contributions licensed under CC BY-SA 3.0