C++:Use the Modulus(%) Operator to get reminder

Printer-friendly versionSend to friend

Use the Modulus(%) Operator to get reminder

#include<iostream.h>            //Header File for console input and output
#include<conio.h>                      //Header File for getch()
        
void main()
{       
        int a,b;                
        a=5;                                         //Initializing the value.
        b=2;                                         //Use Cin>> to input via Keyboard.
        
        int c=a%b;
        
        cout<<"When you divide "<<a<<" by "<<b<<" the reminder is "<<c<<".";    
        
        getch();                //Press any key to return
}

Ouput: When you divide 5 by 2 the reminder is 1.

Syndicate content