Write a program that is able to calculate the answer to an integer division prob
ID: 3755559 • Letter: W
Question
Write a program that is able to calculate the answer to an integer division problem without using the division, integer division, mod, or multiplication operators. The program should ask the user for two integers, and should compute the answer to firstNum // secondNum. The program should then output the full equation, including the answer, to the user. For these inputs, you can assume the following: • The first number may be any positive integer, or zero • The second number may be any positive integer (greater than zero)
Explanation / Answer
Python Program
a=int(input("Enter dividend: "))
b=int(input("Enter divisor: "))
q=a
i=0
while(a>=b):
a=a-b
i=i+1
print("Result: "+str(q)+" divided by "+str(b)+" is "+str(i))
Output
Enter dividend: 10
Enter divisor: 5
Result: 10 divided by 5 is 2
C Program
#include<stdio.h>
void main()
{
int a,b,i=0,q;
printf("Enter the dividend and divisor :");
scanf("%d%d",&a,&b);
q=a;
while(a>=b){
a=a-b;
i++;
}
printf("Result: %d / %d = %d",q,b,i);
}
Output
Enter the dividend and divisor :9
3
Result: 9 / 3 = 3
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.