Home >Backend Development >C#.Net Tutorial >C language addition, subtraction, multiplication and division code

C language addition, subtraction, multiplication and division code

angryTom
angryTomOriginal
2019-11-19 09:37:5116904browse

C language addition, subtraction, multiplication and division code

c language code for addition, subtraction, multiplication and division

Addition, subtraction, multiplication and division are common mathematical operations, and C language certainly supports them. However, the operation symbols in C language are slightly different from those in mathematics, please see the table below.

Addition Subtraction Multiplication Division Find Remainder (remainder)
Mathematics - × ÷
C Language - * / %

The plus sign and minus sign in C language are the same as those in mathematics, but the multiplication sign and division sign are different; in addition, C language also has an additional operator for finding the remainder. that is%.

Recommended course: C Language Tutorial

The following code demonstrates how to perform addition, subtraction, multiplication and division in C language Operation: plain text copy

#include <stdio.h>
int main()
{
    int a = 12;
    int b = 100;
    float c = 8.5;

    int m = a + b;
    int v = b - a;
    float n = b * c;
    double p = a / c;
    int q = b % a;

    printf("m=%d, c=%d, n=%f, p=%lf, q=%d\n", m, c, n, p, q);

    return 0;
}

Output result:

m=112, v=88, n=850.000000, p=1.411765, q=4

The above is the detailed content of C language addition, subtraction, multiplication and division code. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Related articles

See more