C++ PROGRAMS
//
CONSTANTS DECLARATION
#include<iostream.h>
#include<conio.h>
void
main()
{
int
i;
char
ch;
char
str[34];
float
f;
clrscr();
cout<<"ENTER
AN INTEGER : ";
cin>>i;
cout<<"ENTER
A CHARACTER : ";
cin>>ch;
cout<<"ENTER
THE STRING : ";
cin>>str;
cout<<"ENTER
A FLOAT : ";
cin>>f;
cout<<"\nCONSTANTS
"<<endl;
cout<<"\nINTEGER
: " <<i<<endl;
cout<<"\nCHARACTER
: "<<ch<<endl;
cout<<"\nSTRING
: "<<str<<endl;
cout<<"\nFLOAT
: " <<f<<endl;
getch();
}
/*OUTPUT
ENTER
AN INTEGER : 7
ENTER
A CHARACTER : S
ENTER
THE STRING : SUNIL
ENTER
A FLOAT : 6.3
CONSTANTS
INTEGER
: 7
CHARACTER
: S
STRING
: SUNIL
FLOAT
: 6.3
*/
_____________http://sundcs.blogspot.com/____________
//
TO DISPLAY THE SIZE OF VARIOUS DATA TYPES AVAILABLE.
#include<iostream.h>
#include<conio.h>
void
main ()
{
int x=25;
clrscr
();
cout<<"sizeof(char)";
gotoxy(x,1);
cout<<sizeof(char)<<endl;
cout<<"sizeof(signed
char)"; gotoxy(x,2);
cout<<sizeof(signed
char)<<endl;
cout<<"sizeof(unsigned
char)"; gotoxy(x,3);
cout<<sizeof(unsigned
char)<<endl;
cout<<"sizeof(int)";
gotoxy(x,4);
cout<<sizeof(int)<<endl;
cout<<"sizeof(signed
int)"; gotoxy(x,5);
cout<<sizeof(signed
int)<<endl;
cout<<"sizeof(unsigned
int)"; gotoxy(x,6);
cout<<sizeof(unsigned
int)<<endl;
cout<<"sizeof(short)";
gotoxy(x,7);
cout<<sizeof(short)<<endl;
cout<<"sizeof(signed
short)"; gotoxy(x,8);
cout<<sizeof(signed
short)<<endl;
cout<<"sizeof(unsigned
short)"; gotoxy(x,9);
cout<<sizeof(unsigned
short)<<endl;
cout<<"sizeof(short
int)"; gotoxy(x,10);
cout<<sizeof(short
int)<<endl;
cout<<"sizeof(float)";
gotoxy(x,11);
cout<<sizeof(float)<<endl;
cout<<"sizeof(short
float)"; gotoxy(x,12);
cout<<sizeof(short
float)<<endl;
cout<<"sizeof(long)";
gotoxy(x,13);
cout<<sizeof(long)<<endl;
cout<<"sizeof(signed
long)"; gotoxy(x,14);
cout<<sizeof(signed
long)<<endl;
cout<<"sizeof(unsigned
long)"; gotoxy(x,15);
cout<<sizeof(unsigned
long)<<endl;
cout<<"sizeof(long
float)"; gotoxy(x,16);
cout<<sizeof(long
float)<<endl;
cout<<"sizeof(double)";
gotoxy(x,17);
cout<<sizeof(double)<<endl;
cout<<"sizeof(long
double)"; gotoxy(x,18);
cout<<sizeof(long
double)<<endl;
getch
();
}
/*OUTPUT
sizeof(char)
1
sizeof(signed
char) 1
sizeof(unsigned
char) 1
sizeof(int)
2
sizeof(signed
int) 2
sizeof(unsigned
int) 2
sizeof(short)
2
sizeof(signed
short) 2
sizeof(unsigned
short) 2
sizeof(short
int) 2
sizeof(float)
4
sizeof(short
float) 4
sizeof(long)
4
sizeof(signed
long) 4
sizeof(unsigned
long) 4
sizeof(long
float) 8
sizeof(double)
8
sizeof(long
double) 10
*/
_____________________http://sundcs.blogspot.com/_________________
//
EMPLOYEES DETAILS
#include<iostream.h>
#include<conio.h>
void
main()
{
int
eno;
char
grade;
char
name[25];
float
comm;
clrscr();
cout<<"ENTER
EMPLOYEE NAME : ";
cin.getline(name,25);
cout<<"\nENTER
EMPLOYEE NUMBER : ";
cin>>eno;
cout<<"\nENTER
EMPLOYEE GRADE : ";
cin>>grade;
cout<<"\nENTER
EMPLOYEE COMMISION : ";
cin>>
comm;
clrscr();
cout<<
"EMPLOYEE DETAILS: "<<endl;
cout<<
"EMPLOYEE NAME : " <<name<<endl;
cout<<"EMPLOYEE
NUMBER : "<<eno<<endl;
cout<<"EMPLOYEE
GRADE : "<<grade<<endl;
cout<<"EMPLOYEE
COMMISSION : " <<comm<<endl;
getch();
}
/*OUTPUT
ENTER
EMPLOYEE NAME : RAM AIRAN
ENTER
EMPLOYEE NUMBER : 7
ENTER
EMPLOYEE GRADE : A
ENTER
EMPLOYEE COMMISION : 7000
EMPLOYEE
DETAILS:
EMPLOYEE
NAME : RAM AIRAN
EMPLOYEE
NUMBER : 7
EMPLOYEE
GRADE : A
EMPLOYEE
COMMISSION : 7000
*/
_____________________http://sundcs.blogspot.com/_________________
//TO
FIND THE SUM OF TWO NUMBERS
#include<iostream.h>
#include<conio.h>
void
main ()
{
int
no1,no2,sum;
clrscr();
cout<<"ENTER
FIRST NUMBER : ";
cin>>no1;
cout<<"ENTER
SECOND NUMBER :";
cin>>no2;
sum=no1+no2;
cout<<"THE
SUM OF TWO NUMBER : "<<sum;
getch();
}
/*OUTPUT
ENTER
FIRST NUMBER : 25
ENTER
SECOND NUMBER :18
THE
SUM OF TWO NUMBERS : 43
*/
_____________________http://sundcs.blogspot.com/_________________
//TO
FIND THE DIFFERENCE BETWEEN TWO NUMBERS
#include<iostream.h>
#include<conio.h>
void
main()
{
int
no1,no2,difference;
clrscr();
cout<<"ENTER
THE FIRST NUMBER : ";
cin>>
no1;
cout<<"\nENTER
THE SECOND NUMBER : ";
cin>>no2;
difference=no1-no2;
cout<<"\nTHE
DIFFERENCE OF TWO NUMBERS IS : "<<difference;
getch();
}
/*OUTPUT
ENTER
THE FIRST NUMBER : 63
ENTER
THE SECOND NUMBER : 45
THE
DIFFERENCE OF TWO NUMBERS IS : 18
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO DISPLAY PRODUCT OF TWO NUMBERS
#include<iostream.h>
#include<conio.h>
void
main()
{
int
num1, num2, prod;
clrscr();
cout<<"ENTER
THE FIRST NUMBER : ";
cin
>> num1;
cout<<"ENTER
THE SECOND NUMBER : ";
cin>>num2;
prod=num1*num2;
cout<<"THE
PRODUCT OF THE NUMBERS IS : " <<prod;
getch();
}
/*OUTPUT
ENTER
THE FIRST NUMBER : 25
ENTER
THE SECOND NUMBER : 18
THE
PRODUCT OF THE NUMBERS IS : 450
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO DIVIDE A NUMBER WITH ANOTHER
#include<iostream.h>
#include<conio.h>
void
main()
{
float
quotient, remainder;
int
no1,no2;
clrscr();
cout<<"\nENTER
THE DIVIDEND : ";
cin>>
no1;
cout<<"\nENTER
THE DIVISOR : ";
cin>>no2;
quotient=no1/no2;
remainder=no1%no2;
cout<<"\nTHE
QUOTIENT IS "<<quotient;
cout<<"\n\nTHE
REMAINDER IS "<<remainder;
getch();
}
/*
OUTPUT
ENTER
THE DIVIDEND : 87
ENTER
THE DIVISOR : 23
THE
QUOTIENT IS 3
THE
REMAINDER IS 18
*/
_____________________http://sundcs.blogspot.com/_________________
//SQUARE
OF A NUMBER
#include<iostream.h>
#include<conio.h>
void
main ()
{
int
num, sqr;
clrscr
();
cout
<< "ENTER A NUMBER : ";
cin
>> num;
sqr=
num*num;
cout
<< "\nTHE SQUARE OF " << num << " is "
<< sqr;
getch
();
}
/*OUTPUT
ENTER
A NUMBER : 18
THE
SQUARE OF 18 is 324
ENTER
A NUMBER : 25
THE
SQUARE OF 25 is 625
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO FIND THE AREA OF RECTANGLE
#include<iostream.h>
#include<conio.h>
void
main()
{
float
l,b,area;
clrscr();
cout<<
"AREA OF RECT ";
cout<<"\n\nENTER
LENGTH : ";
cin>>
l;
cout<<"\nENTER
BREADTH : ";
cin>>
b;
area=l*b;
cout<<"\nTHE
AREA OF THE RECTANGLE WITH GIVEN PARAMETERS IS : "<<area;
getch();
}
/*OUTPUT
AREA
OF RECT
ENTER
LENGTH : 12
ENTER
BREADTH : 23
THE
AREA OF THE RECTANGLE WITH GIVEN PARAMETERS IS : 276
*/
_____________________http://sundcs.blogspot.com/_________________
//
AREA OF A TRIANGLE
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
long
float height, base, area;
cout<<"\nPLEASE
ENTER THE HEIGHT FOR THE TRAINGLE : ";
cin>>height;
cout<<"\nPLEASE
ENTER THE BASE FOR THE TRIANGLE : ";
cin>>base;
area=base*height*0.5;
cout<<"\nTHE
AREA OF THE TRIANGLE IS : "<<area;
getch();
}
/*
OUTPUT
a)
PLEASE
ENTER THE HEIGHT FOR THE TRAINGLE : 10
PLEASE
ENTER THE BASE FOR THE TRIANGLE : 20
THE
AREA OF THE TRIANGLE IS : 100
b)
PLEASE
ENTER THE HEIGHT FOR THE TRAINGLE : 12
PLEASE
ENTER THE BASE FOR THE TRIANGLE : 17
THE
AREA OF THE TRIANGLE IS : 102
c)
PLEASE
ENTER THE HEIGHT FOR THE TRAINGLE : 29
PLEASE
ENTER THE BASE FOR THE TRIANGLE : 37
THE
AREA OF THE TRIANGLE IS : 536.5
d)
PLEASE
ENTER THE HEIGHT FOR THE TRAINGLE : 13
PLEASE
ENTER THE BASE FOR THE TRIANGLE : 93
THE
AREA OF THE TRIANGLE IS : 604.5
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO FIND THE VOLUME OF A SPHERE
#include<iostream.h>
#include<conio.h>
void
main()
{
float
r,vol;
clrscr();
cout<<
"VOLUME OF A SPHERE";
cout<<"\n\nENTER
RADIUS : ";
cin>>
r;
vol=((4/3)*(22/7)*r*r*r);
cout<<"\nTHE
VOLUME OF THE SPHERE WITH GIVEN PARAMETERS IS : "<<vol;
getch();
}
/*OUTPUT
VOLUME
OF A SPHERE
ENTER
RADIUS : 7
THE
VOLUME OF THE SPHERE WITH GIVEN PARAMETERS IS : 1432.4366
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO FIND THE TEMPERATURE IN CELSIUS FROM KELVIN
#include<iostream.h>
#include<conio.h>
void
main()
{
int
a,c;
clrscr();
cout
<< "ENTER TEMPERATURE IN DEGREE CELSIUS : ";
cin
>> a;
c=a+273;
cout
<< "\nTEMPERATURE IN KELVIN : " << c;
getch();
}
/*OUTPUT
ENTER
TEMPERATURE IN DEGREE CELSIUS : 100
TEMPERATURE
IN KELVIN : 373
*/
_____________________http://sundcs.blogspot.com/_________________
//A
PROGRAM TO FIND SIMPLE INTEREST
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
int
principal,time,rate,interest;
cout<<"\n
ENTER PRINCPAL : ";
cin>>principal;
cout<<"\n
ENTER DURATION : ";
cin>>time;
cout<<"\n
ENTER RATE OF INTEREST :";
cin>>rate;
interest=(principal*time*rate)/100;
cout<<"\n
SIMPLE INTEREST : "<<interest;
getch();
}
_____________________http://sundcs.blogspot.com/_________________
//
PLAYER DETAILS
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
float
runs1, runs2, runs3, runs4, runs5, balls1, balls2, balls3, balls4, balls5;
long
double sr1, sr2, sr3, sr4, sr5, avgsr; char name[30];
cout
<<"\nENTER PLAYER NAME : ";
cin.getline(name,30);
cout<<"\nENTER
RUNS SCORED IN MATCH 1: ";
cin>>runs1;
cout<<"\nENTER
BALLS PLAYED BY PLAYER IN MATCH 1: ";
cin
>> balls1;
sr1=(runs1*100)/balls1;
cout<<"\nENTER
RUNS SCORED IN MATCH 2: ";
cin>>runs2;
cout<<"\nENTER
BALLS PLAYED BY PLAYER IN MATCH 2: ";
cin
>> balls2;
sr2=(runs2*100)/balls2;
cout<<"\nENTER
RUNS SCORED IN MATCH 3: ";
cin>>runs3;
cout<<"\nENTER
BALLS PLAYED BY PLAYER IN MATCH 3: ";
cin
>> balls3;
sr3=(runs3*100)/balls3;
cout<<"\nENTER
RUNS SCORED IN MATCH 4: ";
cin>>runs4;
cout<<"\nENTER
BALLS PLAYED BY PLAYER IN MATCH 4: ";
cin
>> balls4;
sr4=(runs4*100)/balls4;
cout<<"\nENTER
RUNS SCORED IN MATCH 5: ";
cin>>runs5;
cout<<"\nENTER
BALLS PLAYED BY PLAYER IN MATCH 5: ";
cin
>> balls5;
sr5=(runs5*100)/balls5;
avgsr=(sr1+sr2+sr3+sr4+sr5)/5;
clrscr();
cout<<"\nPLAYER
NAME : "<< name <<endl;
cout<<"\nRUNS
SCORED IN MATCH1 : "<< runs1 <<endl;
cout<<"\nBALLS
PLAYED IN MATCH1 : "<< balls1<<endl;
cout<<"\nMATCH1
STRIKE RATE : " << sr1<<endl;
cout<<"\nRUNS
SCORED IN MATCH2 : "<< runs2 <<endl;
cout<<"\nBALLS
PLAYED IN MATCH2 : "<< balls2<<endl;
cout<<"\nMATCH2
STRIKE RATE : " << sr2<<endl;
cout<<"\nRUNS
SCORED IN MATCH3 : "<< runs3 <<endl;
cout<<"\nBALLS
PLAYED IN MATCH3 : "<< balls3<<endl;
cout<<"\nMATCH3
STRIKE RATE : " << sr3<<endl;
cout<<"\nRUNS
SCORED IN MATCH4 : "<< runs4 <<endl;
cout<<"\nBALLS
PLAYED IN MATCH4 : "<< balls4<<endl;
cout<<"\nMATCH4
STRIKE RATE : " << sr4<<endl;
cout<<"\nRUNS
SCORED IN MATCH5 : "<< runs5 <<endl;
cout<<"\nBALLS
PLAYED IN MATCH5 : "<< balls5<<endl;
cout<<"\nMATCH5
STRIKE RATE : " << sr5<<endl;
cout<<"\nAVERAGE
STRIKE RATE : " <<avgsr<<endl;
getch();
}
/*OUTPUT
ENTER
PLAYER NAME : RAHUL DRAVID
ENTER
RUNS SCORED IN MATCH 1: 87
ENTER
BALLS PLAYED BY PLAYER IN MATCH 1: 95
ENTER
RUNS SCORED IN MATCH 2: 99
ENTER
BALLS PLAYED BY PLAYER IN MATCH 2: 112
ENTER
RUNS SCORED IN MATCH 3: 76
ENTER
BALLS PLAYED BY PLAYER IN MATCH 3: 65
ENTER
RUNS SCORED IN MATCH 4: 51
ENTER
BALLS PLAYED BY PLAYER IN MATCH 4: 23
ENTER
RUNS SCORED IN MATCH 5: 124
ENTER
BALLS PLAYED BY PLAYER IN MATCH 5: 157
PLAYER
NAME : RAHUL DRAVID
RUNS
SCORED IN MATCH1 : 87
BALLS
PLAYED IN MATCH1 : 95
MATCH1
STRIKE RATE : 91.578947
RUNS
SCORED IN MATCH2 : 99
BALLS
PLAYED IN MATCH2 : 112
MATCH2
STRIKE RATE : 88.392857
RUNS
SCORED IN MATCH3 : 76
BALLS
PLAYED IN MATCH3 : 65
MATCH3
STRIKE RATE : 116.923077
RUNS
SCORED IN MATCH4 : 51
BALLS
PLAYED IN MATCH4 : 23
MATCH4
STRIKE RATE : 221.73913
RUNS
SCORED IN MATCH5 : 124
BALLS
PLAYED IN MATCH5 : 157
MATCH5
STRIKE RATE : 78.980892
AVERAGE
STRIKE RATE : 119.522981
*/
_____________________http://sundcs.blogspot.com/_________________
//SWAPPING
INTEGERS
#include<iostream.h>
#include<conio.h>
void
main()
{
int
a, b, c;
clrscr();
cout<<"\aENTER
A : ";
cin>>a;
cout<<"\aENTER
B : ";
cin>>b;
c=a;
a=b;
b=c;
cout<<"\n\aNEW
A= \a"<<a;
cout<<"\n\aNEW
B= \a"<<b;
getch();
}
/*OUTPUT
ENTER
A : 23
ENTER
B : 34
NEW
A= 34
NEW
B= 23
*/
_____________________http://sundcs.blogspot.com/_________________
//
CLASSIFY THE TOTAL NUMBER OF DAYS INPUT INTO YEAR, WEEK AND DAYS
#include<iostream.h>
#include<conio.h>
void
main()
{
long
num, temp, days, week, year;
char
ch;
do
{
clrscr();
cout<<"ENTER
THE TOTAL NUMBER OF DAYS : ";
cin>>num;
year=num/365;
temp=num%365;
week=temp/7;
days=temp%7;
cout<<"\n"<<year<<"
years " << week << " weeks " << days <<
" days.";
cout<<"\n\nRepeat?
(y/n) : ";
cin>>ch;
}while(ch=='y'||ch=='Y');
}
/*OUTPUT
a)
ENTER
THE TOTAL NUMBER OF DAYS : 2325
6
years 19 weeks 2 days.
Repeat?
(y/n) : y
b)
ENTER
THE TOTAL NUMBER OF DAYS : 167
0
years 23 weeks 6 days.
Repeat?
(y/n) : y
c)
ENTER
THE TOTAL NUMBER OF DAYS : 4598
12
years 31 weeks 1 days.
Repeat?
(y/n) : y
d)
ENTER
THE TOTAL NUMBER OF DAYS : 356
0
years 50 weeks 6 days.
Repeat?
(y/n) : y
*/
_____________________http://sundcs.blogspot.com/_________________
//TERNARY
OPERATOR
#include<iostream.h>
#include<conio.h>
void
main()
{
int
count=0;
int
num1=7, num2=4;
clrscr();
count=(num1<num2)?num1:num2;
cout<<count;
getch();
}
/*OUTPUT
4
*/
_____________________http://sundcs.blogspot.com/_________________
//NESTED
TERNARY OPERATOR
#include<iostream.h>
#include<conio.h>
void
main()
{
int
count=0;
int
num1=2;
clrscr();
count=(num1<0)?-1:(num1>0)?7:9;
cout<<count;
getch();
}
/*OUTPUT
7
*/
_____________________http://sundcs.blogspot.com/_________________
//
FIND THE GREATER OF TWO GIVEN NUMBERS
#include<iostream.h>
#include<conio.h>
void
main()
{
int
num1, num2;
clrscr
();
cout
<< "PLEASE ENTER THE FIRST NUMBER : ";
cin
>> num1;
cout
<< "PLEASE ENTER THE SECOND NUMBER : ";
cin
>> num2;
if
(num1>num2)
{
cout
<< "1st NUMBER IS GREATER.";
}
else
{
cout
<< "2nd NUMBER IS GREATER.";
}
getch
();
}
/*OUTPUT
PLEASE
ENTER THE FIRST NUMBER : 787
PLEASE
ENTER THE SECOND NUMBER : 657
1st
NUMBER IS GREATER.
PLEASE
ENTER THE FIRST NUMBER : 874
PLEASE
ENTER THE SECOND NUMBER : 897
2nd
NUMBER IS GREATER.
*/
_____________________http://sundcs.blogspot.com/_________________
//GREATER
OF THREE NUMBERS
#include<iostream.h>
#include<conio.h>
void
main()
{
int
a, b, c;
clrscr();
cout<<"ENTER
NUMBER1 : ";
cin>>a;
cout<<"ENTER
NUMBER2 : ";
cin>>b;
cout<<"ENTER
NUMBER3 : ";
cin>>c;
if(a>b
&& a>c && b>c)
{
cout<<a<<"
IS GREATEST."<<endl;
cout<<b<<"
IS SECOND GREATEST."<<endl;
cout<<c<<"
IS LEAST.";
}
else
if(a>b && a>c && c>b)
{
cout<<a<<"
IS GREATEST."<<endl;
cout<<c<<"
IS SECOND GREATEST."<<endl;
cout<<b<<"
IS LEAST.";
}
else
if(b>a && b>c && a>c)
{
cout<<b<<"
IS GREATEST."<<endl;
cout<<a<<"
IS SECOND GREATEST."<<endl;
cout<<c<<"
IS LEAST.";
}
else
if(a>b && a>c && c>a)
{
cout<<b<<"
IS GREATEST."<<endl;
cout<<c<<"
IS SECOND GREATEST."<<endl;
cout<<a<<"
IS LEAST.";
}
else
if(c>a && c>b && b>a)
{
cout<<c<<"
IS GREATEST."<<endl;
cout<<b<<"
IS SECOND GREATEST."<<endl;
cout<<a<<"
IS LEAST.";
}
else
if(c>a && c>b && a>b)
{
cout<<c<<"
IS GREATEST."<<endl;
cout<<a<<"
IS SECOND GREATEST."<<endl;
cout<<b<<"
IS LEAST.";
}
else
cout<<"INVALID
INPUT.";
getch();
}
/*OUTPUT
ENTER
NUMBER1 : 12
ENTER
NUMBER2 : 23
ENTER
NUMBER3 : 34
34
IS GREATEST.
23
IS SECOND GREATEST.
12
IS LEAST.
ENTER
NUMBER1 : 12
ENTER
NUMBER2 : 9
ENTER
NUMBER3 : 23
23
IS GREATEST.
12
IS SECOND GREATEST.
9
IS LEAST.
ENTER
NUMBER1 : 45
ENTER
NUMBER2 : 34
ENTER
NUMBER3 : 32
45
IS GREATEST.
34
IS SECOND GREATEST.
32
IS LEAST.
*/
_____________________http://sundcs.blogspot.com/_________________
//
A PROGRAM IN C LANGUAGE TO FIND THE GREATEST AMONG THREE NUMBERS
#include<stdio.h>
#include<conio.h>
void
main()
{
int
num1,num2,num3;
clrscr();
printf("\nEnter
the value for first number : ");
scanf("%d",&num1);
printf("\nEnter
the value for second number : ");
scanf("%d",&num2);
printf("\nEnter
the value for third number : ");
scanf("%d",&num3);
if(num1>num2&&num1>num3)
printf("
%d is greatest.",num1);
else
{
if(num2>num1&&num2>num3)
printf("\n%d
is greatest.",num2);
else
printf("\n%d
is greatest.",num3);
}
getch();
}
/*
OUTPUT
a)
Enter
the value for first number : 23
Enter
the value for second number : 12
Enter
the value for third number : 986
986
is greatest.
b)
Enter
the value for first number : 349
Enter
the value for second number : 233
Enter
the value for third number : 31
349
is greatest.
c)
Enter
the value for first number : 573
Enter
the value for second number : 847
Enter
the value for third number : 239
847
is greatest.
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO FIND IF A YEAR INPUT IS LEAP OR NOT
#include<iostream.h>
#include<conio.h>
void
main ()
{
clrscr
();
int
year;
cout
<< "ENTER A YEAR : ";
cin
>> year;
if(year%400==0
|| (year%4==0 && year%100!=0))
{
cout
<< "IT IS A LEAP YEAR.";
}
else
{
cout
<< "IT IS NOT A LEAP YEAR";
}
getch
();
}
/*OUTPUT
ENTER
A YEAR : 2004
IT
IS A LEAP YEAR.
ENTER
A YEAR : 2003
IT
IS NOT A LEAP YEAR
*/
_____________________http://sundcs.blogspot.com/_________________
//
DISPLAY MONTH CORRESPONDING TO INPUT, USING IF-ELSE CONSTRUCT
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
int
n;
cout<<"ENTER
A NUMBER LESS THAN OR EQUAL TO 12 : ";
cin>>n;
while(n>12||n<1)
{
cout<<"\nINVALID
ENTRY. PLEASE RE-ENTER YOUR CHOICE : ";
cin>>n;
}
if(n==1)
cout<<n<<"
IMPLIES JANUARY.";
else
if(n==2)
cout<<n<<"
IMPLIES FEBRUARY.";
else
if(n==3)
cout<<n<<"
IMPLIES MARCH.";
else
if(n==4)
cout<<n<<"
IMPLIES APRIL.";
else
if(n==5)
cout<<n<<"
IMPLIES MAY.";
else
if(n==6)
cout<<n<<"
IMPLIES JUNE.";
else
if(n==7)
cout<<n<<"
IMPLIES JULY.";
else
if(n==8)
cout<<n<<"
IMPLIES AUGUST.";
else
if(n==9)
cout<<n<<"
IMPLIES SEPTEMBER.";
else
if(n==10)
cout<<n<<"
IMPLIES OCTOBER.";
else
if(n==11)
cout<<n<<"
IMPLIES NOVEMBER.";
else
if(n==12)
cout<<n<<"
IMPLIES DECEMBER.";
getch();
}
/*OUTPUT
ENTER
A NUMBER LESS THAN OR EQUAL TO 12 : 11
11
IMPLIES NOVEMBER.
ENTER
A NUMBER LESS THAN OR EQUAL TO 12 : 6
6
IMPLIES JUNE.
ENTER
A NUMBER LESS THAN OR EQUAL TO 12 : 8
8
IMPLIES AUGUST.
ENTER
A NUMBER LESS THAN OR EQUAL TO 12 : 9
9
IMPLIES SEPTEMBER.
ENTER
A NUMBER LESS THAN OR EQUAL TO 12 : 12
12
IMPLIES DECEMBER.
ENTER
A NUMBER LESS THAN OR EQUAL TO 12 : 3
3
IMPLIES MARCH.
*/
_____________________http://sundcs.blogspot.com/_________________
/*SALARY
OF THE COMPUTER SALESMAN WITH CONCEPT OF DEFINING THE BASIC SALARY
AS
CONSTANT
#include<iostream.h>
#include<conio.h>
#define
basic 1500
void
main()
{
long
bonus;
long
float commision, salary, comp_no, comp_cost, sales;
char
name[25], choice;
do
{
clrscr();
cout<<"\nPLEASE
ENTER THE NAME : ";
cin>>name;
cout<<"\nPLEASE
ENTER THE NUMBER OF COMPUTERS SOLD : ";
cin>>comp_no;
cout<<"\nPLEASE
ENTER THE COST OF 1 COMPUTER : ";
cin>>comp_cost;
sales=comp_no*comp_cost;
bonus=comp_no*200;
commision=(sales*2)/100;
salary=bonus+commision+basic;
cout<<"\t\t\t\t*S.J.
COMPUTERS*\n";
cout<<"\n\nTOTAL
SALES OF S.J. COMPUTERS : "<<sales;
cout<<"\n\nBASIC
SALARY OF " << name << " : " << basic;
cout<<"\n\nCOMMISION
OF " << name << " : " << commision;
cout<<"\n\nBONUS
OF " << name << " : " << bonus;
cout<<"\n\nNET
SALARY OF " << name << " : " << salary;
cout<<"\n\nPRESS
Y TO REPEAT ELSE EXIT PRESSING ANY KEY : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*
OUTPUT
PLEASE
ENTER THE NAME : Rachit
PLEASE
ENTER THE NUMBER OF COMPUTERS SOLD : 25
PLEASE
ENTER THE COST OF 1 COMPUTER : 30000
*S.J.
COMPUTERS*
TOTAL
SALES OF S.J. COMPUTERS : 750000
BASIC
SALARY OF Rachit : 1500
COMMISION
OF Rachit : 15000
BONUS
OF Rachit : 5000
NET
SALARY OF Rachit : 21500
PRESS
Y TO REPEAT ELSE EXIT PRESSING ANY KEY : N
*/
_____________________http://sundcs.blogspot.com/_________________
//
SALARY FOR AN EMPLOYEE TO BE HIRED FOR A
#include<iostream.h>
#include<conio.h>
void
main()
{
float
age, sal;
char
name[25], exp, choice;
do
{
clrscr();
cout<<"ENTER
NAME : ";
cin>>name;
cout<<"FRESHER
OR EXPERIENCED? (F/E) : ";
cin>>exp;
while(exp!='e'&&
exp!='E'&& exp!='f'&& exp!='F')
{
cout<<"INVALID
INPUT!! PLEASE RE-ENTER THE EXPERIENCE : ";
cin>>exp;
}
cout<<"ENTER
AGE : ";
cin
>>age;
if(exp=='e'||exp=='E')
{
if
(age>=35)
cout<<"MR.
" << name << " YOUR SALARY IS : 10000";
else
if ( age>28 && age <35)
cout<<"MR.
" << name << " YOUR SALARY IS : 7000";
else
cout<<"SORRY
!! YOU ARE NOT ELIGIBLE FOR THE JOB.";
}
else
{
if(age>=28
&& age<=35)
cout<<"MR.
" << name << " YOUR SALARY IS : 4000";
else
cout<<"SORRY
!! YOU ARE NOT ELIGIBLE FOR THE JOB.";
}
cout<<"\nDO
YOU WANT TO CONTINUE? (y/n) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*
OUTPUT
a)
ENTER
NAME : Rachit
FRESHER
OR EXPERIENCED? (F/E) : f
ENTER
AGE : 34
MR.
Rachit YOUR SALARY IS : 4000
DO
YOU WANT TO CONTINUE? (y/n) : y
b)
ENTER
NAME : Rachit
FRESHER
OR EXPERIENCED? (F/E) : f
ENTER
AGE : 27
SORRY
!! YOU ARE NOT ELIGIBLE FOR THE JOB.
DO
YOU WANT TO CONTINUE? (y/n) : y
c)
ENTER
NAME : rachit
FRESHER
OR EXPERIENCED? (F/E) : f
ENTER
AGE : 35
SORRY
!! YOU ARE NOT ELIGIBLE FOR THE JOB.
DO
YOU WANT TO CONTINUE? (y/n) : n
d)
ENTER
NAME : Rachit
FRESHER
OR EXPERIENCED? (F/E) : e
ENTER
AGE : 30
MR.
Rachit YOUR SALARY IS : 7000
DO
YOU WANT TO CONTINUE? (y/n) : y
e)
ENTER
NAME : Rachit
FRESHER
OR EXPERIENCED? (F/E): e
ENTER
AGE : 37
MR.
Rachit YOUR SALARY IS : 10000
DO
YOU WANT TO CONTINUE? (y/n) : y
f)
ENTER
NAME : Rachit
FRESHER
OR EXPERIENCED? (F/E) : e
ENTER
AGE : 28
SORRY
!! YOU ARE NOT ELIGIBLE FOR THE JOB.
DO
YOU WANT TO CONTINUE? (y/n) : n
*/
_____________________http://sundcs.blogspot.com/_________________
//ROUNDING
OFF NUMBERS TO TENS PLACE
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
int
n;
float
a, b;
cout<<"\nENTER
THE NUMBER TO BE ROUNDED OFF : ";
cin>>n;
a=n-(n%10);
b=a+10;
if(n%10<5)
cout<<"\n"<<n<<"
WHEN ROUNDED OFF = "<<a;
else
if(n%10>=5)
cout<<"\n"<<n<<"
WHEN ROUNDED OFF = "<<b;
getch();
}
/*OUTPUT
ENTER
THE NUMBER TO BE ROUNDED OFF : 18
18
WHEN ROUNDED OFF = 20
ENTER
THE NUMBER TO BE ROUNDED OFF : 25
25
WHEN ROUNDED OFF = 30
*/
_____________________http://sundcs.blogspot.com/_________________
//
TO FIND THE ROOTS OF A QUADRATIC EQUATION
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<process.h>
void
main()
{
float
a,b,c,root1,root2,delta;
char
choice;
do
{
clrscr();
cout<<"ENTER
THE VALUES FOR THE VARIABLESIN EQUATION : ax^2 + bx + c :";
cout<<"\nENTER
a : ";
cin>>a;
cout<<"\nENTER
b : ";
cin>>b;
cout<<"\nENTER
c : ";
cin>>c;
if(!a)
{
cout<<"\nINVALID
ENTRY FOR a.";
exit(0);
}
delta=(b*b)-(4*a*c);
if(delta<0)
cout<<"\nIMAGINARY
AND COMPLEX ROOTS.";
else
if (delta>0)
{
root1=(-b+sqrt(delta))/(2*a);
root2=(-b-sqrt(delta))/(2*a);
cout<<"\nROOTS
ARE REAL AND UNEQUAL."<<endl;
cout<<"\nROOTS
ARE : " << root1 << "\t" <<root2;
}
else
if(delta==0)
{
root1=(-b/(2*a));
root2=root1;
cout<<"\nROOTS
ARE REAL AND EQUAL."<<endl;
cout<<"\nROOTS
ARE : " << root1 << "\t" <<root2;
}
cout<<"\n\nDO
YOU WANT TO CONTINUE (Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*OUTPUT
ENTER
THE VALUES FOR THE VARIABLESIN EQUATION : ax^2 + bx + c :
ENTER
a : 3
ENTER
b : 5
ENTER
c : 2
ROOTS
ARE REAL AND UNEQUAL.
ROOTS
ARE : -0.666667 -1
DO
YOU WANT TO CONTINUE (Y/N) : n
*/
_____________________http://sundcs.blogspot.com/_________________
//
MONTH DISPLAY USING SWITCH
#include<iostream.h>
#include<conio.h>
void
main()
{
int
m;
clrscr();
cout<<"ENTER
A NUMBER : ";
cin>>m;
while(m>12||m<1)
{
cout<<"INVALID
ENTRY. RE-ENTER YOUR CHOICE : ";
cin>>m;
}
switch(m)
{
case
1 : cout<<"JANUARY"; break;
case
2 : cout<<"FEBRUARY"; break;
case
3 : cout<<"MARCH"; break;
case
4 : cout<<"APRIL"; break;
case
5 : cout<<"MAY"; break;
case
6 : cout<<"JUNE"; break;
case
7 : cout<<"JULY"; break;
case
8 : cout<<"AUGUST"; break;
case
9 : cout<<"SEPTEMBER"; break;
case
10 : cout<<"OCTOBER"; break;
case
11 : cout<<"NOVEMBER"; break;
case
12 : cout<<"DECEMBER"; break;
}
getch();
}
/*OUTPUT
ENTER
A NUMBER : 11
NOVEMBER
ENTER
A NUMBER : 6
JUNE
ENTER
A NUMBER : 8
AUGUST
ENTER
A NUMBER : 9
SEPTEMBER
ENTER
A NUMBER : 3
MARCH
*/
_____________________http://sundcs.blogspot.com/_________________
//DISPLAY
MEANING OF GRADES USING SWICH CASE STRUCTURE
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
char
ch;
cout<<"ENTER
GRADE : ";
cin>>ch;
switch(ch)
{
case
'a':
case
'A':
cout<<"\nEXCELLENT"<<endl;
break;
case
'b':
case
'B':
cout<<"\nGOOD"<<endl;
break;
case
'c':
case
'C':
cout<<"\nO.K."<<endl;
break;
case
'd':
case
'D':
cout<<"\nPOOR"<<endl;
break;
default:
cout<<"\nINVALID
GRADE :"<<endl;
}
getch();
}
/*OUTPUT
ENTER
GRADE : A
EXCELLENT
ENTER
GRADE : B
GOOD
ENTER
GRADE : C
O.K.
ENTER
GRADE : d
POOR
ENTER
GRADE : E
INVALID
GRADE :
*/
_____________________http://sundcs.blogspot.com/_________________
//
SIMPLE CALCULATOR FOR 2 FRACTIONS
#include<iostream.h>
#include<conio.h>
#include<process.h>
void
main()
{
float
num1,num2,den1,den2,result; char sign, choice;
do
{
clrscr();
cout<<"FRACTION
1 : "<<endl;
cout<<"\nENTER
THE NUMERATOR : "; cin>>num1;
cout<<"\nENTER
THE DENOMINATOR : "; cin>>den1;
cout<<"\nENTER
THE CALCULATION OPERATOR (+, -, *, /) : ";
cin>>sign;
cout<<"\nFRACTION
2 : "<<endl;
cout<<"\nENTER
THE NUMERATOR : "; cin>>num2;
cout<<"\nENTER
THE DENOMINATOR : "; cin>>den2;
if(num1==0
|| num2==0 || den1==0 || den2==0)
{
cout<<"\nOOPS!!! INVALID ENTRY. BYE! "; exit(0); }
switch(sign)
{
case '+': result=((num1/den1)+(num2/den2)); break;
case
'-': result=((num1/den1)-(num2/den2)); break;
case
'*': result=((num1/den1)*(num2/den2)); break;
case
'/': result=((num1/den1)/(num2/den2)); break;
default
:
cout<<"\nOOPS!!!INVALID
CALCULATION OPERATOR. BYE!!";
exit(0);
}
cout<<"\nRESULT
IS : "<<result;
cout<<"\n\nDO
YOU WISH TO RE-EXECUTE THE PROGRAM? (Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*OUTPUT
FRACTION
1 :
ENTER
THE NUMERATOR : 12
ENTER
THE DENOMINATOR : 23
ENTER
THE CALCULATION OPERATOR (+, -, *, /) : *
FRACTION
2 :
ENTER
THE NUMERATOR : 12
ENTER
THE DENOMINATOR : 23
RESULT
IS : 0.272212
DO
YOU WISH TO RE-EXECUTE THE PROGRAM? (Y/N) : n
*/
_____________________http://sundcs.blogspot.com/_________________
//PREDICT
THE DAY ON WHICH A GIVEN DATE FALLS
#include<iostream.h>
#include<conio.h>
void
main()
{
long
x, num, date, month, year, julian, fours, hundreds, four_hundreds, day;char
choice;
do
{
clrscr();
cout
<< "WELCOME! \n\n\nTHE PROGRAM GUESSES THE DAY ON WHICH A GIVEN DATE
OCCURS.\n\nHERE
THE BIRTH DAY SHALL BE GUESSED AS AN EXAMPLE." << endl;
cout
<< "\n\nENTER YOUR BIRTH DATE : ";
cin>>num;
date=num/1000000;
year=num%10000;
x=num%1000000;
month=x/10000;
if
((year%100!=0 && year%4==0) || year%400==0)
julian=366;
else
julian=365;
switch(month)
{
case
1: julian -= 0;
case
2: julian -= 31;
case
3: if ( (year%100!=0 && year%4==0) || year%400==0)
julian
-= 29;
else
julian
-= 28;
case
4: julian -= 31;
case
5: julian -= 30;
case
6: julian -= 31;
case
7: julian -= 30;
case
8: julian -= 31;
case
9: julian -= 31;
case
10: julian -= 30;
case
11: julian -= 31;
case
12: julian -= 30;
}
julian+=date;
fours=(year-1)/4;
hundreds=(year-1)/100;
four_hundreds=(year-1)/400;
day=(year+julian+fours-hundreds+four_hundreds)%7;
cout<<"\nTHE
BITHDAY IS ON : ";
if(day==0)
cout<<"SATURDAY";
else
if (day==1)
cout<<"SUNDAY";
else
if (day==2)
cout<<"MONDAY";
else
if (day==3)
cout<<"TUESDAY";
else
if (day==4)
cout<<"WEDNESDAY";
else
if (day==5)
cout<<"THURSDAY";
else
cout<<"FRIDAY";
cout
<< "\n\nWOULD YOU LIKE TO CONTINUE WITH MORE DATES? (y/n) : ";
cin
>> choice;
}
while(choice=='y' || choice=='Y');
getch();
}
_____________________http://sundcs.blogspot.com/_________________
//
INCREMENT AND DECREMENT OPERATORS
#include<iostream.h>
#include<conio.h>
void
main()
{
clrscr();
int
num, a,b,c,d;
cout<<"ENTER
A NUMBER : ";
cin>>num;
a=num;
b=num;
c=num;
d=num;
cout<<"\n"<<num<<"
is assigned to a,b,c and d : "<<endl;
cout<<"++a
= " << ++a<<"\n--b = "<<
--b<<"\nc++ = " << c++<<endl;
cout<<"d--
= " << d--<<endl;
cout<<"a
= "<<a<<"\nb = "<<b<<"\nc =
"<<c<<"\nd = "<<d<<endl;
getch();
}
/*OUTPUT
ENTER
A NUMBER : 18
18
is assigned to a,b,c and d :
++a
= 19
--b
= 17
c++
= 18
d--
= 18
a
= 19
b
= 17
c
= 19
d
= 17
*/
_____________________http://sundcs.blogspot.com/_________________
//
A SAMPLE PROGRAM TO PRINT 1-100
#include<iostream.h>
#include<conio.h>
void
main ()
{
int
num;
clrscr();
for
(num=1; num<=100; num ++)
{
cout
<<num<<"\t";
}
getch
();
}
/*OUTPUT
1
2 3 4 5 6 7 8 9 10
11
12 13 14 15 16 17 18 19 20
21
22 23 24 25 26 27 28 29 30
31
32 33 34 35 36 37 38 39 40
41
42 43 44 45 46 47 48 49 50
51
52 53 54 55 56 57 58 59 60
61
62 63 64 65 66 67 68 69 70
71
72 73 74 75 76 77 78 79 80
81
82 83 84 85 86 87 88 89 90
91
92 93 94 95 96 97 98 99 100
*/
_____________________http://sundcs.blogspot.com/_________________
sir, i read all programs .these are very useful for beginners.
ReplyDelete