mardi 24 juillet 2018

What is wrong with this if/else statement?

The code below is not working. Whatever numbers I enter, be they equal or not, it always follows the else-branch. Why?

Here is the code:

#include <stdio.h>

int main()
{
    printf("\nEnter breadth:\n\n");

    int a;
    scanf("%a",&a);

    printf("\nEnter length:\n\n");

    int b;
    scanf("%b",&b);

    if (a==b)
    {
        printf("\nThis is a square\n");
    }
    else
    {
        printf("\nThis is a rectangle\n");
    }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire