gpt4 book ai didi

c - 如何在 C 语言的 printf 输出中使用除法的模运算符显示余数

转载 作者:行者123 更新时间:2023-11-30 17:47:24 26 4
gpt4 key购买 nike

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

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*/

最佳答案

printf("When 63 is divided by 6 the remainder is %i\n\n", 63 % 6);

关于c - 如何在 C 语言的 printf 输出中使用除法的模运算符显示余数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18938774/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com