Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Lecture Note: n DIV d: integer part of dividing n by d n MOD d: the remainder n

ID: 3407080 • Letter: L

Question

Lecture Note:

n DIV d: integer part of dividing n by d

n MOD d: the remainder

n = (n DIV d) * d + (n MOD d)

Example: 7=2*3+1, so

7 DIV 3 = 2

7 MOD 3 = 1

Recall the DIVMOD algorithm

This algorithm computed (n DIV d, n MOD d) for integers n and d, both greater than 0.

Using pseudocode in your programming language of choice, expand the algorithm to accept any integer n, both positive and negative (d is still assumed to be positive). Add comments when needed to make sure your logic is clear to the reader.

Explanation / Answer

#include<stdio.h>
function(int n,int d)
{
int a,b,s;
a = n/d; //here a is your n DIV d: integer part of dividing n by d
b = n%d; // here b is your n MOD d: the remainder
s = a*d+b; // This state n = (n DIV d) * d + (n MOD d)
printf("value of nDIVd=%d value of nMODd=%d ",a,b);
printf("(n DIV d) * d + (n MOD d)=%d",s);

}
void main()
{
int a,b,x;
scanf("%d",&a);
scanf("%d",&b);
x= function(a,b);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote