Home  >  Article  >  Backend Development  >  How to find remainder in c language

How to find remainder in c language

藏色散人
藏色散人Original
2020-02-07 11:47:3546810browse

How to find remainder in c language

How to find the remainder in C language?

In C language, the binary operator % is directly used to find the remainder. For example, the remainder of a divided by b can be expressed as a%b

Recommended learning: c language video Tutorial

Note: The two operands of operator % in C language must be integers and cannot be floating point or other structure types, otherwise the compiler will prompt an error.

Sample code:

#include <stdio.h>
int main()
{
      int a=5, b=3, c;
      c=a%b; //将a除以b的余数赋值给c
      printf("%d",c);
      return 0;
}
/*
输出:2
*/

The above is the detailed content of How to find remainder in c language. 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