Lecture 4
Constants and variables
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
cout << "
This is the number of two : 2" << endl;//String
cout << "
This is the number of two : "<< 2 << endl;//constants
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Integer type variables:
It is
range of two byte.
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int i; //Declaring
i=2; //Initializing
cout << "
This is the number of two : "<< i << endl;
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Unsigned Integer type variables:
Code:
#include
<iostream>
#include
<conio.h>
using
namespace std;
int
main (int argc, char *argv[])
{
unsigned int i; //Declaring
i=2;// //Initializing
cout << " This is the number of
two : "<< i << endl;
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Code Exp1:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int AmerAge=30, AmaraAge=29;
//Declaring & Initializing
cout << "This is the
Amer Age: "<<AmerAge<<endl
<< "And the
Amara Age: "<<AmaraAge<<"\n";
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10
Code Exp2:
#include <iostream>
#include <conio.h>
using namespace std;
int main (int argc, char *argv[])
{
int numbertable, multipliertable
; //Declaring & Initializing
cout << "Please enter
the number for which you want a table :
";
cin>>numbertable;
cout<< "Please enter
the multiplier to which you want a table : ";
cin>>multipliertable;
cout<<"\n"<<numbertable<<" X
"<<multipliertable<<" = "
<<numbertable*multipliertable;
getch();
return 0;
}
Code view in dev compiler:
Compile the program Ctrl+F9
Run program Ctrl+F10