C++ Programs Collection
C++ Programs Collection
CONSTANTS DECLARATION
SIZE OF DATA TYPES
EMPLOYEE DETAILS
SUM OF TWO NUMBERS
DIFFERENCE BETWEEN TWO NUMBERS
PRODUCT OF TWO NUMBERS
DIVIDE A NUMBER WITH ANOTHER
SQAURE OF A NUMBER
AREA OF RECTANGLE
AREA OF A TRIANGLE
VOLUME OF A SPHERE
CONVERT TEMPERATURE FROM KELVIN TO CELSIUS
SIMPLE INTEREST
PLAYER DETIALS
SWAPPING INTEGERS
CLASSIFY NUMBER OF DAYS IN YEARS, WEEKS AND DAYS
TERNARY OPERATOR
NESTED TERNARY OPERATOR
FIND GREATER BETWEEN TWO NUMBERS
FIND GREATER BETWEEN THREE NUMBERS
FIND GREATEST AMONG THREE NUMBERS USING C LANGUAGE
CONFIRM WHETHER LEAP YEAR OR NOT
DISPLAY MONTH USING IF-ELSE CONSTRUCT
SALARY OF A COMPUTER SALESMAN USING CONCEPT OF DEFINING VARIABLES WITH
CONSTANT DATA
SALARY FOR A NEW EMPLOYEE TO BE HIRED
GIFT AGAINST BILL AMOUNT
ROUNDING OFF NUMBERS TO TENS PLACE
FIND ROOTS OF A QUADRATIC EQUATION
DISPLAY MONTH USING SWITCH CASE
DISPLAY MEANING OF GRADES WITH SWITCH CASE STRUCTURE
SIMPLE CALCULATOR FOR TWO FRACTIONS
PREDICT THE DAY ON WHICH A GIVEN DATE FALLS
INCREMENT AND DECREMENT OPERATORS
SAMPLE PROGRAM TO PRINT 1-100 USING FOR LOOP
PRINT DIFFERENT PATTERNS
COUNT POSITIVE AND NEGATIVE INPUTS IN TEN ENTRIES
DETERMINE A PERFECT NUMBER
DETERMINE A PRIME NUMBER
PRINT A MULTIPLICATION TABLE USING DO-WHILE LOOP
PRINT A MULTIPLICATION TABLE USING FOR LOOP
REVERSE OF A NUMBER
DISPLAY SERIES : 1,2,3,4,5,6,7………n
DISPLAY SERIES : -1,4,-9,16,-25,36,-49,……...n
DISPLAY SERIES : 0,2,5,9,14,20,27,35,44,54,65…………n
DISPLAY SERIES : 2,6,12,20,30,42,56………….n
PRINT THE FIBONNACI SERIES: 1,2,3,5,8,13,21………….n
AVERAGE OF NUMBERS
SUM OF SERIES WITH FIRST AND LAST TERM ENTERED BY USER
SUM OF FRACTIONS SERIES: 1, 1/2, 1/3, 1/4 , 1/5,………1/n
FACTORS OF A NUMBER
FACTORIAL OF A NUMBER
SUM OF DIGITS IN A NUMBER
COMPOUND INETERST BY SIMPLE INTEREST
SIMPLE CALCULATOR FOR TWO FRACTIONS
SUM OF ALL TERMS IN A ARRAY INPUT BY THE USER
ACCEPT 10 NUMBERS AND PRINT THE SUM OF :
ALL ODD ELEMNTS, EVEN ELEMENTS AND EVERY 3RD ELEMENT SEPARATELY
FORM A NEW NUMBER FROM THREE DIGITS INPUT
PRINT CONSUMER ELECTRICITY BILL AFTER DATA ENTRY
EMPLOYEE PAY-SLIP
REVERSE A VECTOR
FIND LARGEST AND SMALLEST ELEMNT IN A VECTOR
DELETE DUPLICATE ELEMENTS FROM A VECTOR
PLAYER DETAILS USING ARRAYS
WHITE SPACE CONFIRMATION
CONFIRM PRESENCE OF A CHARACTER IN A STRING
COUNT THE NUMBER OF VOWELS IN A STRING
ENCRYPTION OF A STRING
CONVERT A STRING INTO UPPERCASE
FIND SUBSTRING OF STRING
FIND PATTERN STRING IN GIVEN MAIN STRING
CONCATENATE TWO STRINGS
ADDITION OF TWO MATRICES
SUBTRACTION OF A MATRIX FROM ANOTHER
MULTIPLICATION OF TWO MATRICES
FIND ROWSUM AND COLUMNSUM IN A MATRIX
SUM OF ELEMENTS ABOVE AND BELOW THE MAIN DIAGONAL OF THE MATRIX
TRANSPOSE A MATRIX
BINARY SEARCH
BUBBLE SORT
MERGE TWO GIVEN ARRAYS
SORT TWO ARRAYS AND MERGE THEM
TARNSFORM ARRAY : 58712496010 INTO : 97520146810
ARRAY MANIPULATION
CUBE OF A NUMBER USING FUNCTION
PRINT THE LARGEST ELEMENT IN AN ARRAY USING FUNTION
EFFECT OF INCREMENT AND DECREMENT OPERATORS USING FUNCTON
PRINT PYRAMIDS OF DIGITS USING A FUNCTION
FIND THE LEAST COMMON DIVISOR OF TWO NUMBERS USING A FUNCTION
TO FIND THE LCM AND HCF OF GIVEN 3 NUMBERS
SUM OF N NATURAL NUMBERS FROM A GIVEN NUMBER USING A FUNCTION
ILLUSTRATE THE CALL BY VALUE METHOD FOR INVOKING A FUNCTION
SHOW THE HANDICAP OF CALL BY VALUE METHOD
A FUNCTION TO SHOW SPECIAL SERIES
SWAP TWO VALUES USING CALL BY REFERENCE
CONVERT DISTANCE IN FEET OR INCHES USING CALL BY REFERENCE METHOD
TO SET THE LARGER VALUE OF TWO GIVEN VALUES TO (-1) USING CALL BY REFERENCE
FUNCTION TAKING NO ARGUMENTS AND RETURNING NO VALUES
TAKE TWO VALUES AND AN ARITHMETIC OPERATOR TO DISPLAY THE RESULT
SORT AN INTEGER ARRAY USING FUNCTIONS
DISPLAY STUDENTS MARKSHEET USING FUNCTIONS
PALINDROME STRING OR NOT
PRINT THE POSITION OF A CHARACTER IN A STRING USING FUNCTIONS
DETERMINE WHETHER TWO STRINGS CONTAIN EQUAL NUMBER OF CHARACTERS
CHECK WHETHER A CHARACTER IS ALPHANUMERIC OR NOT
CHANGE THE CASE OF A CHARACTER
COPY SMALLER STRING INTO BIGGER STRING
APPEND THE FIRST STRING TO THE SECOND STRING
TO JUSTIFY A STRING
EMPLOYEE DATABASE
HOTEL FOOD BILLING PROGRAM
CONVERT DECIMAL NUMBER TO BINARY NUMBER
CONVERT DECIMAL NUMBER TO OCTAL NUMBER
CONVERT DECIMAL NUMBER TO HEXADECIMAL NUMBER
CONVERT BINARY NUMBER TO DECIMAL NUMBER
CONVERT BINARY NUMBER TO OCTAL NUMBER
CONVERT BINARY NUMBER TO HEXADECIMAL NUMBER
CONVERT OCTAL NUMBER TO DECIMAL NUMBER
CONVERT OCTAL NUMBER TO BINARY NUMBER
CONVERT OCTAL NUMBER TO HEXADECIMAL NUMBER
CONVERT HEXADECIMAL NUMBER TO DECIMAL NUMBER
CONVERT HEXADECIMAL NUMBER TO BINARY NUMBER
CONVERT HEXADECIMAL NUMBER TO OCTAL NUMBER
TRANSLATE NUMBER INTO WORDS
CALENDAR OF A MONTH
MY BEST PROGRAMS MENU
// CONSTANTS DECLARATION RETURN TO INDEX
#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 : R
ENTER THE STRING : RACHIT
ENTER A FLOAT : 6.3
CONSTANTS
INTEGER : 7
CHARACTER : R
STRING : RACHIT
FLOAT : 6.3
*/
// TO DISPLAY THE SIZE OF VARIOUS DATA TYPES AVAILABLE. RETURN TO INDEX
#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
*/
// EMPLOYEES DETAILS RETURN TO INDEX
#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
EMPLOYEE DETAILS:
EMPLOYEE NAME : RAM AIRAN
EMPLOYEE NUMBER : 7
EMPLOYEE GRADE : A
EMPLOYEE COMMISSION : 7000
*/
//TO FIND THE SUM OF TWO NUMBERS RETURN TO INDEX
#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
*/
//TO FIND THE DIFFERENCE BETWEEN TWO NUMBERS RETURN TO INDEX
#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
*/
// TO DISPLAY PRODUCT OF TWO NUMBERS RETURN TO INDEX
#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
*/
// TO DIVIDE A NUMBER WITH ANOTHER RETURN TO INDEX
#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
THE QUOTIENT IS 3
THE REMAINDER IS 18
*/
//SQUARE OF A NUMBER RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main ()
{
/*OUTPUT
ENTER A NUMBER : 18
ENTER A NUMBER : 25
*/
// TO FIND THE AREA OF RECTANGLE RETURN TO INDEX
#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
*/
// AREA OF A TRIANGLE RETURN TO INDEX
#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)
b)
c)
d)
*/
// TO FIND THE VOLUME OF A SPHERE RETURN TO INDEX
#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
/*OUTPUT
*/
//A PROGRAM TO FIND SIMPLE INTEREST RETURN TO INDEX
#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();
}
// PLAYER DETAILS RETURN TO INDEX
#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
/*OUTPUT
ENTER A : 23
ENTER B : 34
NEW A= 34
NEW B= 23
*/
// CLASSIFY THE TOTAL NUMBER OF DAYS INPUT INTO YEAR, WEEK AND DAYS RETURN TO
INDEX
#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)
Repeat? (y/n) : y
b)
Repeat? (y/n) : y
c)
Repeat? (y/n) : y
d)
Repeat? (y/n) : y
*/
//TERNARY OPERATOR RETURN TO INDEX
#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
*/
//NESTED TERNARY OPERATOR RETURN TO INDEX
#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
*/
// FIND THE GREATER OF TWO GIVEN NUMBERS RETURN TO INDEX
#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
*/
//GREATER OF THREE NUMBERS RETURN TO INDEX
#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.
*/
// A PROGRAM IN C LANGUAGE TO FIND THE GREATEST AMONG THREE NUMBERS
RETURN TO INDEX
#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)
986 is greatest.
b)
349 is greatest.
c)
*/
// TO FIND IF A YEAR INPUT IS LEAP OR NOT RETURN TO
INDEX
#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
*/
/*SALARY OF THE COMPUTER SALESMAN WITH CONCEPT OF DEFINING THE BASIC SALARY
AS CONSTANT */ RETURN
TO INDEX
#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
*S.J. COMPUTERS*
#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
*/
//GIFT AGAINST BILL AMOUNT RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float bill, amt;
cout<<"\t\t\t**SJ supermarket**";
cout<<"\n\nWELCOME DEAR CUSTOMER!!!";
cout<<"\n\nENTER BILL NUMBER : ";
cin>>bill;
cout<<"\nENTER AMOUNT OF BILL : ";
cin>>amt;
cout<<"\t\t\t**SJ supermarket**";
if(amt<100 && amt>0)
cout<<"\n\nSORRY, NO GIFT FOR YOU.";
else if(amt>=100 && amt<500)
cout<<"\n\n\nTHANK YOU FOR SHOPPING FROM OUR STORE.\
\nSURPRISE!! A GIFT FOR YOU!!\nCONGRATULATIONS!! YOU WIN A CALCULATOR";
else if(amt>=500 && amt<1000)
cout<<"\n\n\nTHANK YOU FOR SHOPPING FROM OUR STORE.\
\nSURPRISE!! A GIFT FOR YOU!!\nCONGRATULATIONS!! YOU WIN A RADIO.";
else if(amt>=1000)
cout<<"\n\n\nTHANK YOU FOR SHOPPING FROM OUR STORE.\
\nSURPRISE!!A GIFT FOR YOU!!\nCONGRATULATIONS!! YOU WIN OXFORD ATLAS";
else if(amt>=3000)
cout<<"\n\n\nTHANK YOU FOR SHOPPING FROM OUR STORE.\
\nSURPRISE!!A GIFT FOR YOU!!\
\nCONGRATULATIONS!! YOU WIN OXFORD ADVANCED LEARNER'S DICTIONARY";
cout<<"\nPLEASE VISIT US AGIAN SOON.";
getch();
}
/*OUTPUT
**SJ supermarket**
*/
//ROUNDING OFF NUMBERS TO TENS PLACE RETURN TO
INDEX
#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
*/
// TO FIND THE ROOTS OF A QUADRATIC EQUATION RETURN
TO INDEX
#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 b : 5
ENTER c : 2
ROOTS ARE REAL AND UNEQUAL.
*/
// MONTH DISPLAY USING SWITCH RETURN TO
INDEX
#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
*/
//DISPLAY MEANING OF GRADES USING SWICH CASE STRUCTURE
RETURN TO INDEX
#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 :
*/
// SIMPLE CALCULATOR FOR 2 FRACTIONS RETURN
TO INDEX
#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 :
FRACTION 2 :
RESULT IS : 0.272212
*/
PREDICT THE DAY ON WHICH A GIVEN DATE FALLS RETURN
TO INDEX
#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();
}
// INCREMENT AND DECREMENT OPERATORS RETURN
TO INDEX
#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
*/
// A SAMPLE PROGRAM TO PRINT 1-100 RETURN TO
INDEX
#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
*/
//STAR PATTERN 1 RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int count,i;
clrscr();
for(count=0;count<=10;count++)
{
for(i=0;i<=count;i++)
cout<<'*';
cout<<endl;
}
getch();
}
/* Output
*
**
***
****
*****
******
*******
********
*********
**********
***********
*/
// STAR PATTERN 2 RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int count,i;
clrscr();
for(count=10;count>=0;count--)
{
for(i=count;i>=0;i--)
cout<<'*';
cout<<endl;
}
getch();
}
/* OUTPUT
**********
*********
********
*******
******
*****
****
***
**
*
*/
//STAR PATTERN 3 RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int count,i, n=10;
clrscr();
for(count=0;count<=n;count++)
{
for(int j=10; j>count;j--)
{
cout<<" ";
}
for(i=0; i<count;i++)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
/* Output
*
**
***
****
*****
******
*******
********
*********
**********
*/
// STAR PATTERN 4 RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int count,i, n=10;
clrscr();
for(count=0;count<=n;count++)
{
for(i=0; i<count;i++)
{
cout<<" ";
}
for(int j=10; j>count;j--)
{
cout<<"*";
}
cout<<endl;
}
getch();
}
/* Output
**********
*********
********
*******
******
*****
****
***
**
*
*/
//ALPHABETS PATTERN 1 RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr ();
int count,i,n=26,k,j,m;
char ch;
for(i=1, m=65;i<=n;i++,m++)
{
for(k=1;k<=n-i;k++)
{
cout<<" ";
}
for(ch=65;ch<=m;ch++)
{
cout<<ch;
}
cout<<endl;
}
getch();
}
// ALPHABETS PATTERN 2 RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr ();
int count,i,n=26,k,j,m;
char ch;
for(i=1, m=65;i<=n;i++,m++) // for line
{
for(k=1;k<=n-i;k++) // for white space
{
cout<<" ";
}
for(ch=65;ch<=m;ch++) // for elements in line
{
cout<<ch << " ";
}
cout<<endl;
}
getch();
}
/*OUTPUT
ENTER 10 NUMBER :
123
34
56
5
-54
-43
453
-45
-3
-89
THE NUMBER OF POSITIVE INTEGERS : 5
THE NUMBER OF NEGATIVE INTEGERS : 5
*/
//TO DETERMINE A PERFECT NUMBER. RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main ()
{
int num, fact, gfact, fsum=0;
clrscr ();
cout << "ENTER A NUMBER : ";
cin >> num;
gfact=(num/2)+1;
for (fact=1; fact<=gfact; fact=fact+1)
{
if (num%fact==0)
fsum+=fact;
}
if (fsum==num)
cout << "\nIT IS A PERFECT NUMBER. " << endl;
else
cout << "\nIT IS NOT A PERFECT NUMBER. " << endl;
getch ();
}
/*OUTPUT
ENTER A NUMBER : 6
IT IS A PERFECT NUMBER.
ENTER A NUMBER : 25
*/
// TO DETERMINE A PRIME NUMBER. RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main ()
{
long num, fact; int count;
clrscr ();
cout << "ENTER A NUMBER : ";
cin >> num;
for ( fact=1, count=0; fact<=num/2; fact=fact+1)
{
if (num%fact==0)
count=count+1;
}
if (count==1)
cout << "\nYES! ITS IS A PRIME NUMBER." << endl;
else
cout << "\nNO! IT IS NOT A PRIME NUMBER." << endl;
getch ();
}
/*OUTPUT
ENTER A NUMBER : 3
ENTER A NUMBER : 23
ENTER A NUMBER : 9
*/
// PRINT THE MULTIPLES OF A NUMBER USING A DO-WHILE LOOP; RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int num, multi=0;
clrscr();
cout<<"\nPLEASE ENTER THE NUMBER : ";
cin>>num;
cout<<"\nTHE MULTIPLES OF " <<num <<" are : " <<endl << endl;
do
{
multi++;
cout <<num << " X " << multi << " = " << num*multi << endl;
} while(multi<10);
getch();
}
/* Output
a)
63 X 1 = 63
63 X 2 = 126
63 X 3 = 189
63 X 4 = 252
63 X 5 = 315
63 X 6 = 378
63 X 7 = 441
63 X 8 = 504
63 X 9 = 567
63 X 10 = 630
b)
1539 X 1 = 1539
1539 X 2 = 3078
1539 X 3 = 4617
1539 X 4 = 6156
1539 X 5 = 7695
1539 X 6 = 9234
1539 X 7 = 10773
1539 X 8 = 12312
1539 X 9 = 13851
1539 X 10 = 15390
*/
// PRINT THE MULTIPLICATION TABLE OF A NUMBER USING A FOR LOOP; RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int num, multi;
clrscr();
cout<<"\nPLEASE ENTER THE NUMBER : ";
cin>>num;
cout<<"\nTHE MULTIPLES OF " <<num <<" are : " <<endl << endl;
for(multi=1; multi<=10; multi++)
{
cout<< num<<" X " <<multi << " = " << num*multi <<endl;
}
getch();
}
/* Output
a)
81 X 1 = 81
81 X 2 = 162
81 X 3 = 243
81 X 4 = 324
81 X 5 = 405
81 X 6 = 486
81 X 7 = 567
81 X 8 = 648
81 X 9 = 729
81 X 10 = 810
b)
2745 X 1 = 2745
2745 X 2 = 5490
2745 X 3 = 8235
2745 X 4 = 10980
2745 X 5 = 13725
2745 X 6 = 16470
2745 X 7 = 19215
2745 X 8 = 21960
2745 X 9 = 24705
2745 X 10 = 27450
*/
// REVERSE OF A NUMBER INPUT THE USER RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
char choice;
do
{
long num,reverse=0, count, t1;
clrscr();
cout<<"\nENTER A NUMBER : ";
cin>>num;
while (num != 0)
{
t1=num%10;
reverse=(reverse*10)+t1;
num=num/10;
}
/* OUTPUT
a)
ENTER A NUMBER : 63
b)
c)
d)
/* Output
a)
Enter the number of elements for the series : 15
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15
b)
Enter the number of elements for the series : 30
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
c)
Enter the number of elements for the series : 81
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
// PRINT THE SERIES : -1, +4, -9, +16....N RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num, even, odd, sum, count1, count2, temp1=1, temp2;
cout<<"Enter the number of elements : ";
cin>>num;
cout<<"\n";
for(count1=1,count2=2;temp1<=num/2;count1+=2,count2+=2,temp1++)
{
even=count2*count2;
odd=count1*count1;
temp2=odd-(2*odd);
cout<<temp2<<"\t";
cout<<even<<"\t";
}
if(num%2!=0)
{
odd=count1*count1;
temp2=odd-(2*odd);
cout<<temp2;
}
getch();
}
/* Output
a)
Enter the number of elements : 10
b)
Enter the number of elements : 34
c)
Enter the number of elements : 63
*/
// A SERIES WITH 2 APS : 0,2,5,9,14,20,27,35....N RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n,i,sum;
cout<<"Enter the nth term : ";
cin>>n;
cout<<"\n";
for(i=2, sum=0; i<=n;i++)
{
cout<<sum << "\t" ;
sum+=i;
}
cout<<sum;
getch();
}
/* Output
a)
0 2 5 9 14 20 27
b)
Enter the nth term : 18
0 2 5 9 14 20 27 35 44 54
65 77 90 104 119 135 152 170
c)
Enter the nth term : 25
0 2 5 9 14 20 27 35 44 54
65 77 90 104 119 135 152 170 189 209
230 252 275 299 324
d)
Enter the nth term : 36
0 2 5 9 14 20 27 35 44 54
65 77 90 104 119 135 152 170 189 209
230 252 275 299 324 350 377 405 434 464
495 527 560 594 629 665
e)
Enter the nth term : 45
0 2 5 9 14 20 27 35 44 54
65 77 90 104 119 135 152 170 189 209
230 252 275 299 324 350 377 405 434 464
495 527 560 594 629 665 702 740 779 819
860 902 945 989 1034
*/
// TO DISPLAY SERIES : 2,6,12,20,30,42,56.......N RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int sum=0, i,n, t;
clrscr();
cout<<"Enter the number of terms : ";
cin>>n;
cout<<"\n";
for(i=2, t=1; t<=n; t++,i=i+2)
{
cout<<sum<<"\t";
sum+=i;
}
getch();
}
/* Output
a)
Enter the number of terms : 9
0 2 6 12 20 30 42 56 72
b)
Enter the number of terms : 15
0 2 6 12 20 30 42 56 72 90
110 132 156 182 210
c)
Enter the number of terms : 24
0 2 6 12 20 30 42 56 72 90
110 132 156 182 210 240 272 306 342 380
420 462 506 552
d)
Enter the number of terms : 43
0 2 6 12 20 30 42 56 72 90
110 132 156 182 210 240 272 306 342 380
420 462 506 552 600 650 702 756 812 870
930 992 1056 1122 1190 1260 1332 1406 1482 1560
1640 1722 1806
e)
Enter the number of terms : 63
0 2 6 12 20 30 42 56 72 90
110 132 156 182 210 240 272 306 342 380
420 462 506 552 600 650 702 756 812 870
930 992 1056 1122 1190 1260 1332 1406 1482 1560
1640 1722 1806 1892 1980 2070 2162 2256 2352 2450
2550 2652 2756 2862 2970 3080 3192 3306 3422 3540
3660 3782 3906
*/
// PRINT THE FIBONACCI SERIES RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
/* FIBONACCI SERIES */
char choice;
do
{
clrscr();
long double num, a=1, b=0, count;
cout<<"ENTER THE NUMBER OF ELEMENTS REQUIRED : ";
cin>>num;
cout<<"\n\n";
for(count=1; count<=num/2;count++)
{
a+=b;
cout<<b << "\t";
b+=a;
cout<<a << "\t";
}
cout<<"\n\nREPEAT THE SAME PROGRAM? (Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/* Output
a)
ENTER THE NUMBER OF ELEMENTS REQUIRED : 8
0 1 1 2 3 5 8 13
b)
ENTER THE NUMBER OF ELEMENTS REQUIRED : 36
0 1 1 2 3 5 8 13 21 34
55 89 144 233 377 610 987 1597 2584 4181
6765 10946 17711 28657 46368 75025 121393 196418 317811 514229
832040 1346269 2178309 3524578 5702887 9227465
c)
ENTER THE NUMBER OF ELEMENTS REQUIRED : 28
0 1 1 2 3 5 8 13 21 34
55 89 144 233 377 610 987 1597 2584 4181
6765 10946 17711 28657 46368 75025 121393 196418
REPEAT THE SAME PROGRAM? (Y/N) : N
// AVERAGE OF N NUMBERS RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
long float result ;
long num,n, sum=0, count=0;
clrscr();
cout << "\nENTER THE NUMBER OF TERMS : ";
cin >> n;
for(count=0;count<n;sum+=num,count++)
{
cout<<"\nENTER A TERM : ";
cin>>num;
}
result=sum/n;
cout<<"\nTHE AVERAGE OF NUMBERS IS " << result;
getch();
}
/*OUTPUT
ENTER A TERM : 6
*/
/* SUM OF AN ARITHMETIC PROGRESSION WHOSE FIRST TERM AND LAST TERMS ARE
ENTERED BY THE USER AND THE COMMON DIFFERENCE IS 1 */
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
long double first, last, sum ; char choice;
do
{
clrscr();
cout<<"\n\nPLEASE ENTER THE FIRST TERM :";
cin>>first;
cout<<"\n\nPLEASE ENTER THE LAST TERM :";
cin>>last;
for(sum=0;first<=last;first++)
sum=sum+first;
cout<< "\n\n THE FINAL SUM IS : " << sum;
cout<<"\n\nPRESS Y TO REPEAT ELSE EXIT PRESSING ANY KEY : ";
cin>>choice;
}while(choice=='y' || choice=='Y');
cout<<"\n\nPROGRAM EXCLUSIVELY CODED BY RACHIT AGRAWAL OF CLASS 11. \n\
\nANY MODIFICATION DONE HERBY INVITE LEGAL ACTION.\n\nSUGGESTIONS AND
COMMENTS WELCOME AT rachit.agrawal9@gmail.com";
getch();
}
/* OUTPUT
a)
b)
*/
// SUM OF FRACTIONS FROM 1 ... 1/N RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
char des;
clrscr();
do
{
long float num,temp, sum=0;
clrscr();
cout<<"ENTER THE VALUE FOR nth DENOMINATOR : " ;
cin>>num;
cout<<"\n";
for(temp=1;temp<=num;temp++)
{
sum=sum+(1/temp);
cout<<sum << " + ";
}
cout<<"\n\nTHE SUM IS : "<<sum;
cout<<"\n\nREPEAT? (y/n) : ";
cin>>des;
} while(des=='y'||des=='Y');
}
/*Output
a)
ENTER THE VALUE FOR nth DENOMINATOR : 7
REPEAT? (y/n) : y
b)
ENTER THE VALUE FOR nth DENOMINATOR : 18
REPEAT? (y/n) : n
//CALCULATE THE FACTORS OF A GIVEN NUMBER RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main ()
{
int num, fact, gfact;
clrscr ();
cout<<"ENTER A NUMBER : ";
cin >> num;
gfact=num/2;
cout<<"THE FACTORS OF " << num << " ARE : " << endl;
for ( fact=1; fact<=gfact; fact=fact+1)
{
if (num%fact==0)
cout << fact << endl;
}
getch ();
}
/*OUTPUT
ENTER A NUMBER : 90
THE FACTORS OF 90 ARE :
1
2
3
5
6
9
10
15
18
30
45
*/
// FACTORIAL OF A NUMBER RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
char choice;
do
{
clrscr();
long double num, i, fact=1;
cout<<"\nENTER THE NUMBER : ";
cin>>num;
for(i=num;i>=1;i--)
fact=fact*i;
cout<<"\nTHE FACTORIAL OF " << num <<" IS " << fact;
cout<<"\n\nREPEAT THE PROGRAM (y/n) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*Output
a)
ENTER THE NUMBER : 63
b)
ENTER THE NUMBER : 81
c)
ENTER THE NUMBER : 7
d)
ENTER THE NUMBER : 9
e)
ENTER THE NUMBER : 18
/*OUTPUT
*/
// COMPOUND INTEREST BY SIMPLE INTEREST RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
long float interest, prince, rate, amt;
int time, temp, r;
char choice;
do
{
clrscr ();
cout<<"PLEASE ENTER THE PRINCIPAL AMOUNT : ";
cin>>prince;
cout<<"\nENTER THE RATE OF INTEREST : ";
cin>>rate;
cout<<"\nENTER THE TIME : ";
cin>>time;
amt=prince;
cout<<"\n\tTIME\tSIMPLE INTEREST\tAMOUNT";
for(r=8, temp=0,interest=0;temp<=time;temp++, r++)
{
cout<<"\n\t"<<temp<<"\t"<<interest;
gotoxy(33,r);
cout<<amt;
interest=(amt*rate)/100;
amt=amt+interest;
}
cout<<"\n\tClosing"<<"\t"<<interest;
cout<<amt;
cout<<"\n\nTHUS, THE FINAL AMOUNT IS : "<<amt;
cout<<"\n\nREPEAT? (y/n) : ";
cin>>choice;
if(choice=='n'||choice=='N')
cout<<"\nTHANK YOU";
getch();
}while(choice=='y'||choice=='Y');
}
/* OUTPUT
a)
PLEASE ENTER THE PRINCIPAL AMOUNT : 30000
REPEAT? (y/n) : n
// SIMPLE CALCULATOR FOR 2 FRACTIONS RETURN
TO INDEX
#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 :
FRACTION 2 :
ENTER THE NUMERATOR : 12
RESULT IS : 0.272212
/* Output
Entry : 1
Enter : 1
Entry : 2
Enter : 22
Entry : 3
Enter : 345
Entry : 4
Enter : 454
Entry : 5
Enter : 67
Entry : 6
Enter : 234
Entry : 7
Enter : 564
Entry : 8
Enter : 234
Entry : 9
Enter : 563
Entry : 10
Enter : 673
The sum all the elements entered for the array is : 3157
*/
/* TO ACCEPT 10 NUMBERS IN AN ARRAY AND PRINT THE SUM OF: RETURN TO
INDEX
ALL ODD ELEMENTS IN THE ARRAY
ALL EVEN ELEMENTS IN THE ARRAY
EVERY 3RD ELEMENT IN THE ARRAY */
#include<iostream.h>
#include<conio.h>
void main()
{
int array[10], count=0, sum1=0, sum2=0, sum3=0;
clrscr();
//*********input**************
cout<<"\nENTER 10 NUMBERS FOR THE ARRAY : " <<endl<<endl;
for(count=0;count<10;count++)
{
cin >> array[count];
}
//************process***********
for(count=0 ; count<10 ; count++)
{
if(count%2!=0)
sum1=sum1+array[count];
else
sum2=sum2+array[count];
}
for(count=2 ; count<10 ; count=count+3)
{
sum3=sum3+array[count];
}
//**************output***********
cout<<"\nTHE RESULTS ARE : " << endl;
cout<<"\n1: "<<"SUM OF ALL ODD ELEMENTS : "<<sum1<<endl;
cout<<"\n2: "<<"SUM OF ALL EVEN ELEMENTS : "<<sum2<<endl;
cout<<"\n3: "<<"SUM OF EVERY 3rd ELEMENT IN THE ARRAY : "<< sum3 <<endl;
getch();
}
/*OUTPUT
12
23
34
45
56
67
78
89
90
99
*/
// INPUT 3 DIGITS AND FORM A NEW NUMBER RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
char choice, ch1,ch2, ch3, ch4, s[4];
int dig1, dig2, dig3, num2, num3, num4, num5, num6;
do
{
clrscr();
cout<<"\nENTER THREE DIGIT CHARACTER : \n";
cin>>s;
ch1=s[0];
ch2=s[1];
ch3=s[2];
dig1=(ch1-'0');
dig2=(ch2-'0');
dig3=(ch3-'0');
num2=dig1*100 + dig3*10 + dig2;
num3=dig2*100 + dig3*10 + dig1;
num4=dig2*100 + dig1*10 + dig3;
num5=dig3*100 + dig2*10 + dig1;
num6=dig3*100 + dig1*10 + dig2;
cout<<"\nTHE NUMBERS FORMED ARE : \n"<< num2;
cout<<"\n" <<num3<<"\n"<<num4<<"\n"<<num5<<"\n"<<num6;
/*OUTPUT
*/
/* PRINT THE BILL INDEX OF ALL USERS ALONG WITH THEIR ELECTRICITY
RETURN TO INDEX
CONSUMPTION UNITS AND THE BILL TO BE PAYED.*/
#include<iostream.h>
#include<conio.h>
void main()
{
long consumption[25], charges[25];
int count, y;
char name[5][25];
clrscr();
for(count=0; count<5; count++)
{
cout<<"ENTER THE NAME : ";
cin>>name[count];
cout<<"ENTER THE ELECTRICITY CONSUMPTION : ";
cin >> consumption[count];
if(consumption[count]<=400)
charges[count]=consumption[count]*60;
else if (consumption[count]>400 && consumption[count]<=900)
charges[count]=((consumption[count]-100)*80) + 6000;
else if(consumption[count]>900)
charges[count]=((consumption[count]-300)*90) + 22000;
}
clrscr();
gotoxy(1,1);
cout << "NAME";
gotoxy(7,1);
cout << "CONSUMPTION";
gotoxy(20,1);
cout << "CHARGES" <<endl;
for(count=0, y=3; count<5; count++, y++)
{
gotoxy(1,y);
cout<<name[count];
gotoxy(12,y);
cout<<consumption[count];
gotoxy(20,y);
cout<<charges[count];
}
getch();
}
/*OUTPUT
/* Output
Employee Payslip
Repeat ?(y/n) :n
*/
// PROGRAM TO REVERSE A VECTOR RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
char choice;
do
{
clrscr();
int vec[10], count1, count2;
cout<<"ENTER TEN ELEMENTS FOR VECTOR :\n";
for(count1=0;count1<10;count1++)
cin>>vec[count1];
cout<<"\n\n";
for(count1=0, count2=9;count1<5;count1++,count2--)
{
vec[count1]=vec[count1]+vec[count2];
vec[count2]=vec[count1]-vec[count2];
vec[count1]=vec[count1]-vec[count2];
}
cout<<"\n\nTHE ORIGINAL VECTOR IS AS FOLLOWS : \n\n";
for(count1=0;count1<10;count1++)
cout<<" " <<vec[count1];
cout<<"\n\nTHE REVERSED VECTOR IS AS FOLLOWS : \n\n";
for(count1=0; count1<10;count1++)
cout<<" "<<vec[count1];
cout<<"\n\nDO YOU WISH TO RE-EXECUTE THE PROGRAM?(Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/* OUTPUT
12 23 34 45 56 67 78 89 90 98
98 90 89 78 67 56 45 34 23 12
/*OUTPUT
ENTER HOW MANY ELEMENTS ARE THERE IN THE VECTOR (MAX 50) : 15
clrscr();
}
if(ans==0)
cout<<"\nVECTOR IS WITHOUT DUPLICATES:\n";
else
{
cout<<"\n\nVECTOR AFTER DELETING THE DUPLICATES: \n";
for(count2=0; count2<num; count2++)
cout<<"\n"<<vec[count2];
}
231
345
32
45
76
34
32
231
345
231
345
32
45
76
34
*/
// PLAYER DETAILS USING ARRAYS RETURN
TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char name[30];
int count, matches;
float runs[10],balls[10];
long double sr[10], avgsr, temp=0;
cout <<"\nENTER PLAYER NAME : ";
cin.getline(name,30);
cout<<"\nENTER NUMBER OF MATCHES PLAYED : ";
cin>>matches;
for(count=1;count<=matches;count++)
{
cout<<"\nENTER RUNS SCORED IN MATCH "<<count<<" : ";
cin>>runs[count];
cout<<"\nENTER BALLS PLAYED IN MATCH "<<count<<" : ";
cin >> balls[count];
sr[count]=(runs[count]*100)/balls[count];
temp+=sr[count];
}
avgsr=temp/matches;
clrscr();
cout<<"\nPLAYER NAME : "<< name <<endl;
for(count=1;count<=matches;count++)
{
cout<<"\nRUNS SCORED IN MATCH "<<count<<" : "<< runs[count] <<endl;
cout<<"\nBALLS PLAYED IN MATCH "<<count<<" : "<< balls[count]<<endl;
cout<<"\nSTRIKE RATE IN MATCH "<<count<< sr[count]<<endl<<endl;
}
cout<<"\nAVERAGE STRIKE RATE : " <<avgsr<<endl;
getch();
}
/*OUTPUT
ENTER PLAYER NAME : ROHAN GAVASKAR
/*OUTPUT
ENTER THE CHARACTER :
*/
/* CONFIRM PRESENCE OF A CHARACTER IN A STRING*/ RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char choice, ch, str[70], flag;
int len, count;
do
{
clrscr();
cout<<"\nENTER THE STRING:\n\n";
cin.getline(str, 70);
len=strlen(str);
cout<<"\nENTER A CHARACTER: ";
cin.get(ch);
flag='n';
for(count=0;str[count]!=len;count++)
{
if(ch==str[count])
{
flag='Y';
break;
}
}
if(flag=='Y')
{
cout<<"\n";
cout.put(ch);
cout<<" is contained in the string : \n\n";
cout.write(str,len);
}
else
{
cout<<"\n";
cout.put(ch);
cout<<" is not contained in the string : \n\n";
cout.write(str,len);
}
cout<<"\n\nDO YOU WISH TO REPEAT THE PROGRAM?
(Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/* OUTPUT
ENTER A CHARACTER: z
z is contained in the string :
str2[count]='\0';
puts("\nTHE ENCRYPTED STRING IS : ");
cout<<str2;
}
/* OUTPUT
ENTER A STRING : godfather
/*OUTPUT
ENTER A STRING :
UPPERCASE STRING IS :
*/
// PROGRAM TO FIND THE SUBSTRING OF A GIVEN STRING.
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{
clrscr();
char mainstr[50], substr[50];
int pos, count, count1, count2, len, num, temp;
cout<<"ENTER THE MAIN STRING ( MAX 49 CHARACTERS) : \n";
cin.getline(mainstr, 50);
len=strlen(mainstr);
cout<<"\nENTER THE STARTING POSITION OF SUBSTRING : ";
cin>>pos;
if(pos>len)
{
cout<<"\n\nSTARTING POSITION EXCEEDS THE TOTAL LENGTH OF STRING";
exit(0);
}
cout<<"\n\nENTER THE NUMBER OF CHARACTERS IN SUBSTRING : ";
cin>>count;
if(pos<=0)
{
cout<<"\n\nEXTRACTED STRING IS EMPTY.";
exit(0);
}
else if (((pos+count)-1)>len)
{
cout<<"\n\nSTRING TO BE EXTRACTED EXCEEDS LENGTH \n";
num=(len-pos);
}
else
num=count;
count2=0;
for(count1=--pos; count2<num;count2++, count1++)
substr[count2]=mainstr[count1];
/*OUTPUT
*/
// PROGRAM TO SEARCH FOR A PATTERN STRING IN THE THE MAIN STRING
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char mainstr[50], patstr[50];
int count1, count2, count3=0, len1, len2, flag, pos, found=0;
cout<<"ENTER THE MAIN STRING : ";
cin.getline(mainstr, 50);
cout<<"ENTER THE PATTERN STRING : ";
cin.getline(patstr, 50);
len1= strlen(mainstr);
len2= strlen(patstr);
flag=0;
for(count1=0; count1<len1; count1++)
{
for(count2=count1; count2<len1; )
{
if(mainstr[count2]!=patstr[0])
{
flag=1;
count2++;
}
else if(mainstr[count2]==patstr[0])
{
pos=count2;
count3=0;
while(mainstr[count2]==patstr[count3])
{
flag=0;
count2++;
count3++;
}
if(count3>=len2)
{
cout<<"\nPATTERN FOUND AT POSITION " << pos+1 << endl;
found=1;
break;
}
else
count3=0;
}
}
if ( found)
break;
}
if((flag!=0)||((flag==0)&&(count3<len2)))
cout<<"\nPATTERN NOT FOUND."<<endl;
getch();
}
/*OUTPUT
ENTER THE MAIN STRING : Rachit
ENTER THE PATTERN STRING : ach
*/
//PROGRAM TO CONCATENATE TWO STRINGS RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char choice;
do
{
clrscr();
char str1[25], str2[25], str3[25];
int count1, count2;
cout<<"ENTER THE FIRST STRING : ";
cin.getline(str1, 25);
cout<<"ENTER THE SECOND STRING : ";
cin.getline(str2, 25);
for(count1=0; str1[count1]!='\0'; count1++)
{
str3[count1]=str1[count1];
}
str3[count1]=' ';
count1++;
for(count2=0; str2[count2]!='\0'; count2++)
{
str3[count1+count2]=str2[count2];
}
str3[count1+count2]='\0';
cout<<"\nTHE NEW CONCATENATED STRING IS : \n\n";
cout<<str3;
cout<<"\n\nDO YOU WISH TO RE-EXECUTE THE PROGRAM?(Y/N): ";
cin>>choice;
}while(choice=='Y'||choice=='y');
}
/* OUTPUT
ENTER THE FIRST STRING : GOOD EVENING
ENTER THE SECOND STRING : MR. SATYANARAYAN
*/
//ADDITION OF TWO MATRICES RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
int a[10][10],b[10][10],c[10][10],count1, count2,ra,ca,rb,cb;
char choice;
do
{
clrscr();
if((ra==rb)&&(ca==cb))
cout<<"\nTHE TWO MATRICES CAN BE ADDED AS THEY ARE IDENTICAL.";
else
{
cout<<"\nTHE TWO MATRICES CANNOT BE ADDED SINCE THEY ARE INIDENTICAL.";
cout<<"\nTHANK YOU.";
exit(0);
}
for(count1=0;count1<ra;count1++)
{
for(count2=0;count2<ca;count2++)
c[count1][count2]=a[count1][count2]+b[count1][count2];
}
clrscr();
cout<<"MATRIX A: ";
for(count1=0;count1<ra;count1++)
{
cout<<"\n\n";
for(count2=0;count2<ca;count2++)
cout<<"\t"<<a[count1][count2];
}
cout<<"\n\nMATRIX B: ";
for(count1=0;count1<rb;count1++)
{
cout<<"\n\n";
for(count2=0;count2<cb;count2++)
cout<<"\t"<<b[count1][count2];
}
/* OUTPUT
INPUT ROW FOR MATRIX A: 3
1
2
3
12
23
34
45
56
67
98
76
65
45
34
32
21
6
4
MATRIX A:
1 2 3
12 23 34
45 56 67
MATRIX B:
98 76 65
45 34 32
21 6 4
99 78 68
57 57 66
66 62 71
if((ra==rb)&&(ca==cb))
cout<<"\nSUBTRACTION BETWEEN THE TWO MATRICES IS POSSIBLE.";
else
{
cout<<"\nSUBTRACTION BETWEEN THE TWO MATRICES IS NOT POSSIBLE.";
cout<<"\nTHANK YOU.";
exit(0);
}
for(count1=0;count1<ra;count1++)
{
for(count2=0;count2<ca;count2++)
c[count1][count2]=a[count1][count2]-b[count1][count2];
}
clrscr();
cout<<"MATRIX A: ";
for(count1=0;count1<ra;count1++)
{
cout<<"\n\n";
for(count2=0;count2<ca;count2++)
cout<<"\t"<<a[count1][count2];
}
cout<<"\n\nMATRIX B: ";
for(count1=0;count1<rb;count1++)
{
cout<<"\n\n";
for(count2=0;count2<cb;count2++)
cout<<"\t"<<b[count1][count2];
}
/* OUTPUT
45
56
67
78
89
90
32
21
10
MATRIX A:
12 23 34
45 56 67
78 89 90
MATRIX B:
98 87 76
65 54 43
32 21 10
-20 2 24
46 68 80
if((ra==rb)&&(ca==cb))
cout<<"\nMULTIPLICATION OF THE TWO MATRICES IS POSSIBLE.";
else
{
cout<<"\nMULTIPLICATION OF THE TWO MATRICES IS NOT POSSIBLE.";
cout<<"\nTHANK YOU.";
exit(0);
}
for(count1=0;count1<ra;count1++)
{
for(count2=0;count2<cb;count2++)
{
c[count1][count2]=0;
for(count3=0;count3<ca;count3++)
{
c[count1][count2]+=a[count1][count3]*b[count3][count2];
}
}
}
clrscr();
cout<<"MATRIX A: ";
for(count1=0;count1<ra;count1++)
{
cout<<"\n\n";
for(count2=0;count2<ca;count2++)
cout<<" "<<a[count1][count2];
}
cout<<"\n\nMATRIX B: ";
for(count1=0;count1<rb;count1++)
{
cout<<"\n\n";
for(count2=0;count2<cb;count2++)
cout<<" "<<b[count1][count2];
}
/*OUTPUT
45
56
67
78
89
90
76
65
54
43
32
21
MATRIX A:
12 23 34
45 56 67
78 89 90
MATRIX B:
0 98 87
76 65 54
43 32 21
for(count1=0; count1<row;count1++)
{
rosm[count1]=0;
for(count2=0;count2<col; count2++)
rosm[count1] += a[count1][count2];
}
cout<<"\t"<<rosm[count1]<< endl;
}
cout<<"\n";
for(count2=0; count2<col; count2++)
cout<<colsm[count2]<< "\t";
cout<<endl;
cout<<"\n\nDO YOU WISH TO RE-EXECUTE THE PROGRAM? (Y/N): ";
cin>>choice;
}while(choice=='Y'||choice=='y');
}
/*OUTPUT
ENTER THE NUMBER OF ROWS FOR MATRIX : 3
ENTER THE NUMBER OF COLUMN FOR MATRIX : 3
ENTER THE ELEMENTS FOR MATRIX :
25
36
45
49
63
72
70
81
90
25 36 45 106
49 63 72 184
70 81 90 241
*/
/* PROGRAM TO FIND SUM OF ELEMENTS ABOVE AND BELOW THE
RETURN TO INDEX
MAIN DIAGONAL OF MATRIX*/
#include<iostream.h>
#include<conio.h>
void main()
{
int a[20][20], asum, bsum, row, col, count1, count2; char choice;
do
{
clrscr();
cout<<"ENTER THE NUMBER OF ROWS FOR MATRIX : ";
cin>>row;
cout<<"\nENTER THE NUMBER OF COLUMNS FOR MATRIX : ";
cin>>col;
cout<<"\nENTER THE ELEMENTS FOR THE MATRIX :\n\n";
for(count1=0;count1<row;count1++)
{
for(count2=0; count2<col; count2++)
cin>>a[count1][count2];
}
asum=0;
for(count1=0; count1<row;count1++)
{
for(count2=0;count2<col; count2++)
{
if(count1<count2)
asum+=a[count1][count2];
}
}
bsum=0;
for(count1=0; count1<row;count1++)
{
for(count2=0;count2<col; count2++)
{
if(count1>count2)
bsum+=a[count1][count2];
}
}
for(count1=0;count1<row;count1++)
{
cout<<"\n\n";
for(count2=0; count2<col; count2++)
cout<<"\t"<< a[count1][count2];
}
cout<<"\n\nTHE ELEMENTS OF THE MAIN DIAGONAL ARE : ";
for(count1=0; count1<row;count1++)
{
for(count2=0;count2<col; count2++)
{
if(count1==count2)
cout<< a[count1][count2] << " ";
}
}
cout<<"\n\nTHE SUM OF THE ELEMENTS ABOVE THE MAIN DIAGONAL : ";
cout<<asum;
cout<<"\n\nTHE SUM OF THE ELEMENTS BELOW THE MAIN DIAGONAL : ";
cout<<bsum;
cout<<"\n\nDO YOU WISH TO RE-EXECUTE THE PROGRAM? (Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/*Output
1
2
3
4
5
6
7
8
9
18
27
45
63
72
49
35
1 2 3 4
5 6 7 8
9 18 27 45
63 72 49 35
*/
//TRANSPOSE A MATRIX RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
char choice;
do
{
clrscr();
int a[10][10],b[10][10],count1, count2,ra,ca;
cout<<"\nINPUT ROW FOR MATRIX A: ";
cin>>ra;
cout<<"\nINPUT COLUMN FOR MATRIX A: ";
cin>>ca;
for(count1=0;count1<ca;count1++)
{
for(count2=0;count2<ra;count2++)
b[count1][count2]=a[count2][count1];
}
clrscr();
cout<<"MATRIX A: ";
for(count1=0;count1<ra;count1++)
{
cout<<"\n\n";
for(count2=0;count2<ca;count2++)
cout<<"\t"<<a[count1][count2];
}
cout<<"\n\nMATRIX B (TRANSPOSED FORM OF MATRIX A): ";
for(count1=0;count1<ca;count1++)
{
cout<<"\n\n";
for(count2=0;count2<ra;count2++)
cout<<"\t"<<b[count1][count2];
}
cout<<"\n\nDO YOU WISH TO RE-EXECUTE THE PROGRAM?(Y/N) : ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
/* OUTPUT
45
56
67
78
89
90
MATRIX A:
12 23 34
45 56 67
78 89 90
12 45 78
23 56 89
34 67 90
*/
// TO SEARCH FOR POSITION OF A SEARCH NUMBER FROM THOSE INPUT
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int num[15], search, count, flag=0;
clrscr();
cout<<"ENTER 15 INTEGERS FOR AN ARRAY : "<<endl<<endl;
for(count=1;count<=15;count++)
cin>>num[count];
cout<<"\nENTER THE SEARCH NUMBER FROM THE ABOVE ARRAY : ";
cin >> search;
count=1;
do
{
if(num[count]==search)
{
cout<<"\n\nTHE POSITION IS " << count;
flag=1;
}
count++;
}while(count<15);
if(num[count]==search)
{
cout<<"\n\nTHE POSITION IS " << count;
flag=1;
}
if(flag==0)
cout<<"SORRY!! SEARCH NUMBER NOT FOUND IN THE ARRAY.";
getch();
}
/*OUTPUT
12
23
34
45
56
67
78
89
90
90
89
78
76
65
45
THE POSITION IS 15
*/
// BUBBLESORT : to arrange the elements of an array in the ascending order
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int num[7], swap=1, temp, i;
clrscr();
//**********user input*************
cout<<"\nENTER 7 ELEMENTS FOR THE ARRAY:\n";
for(i=0; i<7; i++)
{
cout <<"\nENTRY "<<i+1<< " : ";
cin >> num[i];
}
//****************process**************
do
{
swap=0;
for(i=0; i<6; i++)
{
if(num[i]>num[i+1])
{
temp=num[i];
num[i]=num[i+1];
num[i+1]=temp;
swap=1;
}
}
}while(swap==1);
//***************output****************
clrscr();
cout<<"\nThe sorted array is as follows: " << endl;
for(i=0; i<7;i++)
cout<<"\n"<< num[i]<<endl;
cout << "\nThis program has been created by Rachit Agrawal " <<endl;
getch();
}
/*OUTPUT
ENTRY 1 : 56
ENTRY 2 : 87
ENTRY 3 : 34
ENTRY 4 : 97
ENTRY 5 : 23
ENTRY 6 : 83
ENTRY 7 : 49
23
34
49
56
83
87
97
97
87
83
56
49
34
23
*/
// MERGE TWO GIVEN ARRAYS. RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int array1[10]={2,4,6,9,12,19,17,19,21,22};
int array2[15]={0,1,3,5,7,8,10,11,13,14,16,18,20,23,24};
int array3[25], count1=0, count2=0, count3=0, count4;
clrscr();
do
{
if(array1[count1]<array2[count2])
{
array3[count3]=array1[count1];
cout<< array3[count3]<<"\t";
count1=count1+1;
}
else
{
array3[count3]=array2[count2];
cout<< array3[count3]<<"\t";
count2=count2+1;
}
}while(count1<9 && count2<15);
if(count1==9)
{
for(count4=count2;count4<15;count3++,count4++)
{
array3[count3]=array2[count4];
cout<<array3[count3]<<"\t";
}
}
getch();
}
/*OUTPUT
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 16 18 19 17 19
20 21 23 24
*/
// TO SORT GIVEN TWO INTEGER ARRAYS SEPARATELY AND THEN MERGE THEM
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
//****************variable declaration**********************
int array1[10]={15,21,6,19,25,12,17,9,4,2};
int array2[15]={23,22,16,10,7,18,13,11,5,14,1,8,20,3,24}, array3[25];
int count=0, count1=0, count2=0, count3=0, swap=1, temp=0, count4;
clrscr();
cout<<"THE ORIGINAL ARRAYS ARE :\n\n";
for(count=0;count<10;count++)
cout<<array1[count]<<"\t";
cout<<"\n\n\n";
for(count=0;count<15;count++)
cout<<array2[count]<<"\t";
//****************sorting**************
do
{
swap=0;
for(count=0; count<9; count++)
{
if(array1[count]>array1[count+1])
{
temp=array1[count];
array1[count]=array1[count+1];
array1[count+1]=temp;
swap=1;
}
}
}while(swap==1);
do
{
swap=0;
for(count=0; count<14; count++)
{
if(array2[count]>array2[count+1])
{
temp=array2[count];
array2[count]=array2[count+1];
array2[count+1]=temp;
swap=1;
}
}
}while(swap==1);
//***************************merging******************************
do
{
if(array1[count1]<array2[count2])
{
array3[count3]=array1[count1];
count1++;
}
else if (array1[count1]>array2[count2])
{
array3[count3]=array2[count2];
count2++;
}
else if(array1[count1]==array2[count2])
{
array3[count3]=array1[count1];
count1++;
count3++;
array3[count3]=array2[count2];
count2++;
}
count3++;
}while(count2<15);
if(count2==15)
{
for(count4=count1;count1<10;count1++, count3++)
array3[count3]=array1[count4];
}
//**************output****************
cout<<"\n\nTHE SORTED ARRAYS ARE :\n\n";
for(count=0;count<10;count++)
cout<<array1[count]<<"\t";
cout<<"\n\n\n";
for(count=0;count<15;count++)
cout<<array2[count]<<"\t";
cout<<"\n\n\n\nTHE NEW ARRAY REQUIRED IS :\n" << endl;
for(count=0; count<25;count++)
cout<<array3[count]<<"\t";
getch();
}
/*OUTPUT
15 21 6 19 25 12 17 9 4 2
23 22 16 10 7 18 13 11 5 14
1 8 20 3 24
2 4 6 9 12 15 17 19 21 25
1 3 5 7 8 10 11 13 14 16
18 20 22 23 24
*/
/* GIVEN INTEGER ARRAY : 5 8 7 1 2 4 9 6 0 10 RETURN TO
INDEX
NEW ARRAY TO BE FORMED : 9 7 5 2 0 1 4 6 8 10 */
#include<iostream.h>
#include<conio.h>
void main()
{
int array[10]={5,8,7,1,2,4,9,6,0,10}, newarray[10];
int count1, count2, count3, count4, temp, swap;
clrscr();
cout<<"ORGINAL ARRAY :\n\n";
for(count1=0;count1<10;count1++)
cout<<array[count1]<<"\t";
do
{
swap=0;
for(count1=0;count1<9;count1++)
{
if(array[count1]>array[count1+1])
{
temp=array[count1];
array[count1]=array[count1+1];
array[count1+1]=temp;
swap=1;
}
}
}while(swap==1);
/* OUTPUT
ORGINAL ARRAY :
5 8 7 1 2 4 9 6 0 10
NEW ARRAY :
9 7 5 2 0 1 4 6 8 10
*/
// ARRAY MANIPULATION MENU RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int array[5], newarray[6], count,num, pos,choice;
clrscr();
cout<<"ENTER 5 ELEMENTS FOR THE ARRAY :\n\n";
for(int i=1;i<=5;i++)
cin>>array[i];
do
{
clrscr();
cout<<"ARRAY MANIPULATION\n1 ADD ELEMENT\n2 DELETE ELEMENT\n";
cout<<"3 MODIFY ELEMENT\n4 SHOW ELEMENTS\n5 EXIT\n\n";
cout<<"ENTER YOUR CHOICE : "; cin>>choice;
clrscr();
cout<<"YOUR CHOICE : "<<choice<<endl<<endl;
switch(choice)
{
case 1: do
{
cout<<"ENTER THE POSITION FOR THE NEW ELEMENT : ";
cin>>pos;
}while(pos>6);
cout<<"\nENTER THE ELEMENT : ";
cin>>num;
for(i=1;i<pos;i++)
newarray[i]=array[i];
newarray[i]=num;
for(i=pos+1;i<=6;i++)
newarray[i]=array[i-1];
cout<<"\nTHE NEW ARRAY IS : \n\n";
for(i=1;i<=6;i++)
cout<<newarray[i]<<"\t";
getch();
break;
case 2: do
{
cout<<"ENTER THE POSITION FOR THE ELEMENT TO BE DELETED: ";
cin>>pos;
}while(pos>5);
for(i=1;i<pos;i++)
newarray[i]=array[i];
for(i=pos;i<5;i++)
newarray[i]=array[i+1];
cout<<"\nTHE NEW ARRAY IS : \n\n";
for(i=1;i<5;i++)
cout<<newarray[i]<<"\t";
getch();
break;
case 3: do
{
cout<<"ENTER THE POSITION FOR THE ELEMENT TO BE MODIFIED: ";
cin>>pos;
}while(pos>5);
cout<<"\nENTER THE NEW ELEMENT : ";
cin>>num;
for(i=1;i<pos;i++)
newarray[i]=array[i];
newarray[i]=num;
for(i=pos+1;i<=5;i++)
newarray[i]=array[i];
cout<<"\nTHE NEW ARRAY IS : \n\n";
for(i=1;i<=5;i++)
cout<<newarray[i]<<"\t";
getch();
break;
case 4:
cout<<"\nTHE ELEMENTS ENTERED BY YOU ARE :\n\n";
for(i=1;i<=5;i++)
cout<<array[i]<<"\t";
getch();
break;
default: break;
}
}while(choice!=5);
if(choice==5)
cout<<"EXITING...!!!\n\nTHANK YOU FOR USING PROGRAM\n\nCODED BY RACHIT AGRAWAL.";
cout<<”\nSUGGESSTIONS AND COMMENTS WELCOME AT rachit.agrawal9@gmail.com.”;
getch();
}
/*OUTPUT
ENTER 5 ELEMENTS FOR THE ARRAY :
7
16
25
34
43
ARRAY MANIPULATION
1 ADD ELEMENT
2 DELETE ELEMENT
3 MODIFY ELEMENT
4 SHOW ELEMENTS
5 EXIT
YOUR CHOICE : 1
7 16 45 25 34 43
YOUR CHOICE : 2
7 16 34 43
YOUR CHOICE : 3
7 54 25 34 43
YOUR CHOICE : 4
7 16 25 34 43
YOUR CHOICE : 5
EXITING...!!!
ENTER A NUMBER : 15
*/
// TO PRINT THE LARGEST ELEMENT OF AN ARRAY USING FUNCTION
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
int i;
float amt[50], big;
float large(float array[],int n);
clrscr();
for(i=0;i<50;i++)
{
cout<<"ENTER ELEMENT NUMBER : "<<i+1<<" : ";
cin>>amt[i];
cout<<"WANT TO ENTER MORE? (Y/N) : ";
cin>>ch;
if(ch!='y'&& ch!='Y')
break;
}
if(i<50)
i++;
big=large(amt, i);
cout<<"\nTHE LARGEST ELEMENT OF THE ARRAY IS : "<<big<<endl;
getch();
}
/*OUTPUT
/*OUTPUT
18
19
18
18
19
*/
// TO INVOKE A FUNCTION FOR PRINTING PYRAMIDS OF DIGITS RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void pyramid()
{
static int n=0;
int p, m ,q;
n++;
for(p=1;p<=n;p++)
{
for(q=0;q<=n-p;q++)
cout<<' ';
m=p;
for(q=1;q<=p;q++)
cout<<m++<<' ';
cout<<endl;
}
cout<<endl;
}
void main()
{
int i;
clrscr();
for(i=0;i<5;i++)
pyramid();
}
/*OUTPUT
1
23
1
23
345
1
23
345
4567
1
23
345
4567
56789
*/
// TO INVOKE A FUNCTION TO FIND THE LEAST COMMON DIVISOR OF TWO INTEGERS
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
int lcd(int a,int b)
{
int i,j=2,flag=1;
if(a>b)
i=a;
else
i=b;
while((j<=i)&&(flag))
{
if((a%j==0)&&(b%j==0))
flag=0;
else
j++;
}
if(flag)
j=1;
return j;
}
void main()
{
clrscr();
int x, y, z;
cout<<"\nENTER 2 NUMBERS WHOSE LCD IS TO BE FOUND : ";
cin>>x>>y;
z=lcd(x,y);
cout<<"\nTHE LCD OF GIVEN 2 NUMBERS IS : "<<z<<endl;
getch();
}
/*OUTPUT
*/
//TO FIND THE LCM AND HCF OF GIVEN 3 NUMBERS
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void lcm(int, int, int);
void hcf(int, int, int);
void main()
{
char choice;
do
{ int a,b,c;
clrscr();
cin>>a>>b>>c;
lcm(a,b,c);
hcf(a,b,c);
cout<<"\n\nDO YOU WANT TO REPEAT THE PROGRAM?(Y/N): ";
cin>>choice;
}while(choice=='Y'||choice=='y');
}
/*OUTPUT
*/
//TO SHOW THE HANDICAP OF CALL BY VALUE METHOD RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
void swap(int,int);
int a=7, b=4;
clrscr();
cout<<"THE ORIGINAL VALUES ARE : ";
cout<<"a= " <<a<<" b= "<<b<<endl;
swap(a,b);
cout<<"THE VALUES AFTER SWAP() ARE : ";
cout<<"a= " <<a <<" b= "<<b<<endl;
getch();
}
void swap(int x, int y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"SWAPPED VALUES ARE : ";
cout<<"a= " << x <<" b= "<<y<<endl;
}
/*OUTPUT
*/
//A FUNCTION TO SHOW SPECIAL SERIES RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
#include<math.h>
void factorial(int);
void series(int);
void main()
{
clrscr();
int num;
cout<<"ENTER NUMBER : ";
cin>>num;
series(num);
cout<<"\n\n";
factorial(num);
getch();
}
void factorial(int n)
{
long float i,result=0, fact=1;
for(i=1;i<=n;i++)
{
fact=fact*i;
cout<<"+"<<i/fact<<"\t";
result=result+(i/fact);
}
cout<<"\t="<<result;
}
void series(int n)
{
long count, res=0;
for(count=0;count<=n;count++)
{
cout<<"+"<<pow(n,count)<<"\t";
res=res+pow(n,count);
}
cout<<"\t="<<res;
}
/*OUTPUT
ENTER NUMBER : 5
+1 +5 +25 +125 +625 +3125 =3906
*/
//TO SWAP TWO VALUES USING CALL BY REFERENCE RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
void swap(int &, int &);
int a=7, b=9;
clrscr();
cout<<"\nTHE ORIGINAL VALUES ARE : ";
cout<<"a= " <<a<<" b= " <<b <<"\n";
swap(a,b);
cout<<"THE VALUES AFTER SWAP() ARE : ";
cout<<"a= " <<a << " b= " <<b <<"\n";
getch();
}
void swap(int &x, int &y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"THE SWAPPED VALUES ARE : ";
cout<<"a= " <<x<< " b= "<<y<<"\n";
}
/*OUTPUT
*/
// TO CONVERT DISTANCE IN FEET OR INCHES USING A CALL BY REFERNCE METHOD
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
void convert(float &, char &, char);
float distance;
char choice, type='F';
clrscr();
cout<<"\nENTER DISTANCE IN FEET : ";
cin>>distance;
cout<<"\nYOU WANT THE DISTANCE IN FEETS OR INCHES ? (F/I) : ";
cin>>choice;
switch(choice)
{
case 'f':
case 'F': convert(distance,type,'F');
break;
case 'i':
case 'I': convert(distance, type,'I');
break;
default: cout<<"\nYOU ENTERED A WRONG CHOICE!!!";
exit(0);
}
cout<<"\nDISTANCE = " <<distance<<" " << type << "\n";
getch();
}
void convert(float &d, char &t, char ch)
{
switch(ch)
{
case 'F': if(t=='I')
{
d=d/12;
t='F';
}
break;
case 'I': if(t=='F')
{
d=d*12;
t='I';
}
break;
}
}
/*OUTPUT
DISTANCE = 300 I
*/
//TO SET LARGER OF THE GIVEN INTEGER TO -1 USING CALL BY REFERENCE RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void setlarge(int &a,int &b)
{
if(a>b)
{
cout<<"\n"<<a<<" IS LARGER AND IS SET TO -1.";
a=-1;
cout<<"\nTHE NEW VALUES ARE : "<<a<<"\t"<<b;
}
else
{
cout<<"\n"<<b<<" IS LARGER AND IS SET TO -1.";
b=-1;
cout<<"\nTHE NEW VALUES ARE : "<<a<<"\t"<<b;
}
void main()
{
int a,b;
clrscr();
cout<<"ENTER TWO NUMBER : "<<endl;
cin>>a>>b;
setlarge(a,b);
getch();
}
/*OUTPUT
*/
// TO INVOKE A FUNCTION TAKING NO ARGUMENTS AND RETURNING NO VALUE
RETURN TO INDEX
#include<iostream.h>
#include<string.h>
#include<conio.h>
void func(void);
void main()
{
clrscr();
func();
getch();
}
void func(void)
{
char name[25];
cout<<"\nENTER YOUR NAME : ";
cin.getline(name,25);
int len=strlen(name);
cout.write("HELLO ",7).write(name,len);
return;
getch();
}
/* TO INVOKE A FUNCTION THAT TAKES TWO INTEGERS AND AN ARITHMETIC OPERATOR THEN
DISPLAYS THE CORRESPONDING RESULT.*/
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<process.h>
void main()
{
clrscr();
void calc(int,int, char);
int a,b;
char ch;
cout<<"\nENTER TWO INTEGERS : "<<endl;
cin>>a>>b;
cout<<"\nENTER ATHE ARITHMETIC OPERATOR (+,-,*,%) : \n";
cin>>ch;
calc(a,b,ch);
getch();
}
void calc(int x, int y, char c)
{
switch(c)
{
case '+': cout<<"\nSUM OF " <<x<<" AND "<<y<< " IS " <<(x+y);
break;
case '-': cout<<"\nDIFFERENCE OF " <<x<<" AND " << y;
cout<<" IS " << (x+y);
break;
case '*': cout<<"\nPRODUCT OF " <<x<<" AND "<<y;
cout<<" IS "<<(x*y);
break;
case '/': if(x<y)
{
cout<<"\nFIRST INTEGER SHOULD BE ";
cout<<"GREATER THAN THE SECOND.";
exit(0);
}
cout<<"\nQUOTIENT " <<x<<" / " <<y<<" IS "<<(x/y);
break;
case '%': if(x<y)
{
cout<<"\nFIRST INTEGER SHOULD BE ";
cout<<"GREATER THAN THE SECOND.";
exit(0);
}
cout<<"\nREMAINDER : "<<x<<" % " <<y<<" IS "<<(x%y);
break;
default : cout<<"\nWRONG OPERATOR!!!";
break;
}
return;
}
// TO SORT AN INTEGER ARRAY USING FUNCTION
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
void sort(int num[], int size)
{
int swap=1, temp;
do
{
swap=0;
for(int i=0;i<size-1;i++)
{
if(num[i]>num[i+1])
{
temp=num[i];
num[i]=num[i+1];
num[i+1]=temp;
swap=1;
}
}
}while(swap==1);
cout<<"\n";
}
void main()
{
void sort(int[],int s);
int n[100], s=10, temp, count;
clrscr();
cout<<"\nENTER 10 NUMBERS FOR AN ARRAY TO BE SORTED :\n";
for(count=0;count<s;count++)
cin>>n[count];
temp=count;
sort(n,count);
for(count=0;count<temp;count++)
cout<<n[count]<<"\t";
getch();
}
/*OUTPUT
*/
//STUDENT MARKSHEET USING FUNCTIONS RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
int getdata(void);
float calcperc(int,int,int);
void printresults(int,int,int,float,char);
char calcgrade(float);
int m1,m2,m3,tot;
float perc;
char grade;
clrscr();
m1=getdata();
m2=getdata();
m3=getdata();
perc=calcperc(m1,m2,m3);
grade=calcgrade(perc);
printresults(m1,m2,m3,perc,grade);
getch();
}
int getdata(void)
{
int marks;
void err_msg(void);
do
{
cout<<"ENTER MARKS : ";
cin>>marks;
if(marks<0||marks>100)
err_msg();
}while(marks<0||marks>100);
return marks;
}
void err_msg(void)
{
cout<<"MARKS ARE OUT OF 100"<<endl;
cout<<"\nPLEASE ENTER MARKS BETWEEN 0 TO 100";
cout<<"\nTRY AGAIN";
getch();
}
float calcperc(int s1,int s2,int s3)
{
float per;
per=(s1+s2+s3)/3;
return per;
}
char calcgrade(float per)
{
char grade;
if(per>80)
grade='A';
else if(per>60)
grade='B';
else if (per>40)
grade='C';
else
grade='D';
return grade;
}
void printresults(int s1,int s2,int s3,float p,char g)
{
cout<<"MARKS IN SUBJECT 1 : "<<s1;
cout<<"\nMARKS IN SUBJECT 2 : "<<s2;
cout<<"\nMARKS IN SUBJECT 3 : "<<s3;
cout<<"\nPERCENTAGE SCORE : " << p;
cout<<"\nGRADE SECURED : "<<g;
}
/*OUTPUT
ENTER MARKS : 98
ENTER MARKS : 89
ENTER MARKS : 78
MARKS IN SUBJECT 1 : 98
MARKS IN SUBJECT 2 : 89
MARKS IN SUBJECT 3 : 78
PERCENTAGE SCORE : 88
GRADE SECURED : A
*/
// PALINDROME STRING RETURN
TO INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char ch[10];
int scount,ocount,read=1, len;
clrscr();
cout <<"ENTER A WORD : ";
cin>>ch;
len=strlen(ch);
for(scount=1, ocount=len; scount<=len/2 || ocount>=len/2; scount++, ocount--)
{
if(ch[scount]!=ch[ocount])
read=0;
}
if(read==1)
cout<<"YES! THE WORD IS PALINDROME.";
else
cout<<"NO! THE WORD IS NOT PALINDROME.";
getch();
}
//FIND CHARACTER POSITION IN A STRING RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int findpos(char s[],char c);
char string[80],ch;
int y=0;
cout<<"\nENTER MAIN STRING :\n";
cin.getline(string, 80);
cout<<"\nENTER CHARACTER TO BE SEARCH FOR : ";
cin.get(ch);
y=findpos(string,ch);
if(y==-1)
cout<<"\nSORRY!! THE CHARACTER IS NOT IN STRING.";
getch();
}
int findpos(char s[], char c)
{
int flag=-1;
for(int i=0; s[i]!='\0';i++)
{
if(s[i]==c)
{
flag=0;
cout<<"\nTHE CHARACTER IN THE STRING IS AT POSITION : "<<i+1;
}
}
return (flag);
}
/*OUTPUT
*/
// PROGRAM TO FIND WHETHER TWO STRINGS CONTAIN EQUAL NUMBER OF CHARACTERS.
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
char str1[50], str2[50];
clrscr();
cout<<"ENTER THE FIRST STRING : ";
cin.getline(str1, 49);
cout<<"ENTER THE SECOND STRING : ";
cin.getline(str2, 49);
if(strlen(str1)==strlen(str2))
{
cout<<"\nBOTH STRINGS CONTAIN EQUAL NUMBER OF CHARACTERS.";
}
else
{
cout<<"\nBOTH STRINGS CONTAIN DIFFERENT NUMBER OF CHARACTERS.";
}
getch();
}
/*OUTPUT
*/
// CHECK WHETHER A CHARACTER IS ALPHANUMETRIC OR NOT
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
void main()
{
clrscr();
char ch;
int a;
cout<<"ENTER A CHARACTER : ";
cin>>ch;
a=ch;
if(isalnum(a))
{
cout<<"\nIT IS AN ALPHANUMERIC ";
if(isdigit(a))
cout<<"AND DIGIT CHARACTER. ";
else
cout<<"AND ALPHABETIC CHARACTER.";
}
else
cout<<"\nIT IS SOME OTHER NON-ALPHANUMERIC CHARACTER.";
getch();
}
/*OUTPUT
ENTER A CHARACTER : R
ENTER A CHARACTER : 7
ENTER A CHARACTER : %
*/
// CHANGE THE CASE OF A CHARACTER RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
void main()
{
clrscr();
char ch;
cout<<"\nENTER A CHARACTER : ";
cin>>ch;
if(ch=='\n')
{
ch=getchar();
}
if(isalpha(ch))
{
if(islower(ch))
{
cout<<"\nYOU INPUT A LOWERCASE ALPHABET.";
ch=ch-32;
cout<<"\n\nTHE UPPERCASE ALPHABET IS : "<<ch;
}
else if(isupper(ch))
{
cout<<"\nYOU INPUT AN UPPERCASE LETTER.";
ch=ch+32;
cout<<"\n\nTHE LOWERCASE ALPHABET IS : "<<ch;
}
}
else
cout<<"\nYOU INPUT A NON-ALPHABETICAL CHARACTER.";
getch();
}
/*OUTPUT
ENTER A CHARACTER : R
ENTER A CHARACTER : r
*/
// COPY SMALLER STRING INTO THE BIGGER STRING
RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str1[50], str2[50];
int len1, len2;
cout<<"\nENTER THE FIRST STRING: \n";
cin.getline(str1, 50);
cout<<"\nENTER THE SECOND STRING :\n";
cin.getline(str2, 50);
if(strlen(str1)>strlen(str2))
{
strcpy(str1, str2);
cout<<"\nSECOND STRING IS COPIED INTO THE FIRST STRING. \n";
cout<<str1;
}
else if(strlen(str2)>strlen(str1))
{
strcpy(str2,str1);
cout<<"\nFIRST STRING IS COPIED INTO THE SECOND STRING.\n";
cout<<str2;
}
else if(strlen(str1)==strlen(str2))
{
cout<<"\nSTRINGS ARE OF EQUAL SIZE. \n";
cout<<"\nSTRING1 IS : ";
cout<<str1;
cout<<"\nSTRING2 IS : ";
cout<<str2;
}
getch();
}
/*OUTPUT
*/
// APPEND THE FIRST STRING TO THE SECOND RETURN
TO INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str1[25], str2[50];
cout<<"\nENTER FIRST STRING : ";
cin.getline(str1, 25);
cout<<"\nENTER THE SECOND STRING : ";
cin.getline(str2, 25);
strcat(str2, str1);
cout<<"\n"<<str2;
getch();
}
/*OUTPUT
GOOD MORNING
ABHISHEK AGRAWAL
//TO JUSTIFY A GIVEN STRING RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
char str1[80],str2[80];
int count1=0,count2=0,count3=0,count4=0,count5=0, count=0;
void white_spaces(char a[]);
void justify(int);
void main()
{
clrscr();
cout<<"ENTER A STRING : ";
cin.getline(str1, 80);
white_spaces(str1);
justify(count4);
cout<<"\nTHE JUSTIFIED STATEMENT IS :\n";
for(count=0;count<80;count++)
cout<<str2[count];
getch();
}
void white_spaces(char a[])
{
for(count=0;count<80;count++)
{
if(a[count]==' ')
count1++;
else
count2++;
if(a[count]=='\0')
{
count3=80-count2-count1;
break;
}
}
count4=count3/count1;
}
void justify(int b)
{
for(count=0, count1=0;count1<80;count++, count1++)
{
str2[count1]=str1[count];
if(str1[count]==' ')
{
for(count5=0;count5<b;count5++)
{
count1++;
str2[count1]=' ';
}
}
}
}
*/// EMPLOYEE DATABASE USING ARRAYS RETURN
TO INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
int eno[25],count,emp,swap=1; char grade[25];
char name[25][25],tempn[25][25]; long float comm[25],temp;
clrscr();
cout<<"ENTER THE NUMBER OF EMPLOYEES FOR DATABASE : ";
cin>>emp;
for(count=0;count<emp;count++)
{
cout<<"\n\nENTER EMPLOYEE NAME : ";
cin>>name[count];
cout<<"\nENTER EMPLOYEE NUMBER : ";
cin>>eno[count];
cout<<"\nENTER EMPLOYEE COMMISSION : ";
cin>> comm[count];
if(comm[count]>60000)
grade[count]='A';
else if(comm[count]>40000)
grade[count]='B';
else if(comm[count]>20000)
grade[count]='C';
else
grade[count]='D';
}
clrscr();
do
{
swap=0;
for(count=0;count<(emp-1);count++)
{
if(eno[count]>eno[count+1])
{
temp=eno[count];
eno[count]=eno[count+1];
eno[count+1]=temp;
strcpy(tempn[count],name[count]);
strcpy(name[count],name[count+1]);
strcpy(name[count+1],tempn[count]);
temp=comm[count];
comm[count]=comm[count+1];
comm[count+1]=temp;
swap=1;
temp=grade[count];
grade[count]=grade[count+1];
grade[count+1]=temp;
}
}
}while(swap==1);
cout<< "EMPLOYEE DETAILS: "<<endl<<endl;
cout<< "\nNAME\t\tNUMBER\t\tGRADE\t\tCOMMISSION"<<endl<<endl;
for(count=0;count<emp;count++)
{
cout<<name[count]<<"\t\t"<<eno[count]<<"\t\t";
cout<<grade[count]<<"\t\t"<<comm[count]<<endl<<endl;
}
getch();
}
/*OUTPUT
EMPLOYEE DETAILS:
JAY 3 C 27000
RAM 7 A 636363
PRASAD 10 B 45983
BARNIK 12 D 19875
VINAY 35 C 37945
*/
//A HOTEL FOOD BILLING PROGRAM. RETURN
TO INDEX
#include<iostream.h>
#include<conio.h>
#include<string.h>
//VARIABLES USED
int choice, bill=0, r1, r2, r3, count=0, prod=0;
char rachit[50]; char items[50][50];
//FUNCTIONS DECLARATIONS
void copyright();
void border();
void entry();
void hello();
void menu();
void bil(int);
//MAIN PROGRAM
void main()
{
entry();
do
{
menu();
gotoxy(7,43);
cout<<"ENTER YOUR CHOICE : ";
cin>>choice;
while(choice<0||choice>31)
{
gotoxy(7,45);
cout<<"INVALID ENTRY. PLEASE RE-ENTER YOUR CHOICE : ";
cin>>choice;
}
switch(choice)
{
case 1:bill+=25; hello(); break;
case 2:bill+=45; hello(); break;
case 3:bill+=30; hello(); break;
case 4:bill+=35; hello(); break;
case 5:bill+=40; hello(); break;
case 6:bill+=45; hello(); break;
case 7:bill+=25; hello(); break;
case 8:bill+=35; hello(); break;
case 9:bill+=40; hello(); break;
case 10:bill+=10; hello(); break;
case 11:bill+=45; hello(); break;
case 12:bill+=45; hello(); break;
case 13:bill+=10; hello(); break;
case 14:bill+=20; hello(); break;
case 15:bill+=25; hello(); break;
case 16:bill+=15; hello(); break;
case 17:bill+=20; hello(); break;
case 18:bill+=20; hello(); break;
case 19:bill+=20; hello(); break;
case 20:bill+=25; hello(); break;
case 21:bill+=40; hello(); break;
case 22:bill+=20; hello(); break;
case 23:bill+=35; hello(); break;
case 24:bill+=40; hello(); break;
case 25:bill+=35; hello(); break;
case 26:bill+=35; hello(); break;
case 27:bill+=15; hello(); break;
case 28:bill+=40; hello(); break;
case 29:bill+=45; hello(); break;
case 30:bill+=45; hello(); break;
default: bill+=0;
}
prod++;
}while(choice>0 && choice<31);
bil(prod);
copyright();
}
void border()
{
for(r3=3; r3<=79; r3++)
{
gotoxy(r3,1);
cout<<"*";
gotoxy(r3,50);
cout<<"*";
}
for (count=0;deci>=1;count++)
{
octa[count]=deci%8;
deci=deci/8;
}
for(count--;count>=0;count--)
cout<<octa[count];
getch();
}
//BINARY TO HEXADECIMAL RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int bin, digit, a=0, deci=0,long temp[9]; char result[9];
cout<<"\nENTER A BINARY NUMBER : ";
cin>>bin;
for(int count=0;bin>=1;count++)
{
digit=bin%10;
while(digit>1)
{
cout<<"\nOOPS!!! ERROR. RE-ENTER : ";
cin>>bin;
digit=bin%10;
}
a=digit*pow(2,count);
deci+=a;
bin/=10;
}
for (count1=0;deci>=1;count1++)
{
temp[count1]=deci%16;
deci=deci/16;
if(temp[count1]>9)
{
switch(temp[count1])
{
case 10:result[count1]='A';
break;
case 11:result[count1]='B';
break;
case 12:result[count1]='C';
break;
case 13:result[count1]='D';
break;
case 14:result[count1]='E';
break;
case 15:result[count1]='F';
break;
}
}
else
{
result[count1]=temp[count1]+48;
}
}
cout<<"\n";
for(count=count-1; count>=0;count--)
cout<<result[count];
getch();
}
//OCTAL TO DECIMAL RETURN TO INDEX
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int oct, digit, a=0, deci=0;
cout<<"\nENTER A OCTAL NUMBER : ";
cin>>oct;
for(int count=0;oct>=1;count++)
{
digit=oct%10;
while(digit>7)
{
cout<<"\nOOPS!!! ERROR. RE-ENTER : ";
cin>>oct;
digit=oct%10;
}
a=digit*pow(8,count);
deci+=a;
oct/=10;
}
cout<<"\nTHE DECIMAL NUMBER IS : "<<deci;
getch();
}
//OCTAL TO BINARY RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
int oct, digit, a=0, deci=0;
cout<<"\nENTER A OCTAL NUMBER : ";
cin>>oct;
for(int count=0;oct>=1;count++)
{
digit=oct%10;
while(digit>7)
{
cout<<"\nOOPS!!! ERROR. RE-ENTER : ";
cin>>oct;
digit=oct%10;
}
a=digit*pow(8,count);
deci+=a;
oct/=10;
}
int temp[9];
for (count=0;deci>=1;count++)
{
temp[count]=deci%2;
deci=deci/2;
}
for(count--;count>=0;count--)
cout<<temp[count];
getch();
}
//OCTAL TO HEXADECIMAL RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
long oct, digit, a=0, deci=0,temp[9];;
cout<<"\nENTER A OCTAL NUMBER : ";
cin>>oct;
for(int count=0;oct>=1;count++)
{
digit=oct%10;
while(digit>7)
{
cout<<"\nOOPS!!! ERROR. RE-ENTER : ";
cin>>oct;
digit=oct%10;
}
a=digit*pow(8,count);
deci+=a;
oct/=10;
}
char result[9]={0};
for (count=0;deci>=1;count++)
{
temp[count]=deci%16;
deci=deci/16;
if(temp[count]>9)
{
switch(temp[count])
{
case 10:result[count]='A';
break;
case 11:result[count]='B';
break;
case 12:result[count]='C';
break;
case 13:result[count]='D';
break;
case 14:result[count]='E';
break;
case 15:result[count]='F';
break;
}
}
else
{
result[count]=temp[count]+48;
}
}
cout<<"\n";
for(count=count-1; count>=0;count--)
cout<<result[count];
getch();
}
//HEXADECIMAL TO DECIMAL RETURN TO
INDEX
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();
char hex[8];
long temp[8],sum=0;
cin>>hex;
for(int i=0;hex[i]!='\0';i++)
{
if(isdigit(hex[i]))
temp[i]=hex[i]-48;
else if(isalpha(hex[i]))
{
switch(hex[i])
{
case 'A':temp[i]=10;break;
case 'B':temp[i]=11;break;
case 'C':temp[i]=12;break;
case 'D':temp[i]=13;break;
case 'E':temp[i]=14;break;
case 'F':temp[i]=15;break;
}
}
}
i--;
for(int x=0;i>=0;i--, x++)
sum=sum+(temp[i]*pow(16,x));
cout<<"\n\n"<<sum;
getch();
}
//HEXADECIMAL TO BINARY RETURN
TO INDEX
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();
char hex[8];
long temp[8],sum=0;
cin>>hex;
for(int i=0;hex[i]!='\0';i++)
{
if(isdigit(hex[i]))
temp[i]=hex[i]-48;
else if(isalpha(hex[i]))
{
switch(hex[i])
{
case 'A':temp[i]=10;break;
case 'B':temp[i]=11;break;
case 'C':temp[i]=12;break;
case 'D':temp[i]=13;break;
case 'E':temp[i]=14;break;
case 'F':temp[i]=15;break;
}
}
}
i--;
for(int x=0;i>=0;i--, x++)
sum=sum+(temp[i]*pow(16,x));
long t[25];
for (int count=0;sum>=1;count++)
{
t[count]=sum%2;
sum=sum/2;
}
for(count--;count>=0;count--)
cout<<t[count];
getch();
}
//HEXADECIMAL TO OCTAL RETURN
TO INDEX
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>
#include<ctype.h>
#include<process.h>
void main()
{
clrscr();
char hex[8];
long temp[8],sum=0;
cin>>hex;
for(int i=0;hex[i]!='\0';i++)
{
if(isdigit(hex[i]))
temp[i]=hex[i]-48;
else if(isalpha(hex[i]))
{
switch(hex[i])
{
case 'A':temp[i]=10;break;
case 'B':temp[i]=11;break;
case 'C':temp[i]=12;break;
case 'D':temp[i]=13;break;
case 'E':temp[i]=14;break;
case 'F':temp[i]=15;break;
}
}
}
i--;
for(int x=0;i>=0;i--, x++)
sum=sum+(temp[i]*pow(16,x));
long t[25];
for (int count=0;sum>=1;count++)
{
t[count]=sum%8;
sum=sum/8;
}
for(count--;count>=0;count--)
cout<<t[count];
getch();
}
//TO TRANSLATE NUMBER INTO WORDS RETURN TO
INDEX
cout<<"\n\n\nPRESS N FOR THE NEXT MONTH AND P FOR THE PREVIOUS MONTH.";
cout<<"\nPRESS E EXIT\n\nYOUR CHOICE : ";
cin>>choice1;
if(choice1=='n'||choice1=='N')
{
month1++;
if(month1>12)
month1-=12;
pos=i%7;
goto check;
}
else if(choice1=='p'||choice1=='P')
{
month1--;
if(month1<1)
month1+=12;
pcheck();
goto check;
}
else
cout<<"\n\nTHANX FOR USING THE PROGRAM. PRESS ANY KEY TO EXIT";
getch();
}
void pcheck()
{
if
(month1==1||month1==3||month1==5||month1==7||month1==8||month1==10||month1==12)
m4();
else if(month1==4||month1==6||month1==9||month1==11)
m5();
else if(month1==2)
m6();
pos=i;
}
void fcheck(int t)
{
if(t==2)
cout<<"\t";
else if(t==3)
cout<<"\t"<<"\t";
else if(t==4)
cout<<"\t"<<"\t"<<"\t";
else if(t==5)
cout<<"\t"<<"\t"<<"\t"<<"\t";
else if(t==6)
cout<<"\t"<<"\t"<<"\t"<<"\t"<<"\t";
else if(t==7)
cout<<"\t"<<"\t"<<"\t"<<"\t"<<"\t"<<"\t";
}
void m1()//m1 for type of months having 31 days
{
int count;
for(i=pos, count=1;count<=31;i++, count++)
{
cout<<count<<"\t";
if(i%7==0)
cout<<"\n";
}
}
void m2()//m2 for type of months having 30 days
{
int count;
for(i=pos, count=1;count<=30;i++, count++)
{
cout<<count<<"\t";
if(i%7==0)
cout<<"\n";
}
}
void m3()//m3 for type of months having 28 days
{
int count;
for(i=pos, count=1;count<=28;i++, count++)
{
cout<<count<<"\t";
if(i%7==0)
cout<<"\n";
}
}
void m4()//m4 for type of months having 31 days
{
int count;
for(i=pos, count=31;count>=1;i--, count--)
{
if(i<=0)
i=7;
}
}
void m5()//m2 for type of months having 30 days
{
int count;
for(i=pos, count=30;count>=1;i--, count--)
{
if(i<=0)
i=7;
}
}
void m6()//m3 for type of months having 28 days
{
int count;
for(i=pos, count=28;count>=1;i--, count--)
{
if(i<=0)
i=7;
}
}
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<process.h>
#include<ctype.h>
#include<dos.h>
#include<bios.h>
void prog();
char rachit[25],t, ltype,start,namex[10][15],xname[25];
long num1=0, fact, gfact, fsum, num3, fact1, count1, num4, fact2, gfact1,
bdate,tempo, date, gdate, month, year, julian, fours,hundreds, four_hundreds,
day, digit2, sum, digit3,basicn, digit4, luck;
void check(long);
void pyramid(int);
void matrices(int);
void birth_date(long);
void border()
{
clrscr();
for(r1=3; r1<=79; r1++)
{
gotoxy(r1,1);
cout<<"*";
gotoxy(r1,50);
cout<<"*";
}
for(r2=1; r2<=50; r2++)
{
gotoxy(3,r2);
cout<<"*";
gotoxy(79,r2);
cout<<"*";
}
}
void copyright()
{
clrscr();
border();
gotoxy(22,18);
cout << "PROGRAM EXCLUSIVELY CREATED BY :";
gotoxy(30,20);
cout << "RACHIT AGRAWAL ";
gotoxy(20,22);
cout << "EMAIL: rachit.agrawal9@gmail.com";
gotoxy(15,24);
cout << "PROGRAM TO BE DISTRIBUTED FREELY AS SHAREWARE.";
gotoxy(25,26);
cout << "PROGRAM CODE NOT TO BE MODIFIED.";
gotoxy(10,28);
cout << "MODIFICATIONS WITHOUT HIS PRIOR PERMISSION INVITE LEGAL
ACT.";
gotoxy(15,30);
cout << "SUGGESTIONS AND COMMENTS WILL BE APRRECIATED.";
gotoxy(25,32);
cout << "THANK YOU "<<rachit<<" FOR USING THE PROGRAM. ";
gotoxy(27,34);
cout << "HAVE A PROGRESSIVE DAY! ";
getch();
}
void entry()
{
clrscr ();
for(r1=7; r1<=73; r1++)
{
gotoxy(r1,16);
cout<<"*";
gotoxy(r1,22);
cout<<"*";
}
for( r2=17; r2<=21; r2++)
{
gotoxy(7,r2);
cout<<"*";
gotoxy(73,r2);
cout<<"*";
}
gotoxy(9,19);
cout << "PLEASE ENTER YOUR NAME : ";
cin.getline ( rachit, 24);
}
void confirm()
{
if (bioskey(1)!=0)
{
bioskey(0);
copyright();
prog();
}
}
void loading()
{
int i,x;
clear(1,1,80,50);
box(1,1,79,49,'*');
box(27,5,26,6,'*');
gotoxy(29,7);
cout<<"I N S T R U C T I O N S";
gotoxy(29,8);
cout<<"=======================";
box(5,20,71,9,'*');
gotoxy(7,22);
cout<<"YOU CAN EASILY MOVE THROUGH THE MENU.";
gotoxy(7,24);
cout<<"PROPER LINKS TO PROGRAMS HAVE BEEN PROVIDED.";
gotoxy(7,26);
cout<<"KINLDY COOPERATE WITH ON SCREEN MESSEGES SEPARATELY.";
box(18,40,44,3,'*');
gotoxy(18,39);
cout<<"LOADING PLEASE WAIT:";
int p;
for (i=1,x=19,p=16;p<=100;i++,x+=2, p+=4)
{
gotoxy(56,39);
cout<<p<<"%";
gotoxy(x,41);
cout<<">";
delay(300);
gotoxy(x,41);
cout<<"--";
confirm();
}
clrscr();
}
void main_scr()
{
char txt[100]={" R A C H I T P R E S E N T S "};
int i,x,m,n;;
box(1,1,79,49,'*');
box(5,5,71,7,'*');
for (m=25,n=8,i=0;txt[i]!=0;i++,m++)
{
gotoxy(m,n);
cout<<txt[i];
delay(150);
gotoxy(m,n);
cout<<txt[i];
confirm();
}
clear(6,11,75,11);
box(5,5,71,10,'*');
strcpy(txt," A N E W A C H I E V E M E N T ");
for (m=24,n=11,i=0;txt[i]!='\0';i++,m++)
{
gotoxy(m,n);
cout<<txt[i];
delay(150);
gotoxy(m,n);
cout<<txt[i];
confirm();
}
int len;
strcpy(txt," BEST PROGRAMS ");
len=strlen(txt);
m=45/len;
box(18,25,44,7,'*');
gotoxy(45,44);
cout<<"PRESS ANY KEY TO CONTINUE...";
gotoxy(17,20);
cout<<" W E L C O M E !! "<<rachit;
int r;
void main_menu()
{
int x=7,y=4;
border();
gotoxy(x,y);y+=2;
cout << " WELCOME " << rachit <<" !! SELECT ONE PROGRAM FOR
EXECUTION : "<<endl;
gotoxy(x,y);y+=2;
cout << " 1 " << " SIMPLE CALCULATOR " << endl;
gotoxy(x,y);y+=2;
cout << " 2 " << " NUMBER DETAILS " << endl;
gotoxy(x,y);y+=2;
cout << " 3 " << " PYRAMIDS " << endl;
gotoxy(x,y);y+=2;
cout << " 4 " << " MATRICES " << endl;
gotoxy(x,y);y+=2;
cout << " 5 " << " CARD GAME " << endl;
gotoxy(x,y);y+=2;
cout << " 6 " << " NUMEROLOGY " << endl;
gotoxy(x,y);y+=2;
cout << " 7 " << " ARRAY PROGRAMS " << endl;
gotoxy(x,y);y+=2;
cout << " 8 " << " MENSURATION " << endl;
gotoxy(x,y);y+=2;
cout << " 9 " << " NUMBER SYSTEMS " << endl;
gotoxy(x,y);y+=2;
cout << " 10 " << " EXIT " << endl;
}
void cal_menu()
{
int x=24,y=16;
gotoxy(x,y);y+=2;
cout << " CALCULATOR " << endl;
gotoxy(x,y);y+=2;
cout << " 1 " << " ADD " << endl;
gotoxy(x,y);y+=2;
cout << " 2 " << " SUBTRACT " << endl;
gotoxy(x,y);y+=2;
cout << " 3 " << " MULTIPLY " << endl;
gotoxy(x,y);y+=2;
cout << " 4 " << " DIVIDE " << endl;
gotoxy(x,y);y+=2;
cout << " 5 " << " EXIT " << endl;
}
void num_details()
{
int x=24,y=16;
border();
gotoxy(x,y);y+=2;
cout << " NUMBER DETAILS " << endl;
gotoxy(x,y);y+=2;
cout << " 1 " << " FACTORS " << endl;
gotoxy(x,y);y+=2;
cout << " 2 " << " PERFECT NUMBER " << endl;
gotoxy(x,y);y+=2;
cout << " 3 " << " PRIME NUMBER " << endl;
gotoxy(x,y);y+=2;
cout << " 4 " << " ALL IN ONE " << endl;
gotoxy(x,y);y+=2;
cout << " 5 " << " EXIT " << endl;
}
void pyramenu()
{
b: clrscr();
border();
int x=7,y=6;
gotoxy(x,y);y+=2;
cout << " 1 " << " PYRAMID 1 " << endl;
gotoxy(x,y);y+=2;
cout << " 2 " << " PYRAMID 2 " << endl;
gotoxy(x,y);y+=2;
cout << " 3 " << " PYRAMID 3 " << endl;
gotoxy(x,y);y+=2;
cout << " 4 " << " PYRAMID 4 " << endl;
gotoxy(x,y);y+=2;
cout << " 5 " << " PYRAMID 5 " << endl;
gotoxy(x,y);y+=2;
cout << " 6 " << " PYRAMID 6 " << endl;
gotoxy(x,y);y+=2;
cout << " 7 " << " PYRAMID 7 " << endl;
gotoxy(x,y);y+=2;
cout << " 8 " << " PYRAMID 8 " << endl;
gotoxy(x,y);y+=2;
cout << " 9 " << " PYRAMID 9 " << endl;
gotoxy(x,y);y+=2;
cout << " 10 " << " PYRAMID 10 " << endl;
gotoxy(x,y);y+=2;
cout << " 11 " << " PYRAMID 11 " << endl;
gotoxy(x,y);y+=2;
cout << " 12 " << " PYRAMID 12 " << endl;
gotoxy(x,y);y+=2;
cout << " 13 " << " EXIT " << endl<<endl;
int p;
gotoxy(x,y);y+=2;
cout<<"ENTER YOUR CHOICE FROM THE ABOVE MENU: ";
cin>>p;
pyramid(p);
if(p<13)
goto b;
copyright();
}
void matmenu()
{
a: clrscr();
border();
int x=7,y=6;
gotoxy(x,y);y+=2;
cout << " 1 " << " ADDITION OF TWO MATRICES " << endl;
gotoxy(x,y);y+=2;
cout << " 2 " << " SUBTRACTION OF TWO MATRICES " << endl;
gotoxy(x,y);y+=2;
cout << " 3 " << " MULTIPLICATION OF TWO MATRICES " << endl;
gotoxy(x,y);y+=2;
cout << " 4 " << " ROW SUM AND COLUMN SUM OF A MATRIX " << endl;
gotoxy(x,y);y+=2;
cout << " 5 " << " SUM OF ELEMENTS ABOVE AND BELOW THE MAIN
DIAGONAL OF MATRIX " << endl;
gotoxy(x,y);y+=2;
cout << " 6 " << " TRANSPOSE A MATRIX " << endl;
gotoxy(x,y);y+=2;
cout << " 7 " << " EXIT " << endl;
gotoxy(x,y);y+=2;
cout<<"ENTER YOUR CHOICE FROM THE ABOVE MENU : ";
int p;
cin>>p;
if(p>7)
goto a;
else if(p==7)
{
copyright(); prog();
}
else
matrices(p);
getch();
void xmenu()
{
sh: clrscr();
border();
int x=7,y=4;
gotoxy(x,y);y+=2;
cout<<"1 CONVERT DECIMAL NUMBER TO BINARY NUMBER";
gotoxy(x,y);y+=2;
cout<<"2 CONVERT DECIMAL NUMBER TO OCTAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"3 CONVERT DECIMAL NUMBER TO HEXADECIMAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"4 CONVERT BINARY NUMBER TO DECIMAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"5 CONVERT BINARY NUMBER TO OCTAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"6 CONVERT BINARY NUMBER TO HEXADECIMAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"7 CONVERT OCTAL NUMBER TO DECIMAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"8 CONVERT OCTAL NUMBER TO BINARY NUMBER";
gotoxy(x,y);y+=2;
cout<<"9 CONVERT OCTAL NUMBER TO HEXADECIMAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"10 CONVERT HEXADECIMAL NUMBER TO DECIMAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"11 CONVERT HEXADECIMAL NUMBER TO BINARY NUMBER";
gotoxy(x,y);y+=2;
cout<<"12 CONVERT HEXADECIMAL NUMBER TO OCTAL NUMBER";
gotoxy(x,y);y+=2;
cout<<"13 EXIT ";
gotoxy(x,y);y+=2;
cout << "ENTER YOUR CHOICE (1 to 13) : ";
cin >> choice;
while(choice<1 || choice>13)
goto sh;
check(choice);
}
void array_prog()
{
int x=24,y=16;
border();
gotoxy(x,y);y+=2;
cout << " ARRAY PROGRAMS " << endl;
gotoxy(x,y);y+=2;
cout << " 1 " << " SORT " << endl;
gotoxy(x,y);y+=2;
cout << " 2 " << " SEARCH " << endl;
gotoxy(x,y);y+=2;
cout << " 3 " << " REVERSE " << endl;
gotoxy(x,y);y+=2;
cout << " 4 " << " EXIT " << endl;
}
void mensuration()
{
int x=7,y=4;
border();
gotoxy(x,y);y+=2;
cout<<"MENSURATION";
gotoxy(x,y);y+=2;
cout<<"1 VOLUME OF CUBOID";
gotoxy(x,y);y+=2;
cout<<"2 VOLUME OF CUBE";
gotoxy(x,y);y+=2;
cout<<"3 VOLUME OF CYLINDER";
gotoxy(x,y);y+=2;
cout<<"4 VOLUME OF CONE";
gotoxy(x,y);y+=2;
cout<<"5 VOLUME OF SPHERE";
gotoxy(x,y);y+=2;
cout<<"6 AREA OF SQUARE";
gotoxy(x,y);y+=2;
cout<<"7 AREA OF RECTANGLE";
gotoxy(x,y);y+=2;
cout<<"8 AREA OF TRIANGLE";
gotoxy(x,y);y+=2;
cout<<"9 AREA OF CIRCLE";
gotoxy(x,y);y+=2;
cout<<"10 CIRCUMFERENCE OF CIRCLE";
gotoxy(x,y);y+=2;
cout<<"11 EXIT";
gotoxy(x,y);y+=2;
}
void simple_calculator()
{
do
{
clrscr ();
border();
cal_menu();
gotoxy(24,28);
cout << " ENTER YOUR CHOICE : ";
cin>>choice1;
while(choice1>5 && choice1<1)
{
clrscr();
border();
cal_menu();
gotoxy(24,28);
cout<<" INVALID CHOICE !!!"<<endl;
gotoxy(24,30);
cout<<" PLEASE RE-ENTER YOUR CHOICE : ";
cin>>choice1;
}
if (choice1 == 5)
{
copyright();
prog();
break;
}
else
{
clrscr();
border();
cal_menu();
gotoxy(24,28);
cout << " YOUR CHOICE : " << choice1;
gotoxy(24,30);
cout << " ENTER FIRST NUMBER : " ;
cin >> num1;
gotoxy(24,32);
cout << " ENTER SECOND NUMBER : " ;
cin >> num2;
switch (choice1)
{
case 1: result= num1+num2; break;
case 2: result= num1-num2; break;
case 3: result= num1*num2; break;
case 4: result= num1/num2; break;
}
gotoxy(24,34);
cout << " ANSWER = " << result << endl;
gotoxy(24,36);
cout<<" PRESS ENTER TO CONTINUE";
getch();
}
} while (choice1<5 && choice1 >=1);
}
void number_details()
{
do
{
clrscr ();
border();
num_details();
gotoxy(24,28);
cout << " ENTER YOUR CHOICE : ";
cin>>choice1;
while(choice1>5 ||choice1<1)
{
clrscr();
border();
num_details();
gotoxy(24,24);
cout << " 4 " << " EXIT " << endl;
gotoxy(24,28);
cout<<" INVALID CHOICE !!!"<<endl;
gotoxy(24,30);
cout<<" PLEASE RE-ENTER YOUR CHOICE : ";
cin>>choice1;
}
if (choice1 == 5)
{
copyright();
prog();
break;
}
else
{
clrscr();
border();
num_details();
gotoxy(24,28);
cout << " YOUR CHOICE : " << choice1;
switch (choice1)
{
case 1:
gotoxy(24,30);
cout<<"ENTER A NUMBER : ";
cin >> num4;
gotoxy(24,32);
cout<<"THE FACTORS OF " << num4 << " ARE : " << endl
<<endl;
gfact=num4/2;
gotoxy(24,34);
for ( fact2=1; fact2<=gfact; fact2++)
{
if (num4%fact2==0)
cout<<fact2<<" ";
}
cout<<" and " << num4;
break;
case 2:
gotoxy(24,30);
cout << "ENTER THE NUMBER : ";
cin >> num1;
gfact=(num1/2);
for (fact=1, fsum=0; fact<=gfact; fact=fact+1)
{
if (num1%fact==0)
fsum=fsum+fact;
}
gotoxy(24,32);
if (fsum==num1)
cout << "YES, IT IS A PERFECT NUMBER.";
else
cout << "NO, IT IS NOT A PERFECT NUMBER.";
break;
case 3:
gotoxy(24,30);
cout << "ENTER THE NUMBER : ";
cin >> num3;
for (count1=0, fact1=1; fact1<=(num3/2); fact1=fact1+1)
{
if (num3%fact1==0)
count1=count1+1;
}
gotoxy(24,32);
if (count1==1)
cout << "IT IS A PRIME NUMBER. " << endl;
else
cout << "IT IS A COMPOSITE NUMBER. " << endl;
break;
case 4:
gotoxy(24,30);
cout << "ENTER THE NUMBER : ";
cin >> num1;
gfact=(num1/2);
gotoxy(24,32);
cout<<"THE FACTORS OF " << num1 << " ARE : " << endl
<<endl;
gotoxy(24,34);
for (count1=0,fact=1, fsum=0; fact<=gfact; fact=fact+1)
{
if (num1%fact==0)
{
fsum=fsum+fact;
count1++;
cout<<fact<<" ";
}
}
cout<<" and " << num1;
gotoxy(24,36);
if (fsum==num1)
cout << "YES, IT IS A PERFECT NUMBER.";
else
cout << "NO, IT IS NOT A PERFECT NUMBER.";
gotoxy(24,38);
if (count1==1)
cout << "IT IS A PRIME NUMBER. " << endl;
else
cout << "IT IS A COMPOSITE NUMBER. " << endl;
}
gotoxy(24,40);
cout<<"PRESS ENTER TO CONTINUE";
getch();
}
}while(choice1<5 && choice1>=1);
}
int j,k,c,x;
void pyramid(int fx)
{
clrscr();
switch(fx)
{
case 1: //PYRAMID 1
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
{
cout<<j<<" ";
}
cout<<"\n";
}
break;
case 2: //PYRAMID 2
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
{
cout<<i<<" ";
}
cout<<"\n";
}break;
case 3: //PYRAMID 3
for(i=1;i<=9;i++)
{
for(j=1;j<=i;j++)
{
cout<<"* ";
}
cout<<"\n";
}break;
case 4: //PYRAMID 4
for(i=1,c=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
cout<<c<<" ";
c++;
}
cout<<"\n";
}break;
case 5: //PYRAMID 5
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
if(j%2==0)
cout<<"* ";
else
cout<<"@ ";
}
cout<<"\n";
} break;
case 6: //PYRAMID 6
for(i=1;i<=4;i++)
{
for(j=4;j>=i;j--)
{
cout<<" ";
}
for(x=1;x<=i;x++)
{
cout<<x;
}
cout<<"\n";
}break;
case 7: //PYRAMID 7
for(i=1;i<=4;i++)
{
for(j=4;j>=i;j--)
{
cout<<" ";
}
for(x=i;x>=1;x--)
{
cout<<x;
}
cout<<"\n";
}break;
case 8: //PYRAMID 8
for( i=1;i<=4;i++)
{
for(j=4;j>=i;j--)
{
cout<<" ";
}
for( x=i;x>=1;x--)
{
if(x%2==0)
cout<<"*";
else
cout<<"@";
}
cout<<"\n";
}
break;
case 9: //PYRAMID 9
for(i=1;i<=4;i++)
{
for(j=4;j>=i;j--)
{
cout<<" ";
}
for( x=i;x>=1;x--)
{
if(x%2==0)
cout<<"* ";
else
cout<<"@ ";
}
cout<<"\n";
}break;
case 10: //PYRAMID 10
for( i=1;i<=4;i++)
{
for( j=4;j>=i;j--)
{
cout<<" ";
}
for(x=i;x>=1;x--)
{
if(i%2==0)
cout<<"*";
else
cout<<"@";
}
cout<<"\n";
}break;
case 11: //PYRAMID 11
int count,i;
for(count=0;count<=5;count++)
{
for(i=0;i<=count;i++)
cout<<'*';
cout<<endl;
}
for(count=4;count>=0;count--)
{
for(i=count;i>=0;i--)
cout<<'*';
cout<<endl;
}
break;
case 12: //PYRAMID 12
for( i=1;i<=4;i++)
{
for(j=4;j>=i;j--)
{
cout<<" ";
}
for( x=1;x<=i;x++)
{
cout<<x<<" ";
}
cout<<"\n";
}
for(i=3;i>=1;i--)
{
for(int j=i;j<=4;j++)
{
cout<<" ";
}
for(int x=1;x<=i;x++)
{
cout<<x<<" ";
}
cout<<"\n";
} break;
case 13:
copyright();
prog();
break;
}
getch();
}