Lecture 8
Boolean type variables:
It is
range of one byte.
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
bool i; //Declaring
i=true;
//Initializing
cout << "
This is true : "<< i << endl;
i=false;
//Initializing
cout << "
This is false: "<< i << endl;
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Arithmetic Instruction
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int a,b; //Declaring
a=4; b=5;
//Initializing
cout <<
" Addition : "<< a+b
<< endl;
cout <<
" Subtraction : "<< a-b
<< endl;
cout <<
" Multiplication : "<<
a*b << endl;
cout <<
" Division : "<< a/b
<< endl;
cout <<
" Modulus : "<< a%b
<< endl;
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Logical Instruction
Code AND Truth table:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
bool a,b;
a=true , b=true;
cout << " True and
True : "<< (a & b) << endl;
a=true , b=false;
cout << " True and
False : "<< (a & b) << endl;
a=false , b=true;
cout << " False and True : "<< (a & b)
<< endl;
a=false , b=false;
cout << " False and False : "<< (a & b)
<< endl;
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10