samedi 6 juin 2020

Regarding if else statements in C language

Please explain to me why this code is wrong for the task and below I have explained all the four conditions -[][1]

#include stdio.h
int main()    
{
      int n;
      scanf ("%d", &n);     //taking input
      if (n / 2 != 0)
        {
          printf ("Weird");     //checking first condition
        }
      else if (n % 2 == 0 && 2 <= n <= 5)
        {               //checking second condition
          printf ("Not Weird");
        }
      else if (n % 2 == 0 && 6 <= n <= 20)
        {               //checking third condition
          printf ("Weird");
        }
      else if (n % 2 == 0 && n > 20)
        {               //checking fourth condition
          printf ("Not Weird");
        }
      else
        {
          printf ("Error");
        }
      return 0;
    }

this is the image for the question[1]: https://i.stack.imgur.com/OtY7o.png**

Aucun commentaire:

Enregistrer un commentaire