There is such a function:

int AvsB(char *string1,char *string2){ int i,length=stringLength(string1); for(i=0;i<length;i++){ if(convertInInt(string1[i])>convertInInt(string2[i])){//A>B return printf("%s > %s",string1,string2); } if(convertInInt(string1[i])<convertInInt(string2[i])){//A<B return printf("%s < %s",string1,string2); } if(convertInInt(string1[i])==convertInInt(string2[i])&&i==length-1){//A==B return printf("%s = %s",string1,string2); } } } 

It compares two numbers that are entered as strings. It is necessary to transfer it using recursion.

As I understand it - the solution will be to find the length of the string before the function is called in the program and pass this value as a function parameter.

And the counter for receiving the next element of the line - i must also be passed as a parameter?

Or is there a better approach?

    1 answer 1

    The function should be responsible for one action , i.e. She should not compare and also display a message.

    We take out the conclusion, then we get something like

     int AvsB(char *string1,char *string2) { if ((*string1 == 0) && (*string2 == 0)) return 0; if(convertInInt(*string1)>convertInInt(*string2)) { //A>B return 1; } if(convertInInt(string1[i])<convertInInt(string2[i])){//A<B return -1 } return AvsB(string1+1,string2+1); } int res = AvsB(string1,string2); printf("%s %c %s\n",string1,(res == 1) ? '>' : (res == -1) ? '<' : '=', string2); 

    Like that. We compare the first characters, if they are not equal - the answer is received, they are equal - we compare the lines that are obtained by dropping the first characters. The first check is at the end of the lines.

    The meaning of convertInInt() remains a mystery to me, but if you think that it is needed there ... :)