I was having some problem when trying to do a recursive in C programming. Here is the expected output:
Enter a number: 1234567
Enter the digit position: 3
rDigitValue1(): 5
rDigitvalue2(): 5
And here is my code:
int rdigitValue1(int num, int k)
{
int count = 0, output;
if (count != k) {
rdigitValue1(num / 10, k);
count++;
}
else {
output = (num % 10);
}
return output;
}
The parameter num is the number whereas the parameter k is the position. With these code, when I try to run the program, it just crashed without prompting any error message. Any idea?
Aucun commentaire:
Enregistrer un commentaire