I need to write a function that'll print a 0 or 1 with
f
variable needs to be 0 or 1- when user enters a number, for example
4321
and thef
variable is 0 the function should return 1 because the number is an ascending series from right to left or else it returns 0 - when user enter a number, for example
1234
andf
variable is 1 the function should return 1 because the number is ascending from left to right else it returns 0
here is my code attempt:
#include <stdio.h>
int f2(int num, int f)
{
int x = num % 10, y = num % 100 / 10;
//if (x == y) return 0;
if (f == 0) {
if (x > y) return 0;
else {
f2(num / 10, f);
return 1;
}
}
if (f == 1) {
if (x < y) return 0;
else {
f2(num/10, f);
return 1;
}
}
}
void main()
{
int num, f;
printf("please enter number and f:");
scanf_s("%d %d", &num, &f);
printf("The result of calling f2(%d) is: %d",num, f2(num, f));
}
the problem is when i put f=1 with numbers 1234 the output is blank