0

/* 在页面下方的 3/4 处,我有直接在本段下方列出的代码。我需要它来打印剩余部分,但似乎无法正确处理。我知道使用 Modulus 运算符是此功能的关键,但我不知道如何正确使用它。

result = num1 / num2;                   /* Division */
printf("When 63 is divided by 6 you get %i\n\n", result);

*/

#include <stdio.h>

int main(void)
{

    int     num1    = 63;
    int     num2    = 6;
    int     result;

    float   nickels = 0.05;
    float   pennies = 0.01;
    float   nickPen;                        /* I really wasn't sure rather to add nickPen as a   float or to even add it at all */


    printf("This program will do a few computations with two numbers.\n\n");

    printf("The two numbers used by this program are 63 and 6.\n\n");

    result = num1 + num2;                   /* Addition */
    printf("The sum of 63 + 6 is %i\n", result);

    result = num1 - num2;                   /* Subtraction */
    printf("The difference of 63 - 6 is %i\n", result);

    result = num1 * num2;                   /* Multiplication */
    printf("The product of 63 * 6 is %i\n", result);

    result = num1 / num2;                   /* Division */
    printf("When 63 is divided by 6 you get %i\n\n", result);

    nickPen = nickels*100 + pennies*25;     /* Multiplication and addition of money */
    printf("If you have 100 nickels + 25 pennies you will have $%.2f\n\n", nickPen);

    printf("Thank you for using this program");



        getchar();
        return 0;

} /* End Main*/
4

3 回答 3

0
printf("When 63 is divided by 6 the remainder is %i\n\n", 63 % 6);
于 2013-09-21T23:38:20.130 回答
0

C中的x % y模是模定义为的地方x - ((int)x/y)*y

于 2013-09-21T23:38:27.970 回答
0
result = num1 % num2;    /* Modulus */
printf("When 63 is divided by 6 you get a remainder of %i\n\n", result);
于 2013-09-21T23:41:04.080 回答