C Language Example - Dividing Two Numbers
When dividing two numbers, if there is a remainder, output the remainder.
Example
#include <stdio.h>
int main(){
int dividend, divisor, quotient, remainder;
printf("Enter dividend:");
scanf("%d", ÷nd);
printf("Enter divisor:");
scanf("%d", &divisor);
// Calculate quotient
quotient = dividend / divisor;
// Calculate remainder
remainder = dividend % divisor;
printf("Quotient = %d\n", quotient);
printf("Remainder = %d", remainder);
return 0;
}
Run result:
输入被除数: 5 输入除数: 2 商 = 2 余数 = 1other extensions
C Language Examples