卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章16728本站已运行3320

计算商和余数的C程序?

计算商和余数的C程序?

Given two numbers dividend and divisor. The task is to write a program to find the quotient and remainder of these two numbers when the dividend is divided by the divisor.

In division, we will see the relationship between the dividend, divisor, quotient, and remainder. The number which we divide is called the dividend. The number by which we divide is called the divisor. The result obtained is called the quotient. The number left over is called the remainder.

55 ÷ 9 = 6 and 1
Dividend Divisor Quotient Remainder

Input:
Dividend = 6
Divisor = 2
Output:
Quotient = 3,
Remainder = 0

Explanation

Then, the variables Dividend and Divisor are divided using the arithmetic operator / to get the quotient as result stored in the variable quotient; and using the arithmetic operator % to get the remainder as result stored in the variable remainder.

Example

#include <stdio.h>
int main() {
   int dividend, divisor, quotient, remainder;
   dividend= 2;
   divisor= 6;
   // Computes quotient
   quotient = dividend / divisor;
   // Computes remainder
   remainder = dividend % divisor;
   printf("Quotient = %d

", quotient); printf("Remainder = %d", remainder); return 0; }

卓越飞翔博客
上一篇: Klee的算法(线段的并集长度)在C++中
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏