hello I am a beginner in c programming , I was building a program that gives prints the maximum digit when entering a 2 digit number,if the user doesn't give a 2 digit number , my program asks him to enter again using functions. Also this is my 1st question , I hope some1 answers me
error :- stack smashing detected *** terminated
language :- c programming
source code
#include <stdio.h>
int aa(int x);
int tryg();
int main() {
int h;
printf("enter a 2 digit number\n");
scanf("%d", &h);
aa(h);
return 0;
}
int tryg() {
int d;
printf("enter a 2 digit number\n");
scanf("%d", &d);
aa(d);
}
int aa(int x) {
int count = 0, a[2], max;
while (x > 0) {
a[count] = x % 10;
x = x / 10;
count++;
}
if (count != 2) {
printf(" error you've entered non 2 digit number try again \n");
tryg();
} else {
if (a[0] > a[1])
max = a[0];
else
max = a[1];
printf("maximum digit is %d", max);
}
}