Find the quotient and remainder in C-Programming: If we divided the number a with the number b then we will get a form like a=bq+r, where q is called quotient and r is said to be remainder. For example we divide 5 with 2 then we will get 5=(2*2)+1 so here 2 is quotient and 1 is remainder. We want to solve this with the help of C-Programming. At first we give the required code then we explain.
Code:
#include<stdio.h>
int main()
{
int a,b,q,r;
printf("Enter the dividend:");
scanf("%d",&a);
printf("Enter the divisor:");
scanf("%d",&b);
if(b==0)
printf("Undefined");
q=a/b;
r=a%b;
printf("The quotient and remainder are respectively are %d and %d",q,r);
}
Output:
The output is given below:
Explanation:
1. We use <stdio.h> header package.2. We introduce 4 integers variable a,b,q,r for dividend, divisor, quotient and remainder respectively.
3. Here has a special case that is if we divide any number with 0 then it will be undefined. So we introduce a if case there.
4. / is used for the quotient and % is used to evaluate residue. For more you can visit syntax page.
5. Then we print the value of q and r respectively.
If you have any doubts comment below.
No comments:
Post a Comment