用循环语句实现从键盘输入四个数,组成一个四位数,先输入的在高位

1个回答

  • #include

    int main()

    {

    int a[4];

    int i;

    printf("Please inpuet the 4 numbers:n");

    for (i = 0; i < 4; i++)

    {

    printf("Please Inpuet the %dth number.n",i + 1);

    scanf("%d",&a[i]);

    }

    printf("the 4 number are:n");

    printf("千位:%dn",a[0]);

    printf("百位:%dn",a[1]);

    printf("十位:%dn",a[2]);

    printf("个位:%dn",a[3]);

    printf("这个四位数是:%dn",((a[0] * 1000) + (a[1] * 100) + (a[2] * 10) + a[3]));

    return 0;

    }