Skip to main content
1 of 4
chux
  • 33.6k
  • 2
  • 38
  • 92
  1. Standard C does not allow definition a function within another. Move definitions of functions like int ask() outside of main().

  2. 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);
     }
    
  3. Likewise for nonZeroRand(). In this case, code could simply re-try to avoid the 1 bias.

    int nonZeroRand(void) {
      int n;
      do {
        int n=(rand()%randMax - randMax);
      } while (n == 0);
      return n;
    }
    
  4. stdout may not be buffered as expected. Use fflush() to insure output is seen before asking for input.

    printf("\nEnter f:");
    fflush(stdoout); // add
    scanf("%d", &inputF);
    
  5. Robust code check the return value of user input.

     // scanf("%d", &inputF);
     if (scanf("%d", &inputF!= 1) Handle_Error();
    
  6. Curious that code did define f,g,h,k in alphabetically order.

  7. 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);
    
  8. ... 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