Chữ số chẵn lẻ

Nhập vào một số tự nhiên có 4 chữ số và đếm xem số chữ số chẵn nhiều hơn, ít hơn, hay bằng số chữ số lẻ.
 avatar
unknown
c_cpp
a year ago
521 B
74
Indexable
#include <stdio.h>

int main()
{
    int abcd, a, b, c, d, so_le;

    printf("Nhap vao so co 4 chu so: ");
    scanf("%d", &abcd);

    d = abcd % 10;
    c = (abcd / 10) % 10;
    b = (abcd / 100) % 10;
    a = abcd / 1000;

    so_le = a%2 + b%2 + c%2 + d%2;

    if (so_le == 4 - so_le)
        printf("So chu so le bang so chu so chan.");
    else if (so_le > 4 - so_le)
        printf("So chu so le nhieu hon so chu so chan.");
    else
        printf("So chu so chan nhieu hon so chu so le.");
    
    return 0;
}
Editor is loading...
Leave a Comment