Standard C does not allow definition a function within another. Move definitions of functions like
int ask()
outside ofmain()
.The
if ( n == 0 ){ n++; }
favors the return value of 1- a bias. Alternative:// return [-level...-1, 1...level] int nonZeroCoefficient(void) { int n = rand()%(2*level); if (n % 2) { return n/2 + 1; } return -(n/2 + 1); }
Likewise for
nonZeroRand()
. In this case, code could simply re-try to avoid the1
bias.int nonZeroRand(void) { int n; do { int n=(rand()%randMax - randMax); } while (n == 0); return n; }
stdout
may not be buffered as expected. Usefflush()
to insure output is seen before asking for input.printf("\nEnter f:"); fflush(stdoout); // add scanf("%d", &inputF);
Robust code check the return value of user input.
// scanf("%d", &inputF); if (scanf("%d", &inputF!= 1) Handle_Error();
Curious that code did define
f,g,h,k
in alphabetically order.Formating to the width of the review presentation is appreciated.
}else{ printf("\nSorry! your answer is not currect!\nthe currect answer is:\nf:%d\ng:%d\nh:%d\nk:%d\n \ntry again",f, g, h, k);
... versus (also check spelling)
}else{ printf("\nSorry! your answer is not correct!\n" "the correct answer is:\nf:%d\ng:%d\nh:%d\nk:%d\n \n" "try again",f, g, h, k);
chux
- 33.6k
- 2
- 38
- 92