演示数学运算符,以及不同类型的除法

#include <stdio.h>
int main()
{
    float a = 19.0;
    float b = 5.0;
    float floatAnswer;
    int x = 19;
    int y = 5;
    int intAnswer;

    floatAnswer = a / b;
    printf("%.1f divided by %.1f equals %.1f/n", a, b, floatAnswer);
    floatAnswer = x /y; //Take 2 creates an answer of 3.0
    printf("%d divided by %d equals %.1f/n", x, y, floatAnswer);


    intAnswer = a / b;
    printf("%.1f divided by %.1f equals %d/n", a, b, intAnswer);
    intAnswer = x % y; // This calculates the remainder (4)
    printf("%d modulus (i.e. remainder of) %d equals %d", x, y, intAnswer);

    return 0;
}

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/266777.html

(0)
上一篇 2022年6月7日
下一篇 2022年6月7日

相关推荐

发表回复

登录后才能评论