C language addition, subtraction, multiplication and division code

angryTom
Release: 2019-11-19 09:37:51
Original
16850 people have browsed it

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;
}
Copy after login

Output result:

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

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template