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

In this question, you will explore different common uses of modulus (%) operator

ID: 441100 • Letter: I

Question

In this question, you will explore different common uses of modulus (%) operator. 1. Extract individual digits of an integer. ? Declare and initialize an integer with 12345 as value. ? Output the value of 12345 / 100 % 10. 2. Test divisibility of a number. ? Output the value of 12345 % 3, 12345 % 4 and 12345 % 5 respectively. ? If the value is 0, it means that the value on the left is divisible by the number on the right. ? If the value is any value other than 0, it means the value on the left is NOT divisible by the number on the right.

Explanation / Answer

#include<iostream>
using namespace std;

int mian(){
//1
int num=12345;
cout<<"12345/100%10 =" <<num/100%10<<endl;

//2.
cout<<"12345 % 3 = "<<num % 3<<endl;
cout<< "12345 % 4= "<<num % 4<<endl;
cout<<"12345 % 5 = " <<num % 5<<endl;

return 0;

}

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