Page 20 - Modular_V1.1_Flipbook
P. 20
MORE SOLVED PROGRAMS
Program 3: To swap the values of two variables without using third variable.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a, b;
a = 10;
b = 20;
cout<<”Values of a and b before swapping are “<<a<< “ and “ <<b<< “.\n”;
a = a + b;
b = a - b;
a = b - a;
cout<<”Values of a and b after swapping are “<<a<< “ and “ <<b<< “.”;
getch();
}
Preceding program shows the same output as Program 1.
Program 4: To calculate the area of a circle of radius 5 cm.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int radius = 5;
float pi = 3.14, area = 0;
area = pi * radius * radius;
cout<<”Area of circle is: “<<area;
getch();
}
Recap
A character set refers to the letters, digits or special symbols that can be used to write programs
in C++ language.
Tokens are the smallest individual units of a C++ program.
Keywords are the reserved words which cannot be used as variable names as they carry a
special meaning for the compiler.
A data type specifies the type of value a variable can contain.
18 Touchpad MODULAR (Version 1.1)-X

