#include <stdio.h>
#include <stdio.h>
void reverseDigits(int n, int *result);
main(void)
{
int result;
int n;
int cont = 1;
while (cont) {
result = 0;
printf("Enter a number: ");
scanf("%d", &n);
reverseDigits(n, &result);
printf("result = %d\n", result);
printf("Continue (1 for yes, 0 for no): ");
scanf("%d", &cont);
}
return 0;
}
void reverseDigits(int n, int *result){
if(n>0){
return;
}
int reverseNum=reverseNum*10+(n%10);
n=n/10;
*result=reverseNum;
int x=*result;
reverseDigits(n,&x);
}
Is that really your intent? You are effectively saying that for any number greater than 0, you will not process it. I expect that you have your >< signs mixed up.
even if it is switched to < , the program still doesn't run correctly. compilation has no error but when it runs it says that it has stopped working. any idea what went wrong?