Implement input validation for leading zero

Add validation to prevent input starting with 0.
This commit is contained in:
2025-11-17 10:10:33 +07:00
committed by GitHub
parent 951ff52912
commit 9aaeb4bece
+7
View File
@@ -61,6 +61,13 @@ int scan(void){
printf("You enter n>100 000 Try again\nNum: "); printf("You enter n>100 000 Try again\nNum: ");
continue; continue;
} }
if(x=='0'&&n<=0){
while((x = getchar())!='\n')
if(x == EOF) return 0;
printf("You num cannot starts with 0. Try again\nNum: ");
continue;
}
} }
if (x == EOF) return 0; if (x == EOF) return 0;