Page 25 - Modular_V1.1_Flipbook
P. 25

Clickipedia




                   The difference between ‘/’ and ‘%’ operators is that ‘/’ operator gives the quotient and ‘%’
                   operator gives the remainder obtained during division.


                 Program 1: To perform arithmetic operations.
                 #include<iostream.h>
                 #include<conio.h>

                 void main()
                 {
                 int a, b, sum, sub, mul, divs;
                 a = 20, b= 5;

                 sum = a + b;
                 clrscr();
                 cout<<”Addition result is : “ << sum <<”\n”;
                 sub = a - b;
                 cout<<”Subtraction result is : “ << sub <<”\n”;
                 mul = a * b;

                 cout<<”Multiplication result is : “ << mul <<”\n”;
                 divs = a / b;
                 cout<<”Division result is : “ << divs <<”\n”;
                 getch();

                 }
                 Program 2: To convert the given time into hours and minutes.
                 #include<iostream.h>
                 #include<conio.h>
                 void main()

                 {
                 int t, h, m;
                 t = 500;
                 clrscr();

                 cout<<”Time in minutes is: “<< t<<”\n”;
                 h = t / 60;
                 m = t % 60;
                 cout<< “Hours are: “ <<h<<”\n”;
                 cout<< “Minutes are: “ <<m;
                 getch();

                 }




                                                                                               Operators in C++   23
   20   21   22   23   24   25   26   27   28   29   30