Respuesta :
Answer:
# The user is prompted to enter number as dividend
# The received number is assigned to userNum
userNum = int(input("Enter the number you want to divide: "))
# The user is prompted to enter number as divisor
# The divisor is assigned to x
x = int(input("Enter the number of times to divide: "))
# divideNumber function is defined to do the division
def divideNumber(userNum, x):
# counter is declared to control the loop
counter = 1
# the while-loop loop 3 times
# the division is done 3 times
while counter <= 3:
# integer division is done
# truncating the remainder part
userNum = userNum // x
# the result of the division is printed
print(userNum, end=" ")
# the counter is incremented
counter += 1
# the divideNumber function is called
# the received input is passed as parameter
# to the function
divideNumber(userNum, x)
# empty line is printed
print("\n")
Explanation:
The // operator in python works like the / operator in C. The // operator returns only the integer part of division operation. For instance 6 // 4 = 1. The fraction part is discarded.
The code below is in C
It uses a for loop to divide the userNum by x three times and prints the result of each division
Comments are used to explain each line of code
//Main.c
#include <stdio.h>
int main()
{
//Declare the variables
int userNum, x;
//Ask the user to enter the userNum and x
scanf("%d", &userNum);
scanf("%d", &x);
/*Create a for loop that iterates 3 times
Divide the userNum by x, and assign the result to userNum
Print the userNum
*/
for(int i=0; i<3; i++){
userNum /= x;
printf("%d ", userNum);
}
return 0;
}
You may read more about the loops in the following link:
brainly.com/question/14577420