Page 89 - Modular_V1.1_Flipbook
P. 89
if(a%2 == 0)
{
cout<<”You have entered an even number. Operation is abort.”;
abort();
}
else
{
exit(0);
}
getch();
}
If you run the preceding program and enter an even number, then your program will abort abnormally
after printing the message. If you enter an odd number, then your program will terminate. You can
see the printed message by selecting the Output option from the Window menu.
MORE SOLVED PROGRAMS
2
Program 4: To calculate the value of E = mc using functions, if m = 100 kg and c = 2 m/s.
#include<iostream.h>
#include<math.h>
#include<conio.h>
void main()
{
double energy, mass, lightspeed;
clrscr();
cout<<”Enter the value of mass: “;
cin>>mass;
cout<<”Enter the speed of light: “;
cin>>lightspeed;
energy = mass * pow(lightspeed, 2);
cout<<”Energy is: “<<energy<<” Joules”;
getch();
}
Program 5: To take a character as input and check whether it is an uppercase letter. If it is an
uppercase letter, then change it into lowercase.
#include<iostream.h>
#include<ctype.h>
#include<conio.h>
void main()
{
Header Files and Library Functions 87

