0% found this document useful (0 votes)
44 views

Computer Science

This document contains programs written in C++ to perform various calculations and operations. It includes 20 programs with examples and outputs: 1. A program to print "Welcome in C++" 2. A program to find the sum of two numbers 3. A program to find the square of a number The document provides the full source code for each program alongside sample inputs and outputs to demonstrate how each program functions. The programs cover topics such as calculations, conditional statements, functions, data types and more.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Computer Science

This document contains programs written in C++ to perform various calculations and operations. It includes 20 programs with examples and outputs: 1. A program to print "Welcome in C++" 2. A program to find the sum of two numbers 3. A program to find the square of a number The document provides the full source code for each program alongside sample inputs and outputs to demonstrate how each program functions. The programs cover topics such as calculations, conditional statements, functions, data types and more.
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 80

COMPUTER

COMPUTER
SCIENCE
SCIENCE
PROGRAMS IN C++
PROGRAMS IN C++
2011-2012
NA
ME: ALOK KUMAR
ROLL NO: 05
1. Program to print WELCOME IN C++.
#include<iotream.!"
#oid main$%
&
cout <<'Welcome in C++ Programming'(
)
O*+P*+
Welcome in C++ Programming.
,. Program to -ind um o- t.o num/er.
#include<iotream.!"
#oid main$%
&
int num10num,0um(
cout<<'Enter Num/er 11 '(
cin""num1(
cout<<'Enter Num/er ,1 '(
cin""num,(
um2num1+num,(
cout<<'3um o- num/er1 '<<um(
)
O*+P*+
Enter Num/er 11 4
Enter Num/er ,1 5
3um o- num/er1 11
6. Program to -ind 7uare o- a num/er.
#include<iotream.!"
#oid main$%
&
int num107uare(
cout<<'Enter num/er1 '(
cin""num1(
7uare2num18num1(
cout<<'37uare o- num/er i1 '<<7uare(
)
O*+P*+
Enter num/er1 4
37uare o- num/er i1 ,4
9. Program to c!ec: .!et!er a num/er i greater t!an or
le t!an ot!er num/er.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int num10num,(
cout<<'Enter #alue -or num 11 (
cin""num1(
cout<<'Enter #alue -or num ,1 '(
cin""num,(
i-$num1"num,%
cout<<'Num1 i greater t!an num ,'(
ele
cout<<'Num1 i maller t!an num ,'(
)
O*+P*+
Enter #alue -or num 11 4
Enter #alue -or num ,1 1;
Num1 i maller t!an num ,
4. Program to calculate percentage mar: -or t!ree
u/<ect.
#include<iotream.!"
#oid main$%
&
-loat Engli!0 Mat!0 3cience0 3um0 Percentage(
cout<<'Enter mar: o- 3u/<ect EN=LI3>0 M?+>3 @ 3CIENCE1 '(
cin""Engli!""Mat!""3cience(
3um2Engli!+Mat!+3cience(
Percentage23um81;;A6;;(
cout<<'Percentage 2 '<<Percentage(
)
O*+P*+
Enter mar: o- 3u/<ect EN=LI3>0 M?+>3 @ 3CIENCE1
B;
BC
B4
Percentage 2 B9.66666666
5. Program t!at read temperature in Celiu and diplaD
it in Ea!ren!eit.
#include<iotream.!"
#oid main$%
&
int Celiu0 Ea!ren!eit(
cout<<'Enter temperature in degree CELCI*31 '(
cin""Celiu(
Ea!ren!eit2B8CeliuA4+6,(
cout<<'+emperature in degree E?>FEN>EI+1 '<<Ea!ren!eit(
)
O*+P*+
Enter temperature in degree CELCI*31 9;
+emperature in degree E?>FEN>EI+1 1;9
G. Program t!at read radiu o- a circle and print it area.
#include<iotream.!"
#oid main$%
&
-loat radiu0area(
cout<<'Enter Fadiu o- circle1 '(
cin""radiu(
area2radiu86.198radiu(
cout<<'?rea o- Circle1 '<<area(
)
O*+P*+
Enter Fadiu o- circle1 19
?rea o- Circle1 514.99
C. Program t!at enter #alue o- H -rom uer and print I 2
,H and J 2 ,H K1.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int H0D0L(
cout<<'Enter H1 '(
cin""H(
D2,8H(
L2,8HK1(
cout<<' I 2 '<<D<<'Mn'<<' J 2 '<<L(
)
O*+P*+
Enter H1 4
I 2 1;
J 2 B
B. Program to con#ert a gi#en num/er o- daD into Dear0
.ee: and daD.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int totaldaD0Dear0.ee:0daD0rem10rem,(
cout<<'Enter total num/er o- daD 1 '(
cin""totaldaD(
Dear2totaldaDA654(
rem12totaldaDN654(
.ee:2rem1AG(
rem,2rem1NG(
daD2rem,(
cout<<'Iear 2 '<<Dear<<'Mt.ee: 2 '<<.ee:<<'MtdaD 2 ' <<daD(
)
O*+P*+
Enter total num/er o- daD 1 B45
Iear 2 , .ee: 2 6, daD 2 ,
1;. Program -or .apping o- t.o num/er uing t!ird
num/er.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int a0 /0 c(
cout<<'Enter a 1 '(
cin""a(
cout<<'Enter / 1 '(
cin""/(
c2a(
a2/(
/2c(
cout<<'Mna2 '<<a<<'Mn'<<'/2 '<</(
)
O*+P*+
Enter a1 4
Enter /1 G
a2 G
/2 4
11. Program -or .apping o- t.o num/er .it!out uing
t!ird #aria/le.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int a0/(
cout<<'Enter a 1 '(
cin""a(
cout<<'Enter / 1 '(
cin""/(
a2a+/(
/2aK/(
a2aK/(
cout<<'Oalue a-ter .apping1 '<<'Mna2 '<<a<<'Mn/2 '<</(
)
O*+P*+
Enter a1 9
Enter /1 B
Oalue a-ter .apping1
a2 B
/2 9
1,. Program to input t!ree num/er and print t!e larget
o- t!ree.
#include<iotream.!"
#oid main$%
&
int H0D0L(
cout<<'Enter t!ree #aria/le 1 '<<'Mn'(
cin""H""D""L(
i-$H"D@@H"L%
cout<<'Mn'<<H<<' i greater'(
i-$D"H@@D"L%
cout<<'Mn'<<D<<' i greater'(
i-$L"H@@L"D%
cout<<'Mn'<<L<<' i greater'(
)
O*+P*+
Enter t!ree #aria/le 1
4
B
6
B i greatet
16. Program to c!ec: .!et!er t!e entered num/er i odd
or e#en.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int num(
cout<<'Enter anD num/er1 (
cin""num(
i-$numN,22;%
cout<<'Num/er i e#en'(
ele
cout<<'Num/er i odd'(
)
O*+P*+
Enter anD num/er1 4
Num/er i odd
Enter anD num/er1 1C
Num/er i e#en
19. Program to -ind 3imple Interet and Compound
Interet.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int P0F0+(
-loat 3I0CI(
cout<<'Enter #alue -or P F +'<<'Mn'(
cin""P""F""+(
3I2P8F8+A1;;(
CI2P8$1+FA1;;%P+(
cout<<'3imple interet2 '<<3I<<'Mn'<<'Compound Interet2 '<<CI(
)
O*+P*+
Enter #alue -or P F +
1;;;
4
6
3imple interet 2 14;
Compound Interet 2 1;;6
14. Program to -ind area o- a triangle.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int /0 !0 area(
cout<<'Enter #alue o- Qae and >eig!t o- triangle'<<'Mn'(
cin""/""!(
area2/8!A,(
cout<<'?rea o- triangle1 '<<area(
)
O*+P*+
Enter #alue o- Qae and >eig!t o- triangle
4
9
?rea o- triangle1 1;
15. Program t!at eed t!e name o- uer and num/er
o- unit and diplaD t!e electricitD c!arge .it! name.
+!e electricitD /oard c!arge according to -ollo.ing data1
Eor -irt 1;; unit 2 9;pAunit
Eor neHt ,;; unit 2 4;pAunit
QeDond 6;; unit 2 5;pAunit
?ll t!e uer are c!arged motor c!arge alo .!ic! i F 4;.
#include<iotream.!"
#include<tdio.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
c!ar nameR,4S(
int unit0 c!arge(
cout<<'Enter Dour name1 '(
get$name%(
cout<<'Enter total unit1 '<<Mn(
cin""unit(
i-$unit<21;;%
c!arge21;;89;A1;;+4;(
i-$unit"1;;@@unit<26;;%
c!arge21;;89;A1;;+$unitK1;;%84;A1;;+4;(
i-$unit"6;;%
c!arge21;;89;A1;;+,;;84;A1;;+$unitK6;;%85;A1;;+4;(
put$name%(
cout<<'+otal ElectricitD C!arge1 '<<c!arge(
)
O*+P*+
Enter Dour name1 ?lo: Tumar
Enter total unit1 ,C4
?lo: Tumar
+otal ElectricitD C!arge1 1C,
1G. Program to enter mar: in -i#e u/<ect and
calculate percentage. UiplaD grade according to
-ollo.ing peci-ication.
Percentage =rade
"B; ?
<2 B; and"C1 Q
<2 C; and"G1 C
<2 G; and"51 U
<2 5; and"41 E
<2 4; and"91 E
<29; Eail
#include<iotream.!"
#include<tdio.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
c!ar nameR5GS0 grade(
int eng0 mat!0 c0 p!D0 c!em0 um0 percentage(
cout<<'Enter Dour name1 '(
get$name%(
cout<<'Enter mar: in 4 u/<ect'<<'Mn'(
cin""eng""mat!""c""p!D""c!em(
um2eng+mat!+c+p!D+c!em(
percentage2umA4(
cout<<'Mn'<<'Mn'(
put$name%(
cout<<'Percentage1 '<< percentage <<VNV(
i-$percentage "B;%
grade2V?V(
i-$percentage <2B;@@ percentage "C1%
grade2VQV(
i-$percentage <2C;@@ percentage "G1%
grade2VCV(
i-$percentage <2G;@@ percentage "51%
grade2VUV(
i-$percentage <25;@@ percentage "41%
grade2VEV(
i-$percentage <24;@@ percentage "91%
grade2VEV(
i-$percentage <29;%
grade2V=V(
cout<<'Mn'<<'=rade1 '<<grade(
)
O*+P*+
Enter Dour name1 ?lo: Tumar
Enter mar: in 4 u/<ect
B6
BG
B4
B;
BB
?lo: Tumar
Percentage1 B9N
=rade1 ?
1C. Program t!at accept a c!aracter /et.een ? and W and
print neHt 9 c!aracter.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
c!ar c!(
cout<<'Enter c!aracter /et.een ? to W1 '(
cin""c!(
int num 2c!(
cout<<c!ar$num+1%(
cout<<' '<<c!ar$num+,%(
cout<<' '<<c!ar$num+6%(
cout<<' '<<c!ar$num+9%(
)
O*+P*+
Enter c!aracter /et.een ? to W1 E
= > I W
1B. Program to input a tudent tDpe $X?Y or XQY%0 and -or
X?Y initialiLe t!e collage account .it! F ,;; ot!er.ie
initialiLe t!e !otel account .it! F ,;;.
#include<iotream.!"
#oid main$%
&
c!ar tuZtDpe(
int collZacc0!otelZacc(
cout<<'Enter tudent tDpe1 '(
cin""tuZtDpe(
i-$tuZtDpe22V?V%
collZacc2,;;(
cout<<MnCollage account1<<collZacc(
i-$tuZtDpe22VQV%
!otelZacc2,;;(
cout<<Mn>otel account1<<!otelZacc(
)
O*+P*+
Enter tudent tDpe1 ?
Collage account1 ,;;
,;. Program t!at print area -or c!oice 1 and perimeter -or
c!oice , o- a circle
#include<iotream.!"
#oid main$%
&
c!ar c!oice(
int radiu0 area0 peri(
cout<<'Enter radiu o- circle1 '(
cin""radiu(
cout<<'Enter 1 -or area or , -or perimeter1 '(
cin""c!oice(
area2,,8radiu8radiuAG(
peri2,8,,8radiuAG(
i-$c!oice22V1V%
cout<<'?rea1 '<<area(
ele
cout<<'Perimeter1 '<<peri(
)
O*+P*+
Enter radiu o- circle1 G
Enter 1 -or area or , -or perimeter1 1
?rea1 149
,1. Program to -ind #alue o- P i- P2 $. + H%A$DKL%. +!e
#alue o- .0 H0 D0 L are entered /D uer.
#include<iotream.!"
#oid main$%
&
-loat .0 H0 D0 L0 P(
cout<<'Enter num/er .0 H0 D0 L'(
cin"".""H""D""L(
P2 $. + H%A$DKL%(
cout<<'MnP 2 $. + H%A$DKL% 2 '<<P(
)
O*+P*+
Enter num/er .0 H0 D0 L
4
G
5
6
P 2 $. + H%A$DKL% 2 9
,,. Program .!ic! raie anD num/er H to a poiti#e
po.er n.
#include<iotream.!"
#include<conio.!"
#include<mat!.!"
#oid main$%
&
clrcr$%(
long dou/le H0n0p(
cout<<'Enter anD num/er H1 '(
cin""H(
cout<<'Enter #alue o- n1 '(
cin""n(
p2po.$H0n%(
cout<<'H raied to t!e po.er n i1 '<<p(
)
O*+P*+
Enter anD num/er H1 4
Enter #alue o- n1 9
H raied to t!e po.er n i1 5,4
,6. Program to calculate commiion -or t!e alemen t!e
commiion i calculated according to -ollo.ing rate.
3ale Commiion rate
6;;;1 on.ard 14N
,,;;; [ 6;;;; 1;N
1,;;1 [ ,,;;; GN
4;;1 [ 1,;;; 6N
; [ 4;;; ;N
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
-loat ale(
cout<<'Enter ale made /D aleman1 '(
cin""ale(
i-$ale"4;;;%
i-$ale<1,;;;%
i-$ale<,,;;;%
i-$ale<6;;;;%
cout<<'Commiion 2 '<<ale8;.14(
ele
cout<<'Commiion 2 '<<ale8;.1;(
ele
cout<<'Commiion 2 '<<ale8;.;G(
ele
cout<<'Commiion 2 '<<ale8;.;6(
ele
cout<<'Commiion 2 '<<ale8;(
)
O*+P*+
Enter ale made /D aleman1 6549C
Commiion 2 49C,.,
,9. Program to print .!et!er t!e entered c!aracter i an
uppercae or a lo.ercae c!aracter or a digit or anD ot!er
c!aracter. +!e ?3CII code are gi#en /elo..
C!aracter ?3CII Fange
X;Y [ XBY 9C [ 4G
X?Y [ XJY 54 [ B;
XaY [ XLY BG K 1,,
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
c!ar c!(
int num(
cout<<'Enter anD C!aracter1 '(
cin""c!(
num2c!(
i-$num"29C%
i-$num"254%
i-$num"2BG@@num<1,6%
cout<<'Mn+!e entered c!aracter i a lo.er cae alp!a/et'(
ele
cout<<'Mn+!e entered c!aracter i a upper cae alp!a/et'(
ele
cout<<'Mn+!e entered c!aracter i a digit'(
ele
cout<<'Mn+!e entered c!aracter i anD ot!er c!aracter'(
)
O*+P*+
Enter anD C!aracter1 <
+!e entered c!aracter i a lo.er cae alp!a/et
,4. Program to print ta/le o- anD num/er.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int n0i(
cout<<'MnEnter anD num/er 1'(
cin""n(
-or$i21(i<21;(i++%
&
cout<<'Mt'(
cout<<n8i(
)
)
O*+P*+
Enter anD num/er1 ,
, 9 5 C 1; 1, 19 15 1C ,;
,5. Program to print root o- a 7uadratic e7uation.
#include<iotream.!"
#include<conio.!"
#include<mat!.!"
#oid main$%
&
clrcr$%(
-loat a0/0c0root10root,0delta(
cout<<'Enter t!e #alue o- a0 / @ c o- t!e 7uadratic e7uation o- t!e -orm
MnaH
,
+/H+c Mn'(
cin""a""/""c(
i-$a22;%
cout<<'+!e #alue o- VaV !ould not /e Lero Mn ?/ording\\\\\ Mn'(
ele
&
delta 2/8/K98a8c(
i-$delta";%
&
root12$K/+7rt$delta%%A$,8a%(
root,2$K/K7rt$delta%%A$,8a%(
cout<<'Foot are real and une7ual'(
cout<<'Mn root12 '<<root1(
cout<<'Mn root,2 '<<root,(
)
ele i-$delta22;%
&
root12root,2K/A$,8a%(
cout<<'Foot are real and e7ual'(
cout<<'Mn Foot12 '<<root1(
cout<<'Mn Foot,2 '<<root,(
)
ele
cout<<'root are compleH Mn'(
)
)
O*+P*+
Enter t!e #alue o- a0 / @ c o- t!e 7uadratic e7uation o- t!e -orm
aH
,
+/H+c
1
K4
9
Foot are real and une7ual
Foot12 1
Foot,2 9
,G. Program to -ind a num/er i prime or not.
#include<iotream.!"
#include<conio.!"
#include<proce.!"
#oid main$%
&
clrcr$%(
int n0i(
cout<<'Enter anD num/er1 '(
cin""n(
-or$i2,(i<2nK1(i++%
i-$nNi22;%
&
cout<<'MnEntered num/er i NO+ a PFIME N*MQEF '(
eHit$;%(
)
cout<<'MnEntered num/er i a PFIME N*MQEF '(
)
O*+P*+
Enter anD num/er1 1G
Entered num/er i a PFIME N*MQEF
,C. Program t!at print t!e -ollo.ing erie
1 , 9 C 15 6, 59 1,C
#include<iotream.!"
#include<mat!.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int <0i(
-or$i2;(i<2G(++i%
&
<2po.$,0i%(
cout<<<<<V V(
)
)
O*+P*+
1 , 9 C 15 6, 59 1,C
,B. Program t!at print -irt n natural num/er and print
t!eir um.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int i0 n0 um2;(
cout<<'Enter #alue o- n1 '(
cin""n(
-or$i21(i<2n(i++%
&cout<<i<<V V(
um+2i(
)
cout<<'Mnum 2 '<<um(
)
O*+P*+
Enter #alue o- n1 ,;
1 , 6 9 4 5 G C B 1; 11 1, 16 19 14 15 1G 1C 1B ,;
3um 2 ,1;
6;. Program to print um o- e#en and odd natural
num/er in -irt n natural num/er.
#include<iotream.!"
#oid main$%
&
int n0i0um12;0um,2;(
cout<<'Enter t!e num/er o- num/er 1 '(
cin""n(
-or$i21(i<2n(i++%
&i-$iN,22;%
um1+2i(
ele
um,+2i(
)
cout<<'Mn3um o- e#en num/er1 '<<um1(
cout<<'Mn3um o- odd num/er1 '<<um,(
)
O*+P*+
Enter t!e num/er o- num/er1 1;
3um o- e#en num/er1 6;
3um o- odd num/er1 ,4
61. Program -or generating t!e gi#en output.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int i0<(
-or$i21(i<24(i++%
&
cout<<'Mn'(
-or$<21(<<2i(<++%
cout<<V8V(
)
)
O*+P*+
8
88
888
8888
88888
6,. Program -or generating t!e gi#en output.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int i0<(
-or$i21(i<29(i++%
&
cout<<'Mn'(
-or$<21(<<2,8iK1(<++%
cout<<V8V(
)
)
O*+P*+
8
888
88888
8888888
66. Program -or generating t!e gi#en output.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int i(
-or$i21(i<24(++i%
&
cout<<'Mn'(
-or$int <21(<<2i(++<%
cout<<i(
)
)
O*+P*+
1
,,
666
9999
44444
69. Program -or generating t!e gi#en output.
#include<iotream.!"
#oid main$%
&
int i0 <0 :0 n(
cout<<'Enter num/er o- line1 '(
cin""n(
-or$i21(i<2n(i++%
&
cout<<'Mn'(
-or$<21(<<2nKi(<++%
cout<<V V(
-or$:21(:<2i(:++%
cout<<V8V(
)
)
O*+P*+
Enter num/er o- line1 6
8
88
888
64. Program to print -actorial o- a num/er.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
clrcr$%(
int i0 n0 -acto21(
cout<<'Enter anD num/er1 '(
cin""n(
-or$i21(i<2n(i++%
-acto82i(
cout<<'Mn'<<n<<' -actorial 2 '<<-acto(
)
O*+P*+
Enter anD num/er1 4
4 -actorial 2 1,;
65. Program -or generating t!e gi#en output.
#include<iotream.!"
#oid main$%
&
c!ar c!(
int i2c!0 <0 n(
cout<<'Enter num/er o- line1 '(
cin""n(
-or$i254(i<2n+54(i++%
&
cout<<'Mn'(
-or$<254(<<2i(<++%
cout<<c!ar$<%(
)
)
O*+P*+
Enter num/er o- line1 9
?
?Q
?QC
?QCU
6G. Program -or generating t!e gi#en output.
#include<iotream.!"
#oid main$%
&
int i0 <0 :0 n(
cout<<'Enter num/er o- line1 '(
cin""n(
-or$i21(i<2n(i++%
&
cout<<'Mn'(
-or$<21(<<2iK1(<++%
cout<<X X(
-or$:2n(:"2i(:KK%
cout<<'@ '(
)
)
O*+P*+
Enter num/er o- line1 9
@ @ @ @
@ @ @
@ @
@
6C. Program to c!ec: .!et!er a num/er i palindrome or
not.
#include<iotream.!"
#include<tring.!"
#oid main$%
&
int n0 n10 n,2n0 re#2;(
cout<<'Enter anD num/er1 '(
cin""n(
.!ile$n%
&n12nN1;(
re#2re#81;+n1(
n2nA1;(
)
i-$n,22re#%
cout<<'MnNum/er i palindrome'(
ele
cout<<'MnNum/er i not palindrome'(
)
O*+P*+
Enter anD num/er1 1,1
Num/er i palindrome
6B. Program to c!ec: .!et!er entered c!aracter i an
alp!a/et or not.
#include<iotream.!"
#include<ctDpe.!"
#oid main$%
&
c!ar c!(
cout<<'Enter c!aracter 1'(
cin""c!(
i-$ialp!a$c!%%
cout<<'It i an alp!a/et.'(
ele
cout<<'It i not an alp!a/et.'(
)
O*+P*+
Enter c!aracter1 a
It i an alp!a/et.
Enter c!aracter1 N
It i not an alp!a/et.
9;. Program to c!ec: .!et!er t!e entered c!aracter i
o- uppercae or lo.ercae.
#include<iotream.!"
#include<ctDpe.!"
#oid main$%
& c!ar c!(
cout<<'Enter c!aracter1'(
cin""c!(
i-$ialp!a$c!%%
& cout<<'It i an alp!a/et.Mn'(
i-$iupper$c!%%
cout<<'It i an upper cae.'(
ele
cout<<'It i a lo.er cae.'(
)
ele
cout<<'It i not an alp!a/et.'(
)
O*+P*+
Enter c!aracter1 r
It i an alp!a/et.
It i a lo.er cae.
91. Program to concatenate t.o tring.
#include<iotream.!"
#include<tdio.!"
#include<tring.!"
#oid main$%
&
c!ar 1R1;S0 ,R1;S(
cout<<'Enter tring 11'(
get$1%(
cout<<'Enter tring ,1'(
get$,%(
cout<<trcat$10,%(

)
O*+P*+
Enter tring 11 =OOU
Enter tring ,1 L*CT
=OOUL*CT
Enter tring 11 WEL
Enter tring ,1 COME
WELCOME
9,. Program to -ind out num/er o- .ord preent in a
line.
#include<iotream.!"
#include<tring.!"
#oid main$%
&
int n21(
c!ar trR1;;S(
cout<<'Enter line1'(
cin.getline$tr01;;%(
-or$int i21( trRiS\2VM;V( i++%
&
i- $ trRiK1S\2V V @@ trRiS22V V%
n2n+1(
)
cout<< MnNum/er o- .ord 2 <<n(
)
O*+P*+
Enter line1 MD name i ?lo: Tumar.
Num/er o- .ord 2 4
Enter line1 Program to -ind out num/er o- .ord preent in a line.
Num/er o- .ord 2 11
96. Program to print a .ord /D deleting 1 letter -rom
end in eac! turn.
#include<iotream.!"
#include<tring.!"
#oid main$%
& c!ar trR,4S(
cout<<'Enter tring1'(
cin.getline$tr0,4%(
int len2trlen$tr%(
-or$int i2len( i<2;( iKK%
& -or$int <2;( <<2i( <++%
cout<<trR<S(
cout<<Mn(
)
)
O*+P*+
Enter tring1 >ELLO
>ELLO
>ELL
>EL
>E
>
99. Program to c!ec: .!et!er t!e gi#en tring i
palindrome or not.
#include<iotream.!"
#include<tring.!"
#oid main$%
& c!ar trR,;S(
int len0 i0 -21(
cout<<'Enter tring1'(
cin.getline$tr0,;%(
len2trlen$tr%(
-or$i2;0 len2lenK1( i<2lenA,( i++0 lenKK%
& i-$trRiS\2trRlenS%
-2;(
/rea:(
)
i-$-221%
cout<<'Entered tring i palindrome.'(
ele
cout<<'Entered tring i not a palindrome.'(
)
O*+P*+
Enter tring1 F?U?F
Entered tring i palindrome.
94. Program to -ind .!et!er a gi#en c!aracter i preent
in a tring or not and alo -ind t!e poition o- c!aracter.
#include<iotream.!"
#include<conio.!"
#include<tring.!"
#oid main$%
& clrcr$%(
c!ar trR,;S0 c!(
int i0 -2;(
cout<<'Enter tring1'(
cin.getline$tr0,;%(
cout<<'Enter c!aracter1'(
cin""c!(
-or$i21( i<2len( i++%
&
i-$trRiS22c!%
&
-21(
/rea:(
)
)
i-$-221%
cout<<+!e gi#en c!aracter i preent in t!e
tring.<<Mn +!e poition o- t!e c!aracter
i1<< i(
ele
cout<<+!e gi#en c!aracter i not preent in t!e
tring.(
)
O*+P*+
Enter tring1 MD name i T!an and I am not a terrorit.
Enter c!aracter1 T
+!e gi#en c!aracter i preent in t!e tring
+!e poition o- t!e c!aracter i1 1,
Enter c!aracter1 t
+!e gi#en c!aracter i preent in t!e tring
+!e poition o- t!e c!aracter i1 6,
95. Program to -ind cu/e o- a num/er $uing
-unction%.
#include<iotream.!"
int cu/e$int%(
#oid main$%
&
int a0c(
cout<<'Enter num/er1 '(
cin""a(
c2cu/e$a%(
cout<<'Cu/e o- t!e num/er1 '<<c(
)
int cu/e$int /%
&
int n(
n2/8/8/(
return n(
)
O*+P*+
Enter num/er1 4
Cu/e o- t!e num/er1 1,4
9G. Program to print larget e#en and odd num/er -rom a
lit o- num/er entered t!roug! :eD/oard. +!e lit
terminate a oon a one enter Lero $uing -unction%.
#include<iotream.!"
#include<conio.!"
#oid e#enZodd$int%(
#oid main$%
&
clrcr$%(
int n(
e#enZodd$n%(
)
#oid e#enZodd$int n%
&
int maHe#en2;0 maHodd2;(
.!ile$n%
&
cout<<'Enter num/er1'(
cin""n(
i-$nN,22;%
&
i-$n"maHe#en%
maHe#en2n(
)
ele i-$nN,221%
&
i-$n"maHodd%
maHodd2n(
)
ele i-$n22;%
/rea:(
)
cout<<'Larget odd num/er1'<<maHodd<<'Mn Larget e#en
num/er1'<<maHe#en(
)
O*+P*+
Enter num/er14
5
C
B
G
14
1C
Larget odd num/er1 14
Larget e#en num/er1 1C
9C. Program to calculate -actorial o- a num/er $uing
-unction%.
#include<iotream.!"
#oid -actorial$int%(
#oid main$%
& int n(
cout<<'Enter num/er1'(
cin""n(
-actorial$n%(
)
#oid -actorial$int n%
& int -act21(
int i(
-or$i21( i<2n( i++%
-act2-act8i(
cout<< MnEactorial o- <<n<< i <<-act(
)
O*+P*+
Enter num/er1 5
Eactorial o- 5 i G,;
Enter num/er1 4
Eactorial o- 5 i 1,;
9B. Program to -ind larget num/er o- a lit o- no.
entered t!roug! :eD/oard $uing -unction%.
#include<iotream.!"
#oid larget$%(
#oid main$%
& larget$%(
)
#oid larget$%
& c!ar an2VDV( int n0 large2;(
.!ile$an22VDV%
& cout<<'Enter num/er1'(
cin""n(
i-$n"large%
large2n(
cout<<'Iou .ant to enter num/er]$D or n%1'(
cin""an(
)
cout<< Mn Larget num/er entered1 <<large(
)
O*+P*+
Enter num/er1 4 5 C 94 5C ,5 54 64 GB 54 K5 59 ,4 59 6 B 1;
Larget num/er entered1 GB
4;. Program t!at input t!ree num/er and -ind t!e
greatet among t!em $uing -unction%.
#include<iotream.!"
#oid greatet$int0 int0 int%(
#oid main$%
& int maH0 d0 e0 -(
cout<<'Enter 6 num/er1'(
cin""d""e""-(
greatet$d0 e0 -%(
)
#oid greatet$int d0 int e0 int -%
& i-$d"e @@ d"-%
cout<<'Eirt num/er i greatet'(
ele i-$e"d @@ e"-%
cout<<'3econd num/er i greatet'(
ele i-$-"d @@ -"e%
cout<<'+!ird num/er i greatet'(
)
O*+P*+
Enter 6 num/er1 4
B
,
3econd num/er i greatet
41. Program to -ind larget and mallet element in a
#ector.
#include<iotream.!"
#oid main$%
& int #R1;S0 large0 mall0 i(
cout<<'Enter t!e #alue in #ector '(
-or$i2;(i<1;( i++%
cin""#RiS(
large2#R1S(
mall2#R1S (
-or $i2;(i<1;(i++%
& i-$#RiS"large%
large2#RiS(
ele i-$#RiS<mall%
mall2#RiS(
)
cout<<'Mn Larget element 2'<<large(
cout<<'Mn 3mallet element2 '<<mall(
)
O*+P*+
Enter t!e #alue in #ector
4 5 C 9 6 9 B 4 1 ,
Larget element 2 B
3mallet element2 1
4,. Program -or .apping o- t.o num/er $uing
-unction%.
#include<iotream.!"
#oid .ap$int0int%(
#oid main$%
& int a0/(
cout<<'Enter num11 MnEnter num,1'(
cin""a""/(
.ap $a0/%(
)
#oid .ap$int c0 int d%
& int temp(
temp 2c(
c2d(
d2temp(
cout<< MnOalue a-ter .apping num/er.
cout<< MnNum1<<c<<'MnNum,'<<d(
)
O*+P*+
Enter num11 B
Enter num,1 14
Oalue a-ter .apping num/er.
Num11 14
Num,1 B
46. Program to -ind um o- digit o- a num/er $uing
-unction%.
#include<iotream.!"
int um$int%(
#oid main$%
& int n0(
cout<<'Enter num/er1'(
cin""n(
2um$n%(
cout<< Mn 3um o- digit 1<<(
)
int um$int n1%
& int p2;(
.!ile$n1%
& p2p+$n1N1;%(
n12n1A1;(
)
return p(
)
O*+P*+
Enter num/er1645
3um o- digit 1 19
49. Program to print all t!oe element o- a matriH t!at are
on and are on t!e rig!t ide o- main diagonal.
#include<iotream.!"
#oid main$%
&int arrR6SR6S(
cout<<'Enter matriH1'(
-or$int i2;(i<6(i++%
-or$int <2;(<<6(<++%
cin""arrRiSR<S(
-or$i2;(i<6(i++%
& cout<<'Mn'(
-or$int <2;(<<6(<++%
& i-$i<2<%
cout<<arrRiSR<S(
ele
cout<<' '(
))
)
O*+P*+
Enter matriH1 , 5 B
C 1 4
9 , 6
, 5 B
1 4
6
44. Program to print and con#ert all t!e element o-
an arraD poiti#e $uing -unction%.
#include<iotream.!"
#oid negati#e$int arrRS0int%(
#oid main$%
& int iLe21;0 arrRiLeS(
cout<<'Enter element o- an arraD1'(
-or$int i2;( i<iLe( i++%
cin""arrRiS(
negati#e$arr0iLe%(
)
#oid negati#e$int arr1RS0 int iLe1%
& -or$int i2;( i<iLe1( i++%
& i-$arr1RiS<;%
arr1RiS2arr1RiS8K1(
)
-or$i2;(i<iLe1( i++%
cout<<arr1RiS<<Mt(
)
O*+P*+
Enter element o- an arraD1
1 , K5 KC 4 KB 4 9 C KB
1 , 5 C 4 B 4 9 C B
45. Program to generate t!e gi#en output.
#include<iotream.!"
#oid main$%
& int arr1R4SR4S(
int arrRS2&10,060904)(
-or$int i2;(i<4(i++%
-or$int <2;(<<4(<++%
arr1RiSR<S2arrR<S(
-or$i2;( i<4( i++%
-or$int <2;( <<4( <++%
& i-$i+<"9%
arr1RiSR<S2;( )
-or$i2;(i<4(i++%
& cout<<'Mn'(
-or$int <2;(<<4(<++%
cout<<arr1RiSR<S<<' '(
)
)
O*+P*+
1 , 6 9 4
1 , 6 9 ;
1 , 6 ; ;
1 , ; ; ;
1 ; ; ; ;
4G. Program to diplaD a ,U arraD in 1U arraD.
#include<iotream.!"
#oid main$%
& int ?R6SR6S0 QRBS(
int i0<0:2;(
cout<<'Enter ?rraD ?1'(
-or$i2;( i<6( i++%
-or$<2;( <<6( <++%
cin""?RiSR<S(
-or$i2;( i<6( i++%
& cout<<'Mn'(
-or$<2;( <<9( <++%
cout<<?RiSR<S<<' '()
-or$i2;( i<6( i++%
-or$<2;( <<6( <++%
& QR:S2?RiSR<S(
:++()
-or$:2;( :<B( :++%
cout<<QR:S(
)
O*+P*+
Enter ?rraD ?1 1 , 6
1 , 6
1 , 6
?rraD Q1 1 , 6 1 , 6 1 , 6
4C. Program to concatenate t.o arraD.
#include<iotream.!"
#oid main$%
& int i0 <0 :(
int ?R4S0 QR4S0 CR1;S(
cout<<'Enter arraD ?1'(
-or$i2;( i<4( i++%
cin""?RiS(
cout<<'Enter arraD Q1'(
-or$<2;(<<4(<++%
cin""QR<S(
-or$i2;0:2;( i<4(:++0 i++%
CR:S2?RiS(
-or$:240 i2;( i<4( :++0 i++%
CR:S2QRiS(
cout<<'Mn?rraD C1'(
-or$:2;(:<1;(:++%
cout<<CRiS<<' '(
)
O*+P*+
Enter arraD ?1 ; 1 , 6 9
Enter arraD Q1 4 5 G C B
?rraD C1 ; 1 , 6 9 4 5 G C B
4B. Program to replace a num/er -rom arraD .it! ;
and ta:e all ; o- t!e arraD to t!e le-t.
#include<iotream.!"
#oid main$%
&
int arrRBS0 n0 t0 :(
cout<<'Enter arraD1'(
-or$int i2;( i<B( i++%
cin""arrRiS(
cout<<'Enter num/er1'(
cin""n(
-or$i2;( i<B( i++%
&
i-$arrRiS22n%
arrRiS2;(
)
-or$i2;( i<B( i++%
cout<<arrRiS<<'Mn'(
cout<<'Mn'(
-or$:2;(:<,( :++%
&
-or$i2C( i"2;( iKK%
&
i-$arrRiS22;%
&
-or$int <2i(<";(<KK%
&
t2arrR<S(
arrR<S2arrR<K1S(
arrR<K1S2t(
)
)
)
)
cout<< ?rraD a-ter replacing <<n<<1 (
-or$i2;( i<B( i++%
cout<<arrRiS(
)
O*+P*+
Enter arraD1 5 4 9 5 B 4 1 4 C
Enter num/er1 5
?rraD a-ter replacing X4Y1
; ; ; 5 9 5 B 1 C
5;. Program to calculate t!e um o- element o- t!e
ro. o- matriH.
#include<iotream.!"
#oid main$%
& int ?R6SR6S0 um(
cout<<'Enter matriH ?1'(
-or$int i2;( i<6( i++%
& -or$int <2;( <<6( <++%
cin""?RiSR<S(
)
-or$i2;( i<6( i++%
& um2;(
-or$int <2;( <<6( <++%
um2um+?RiSR<S(
cout<< Mn3um o- ro.<<i+1<< i <<um<<'Mn'(
)
)
O*+P*+
Enter matriH ?1 1 , 6
9 4 5
G C B
3um o- ro. 1 i 5
3um o- ro. , i 14
3um o- ro. 6 i ,9
51. Program to multiplD t.o matrice.
#include<iotream.!"
#include<conio.!"
#oid main$%
&
int ?R6SR6S0 QR6SR6S0 CR6SR6S(
cout<<'Enter matriH ?1'(
-or$int i2;( i<6( i++%
&
-or$int <2;( <<6( <++%
cin""?RiSR<S(
)
cout<<'Enter matriH Q1'(
-or$i2;( i<6( i++%
&
-or$int <2;( <<6( <++%
cin""QRiSR<S(
)
cout<< MnMatriH ? ^ matriH Q 1
-or$i2;( i<6( i++%
&
cout<<'Mn'(
-or$int <2;( <<6( <++%
&
int um2;(
-or$int :2;( :<6( :++%
&
um+2?RiSR<S8QR:SR<S(
)
cout<<um<<' '(
)
)

)
O*+P*+
Enter matriH ?1 1 , 1
, 1 ,
1 , 1
Enter matriH Q1 , 1 ,
1 , 1
, 1 ,
MatriH ? ^ matriH Q1
4 C 4
1; 9 1;
4 C 4
5,. Program to delete duplicate element o- an arraD
.it! ; and ta:e all ; to rig!t.
#include<iotream.!"
#oid main$%
& int ?R1;S(
cout<<'Enter arraD1'(
-or$int i2;( i<1;( i++%
cin""?RiS(
-or$i2;( ?RiS\2VM;V( i++%
& -or$int <2i+1( ?R<S\2VM;V( <++%
& i-$?RiS22?R<S%
& -or$int :2<( ?R:S\2VM;V( :++%
?R:S2?R:+1S( )
))
-or$i2;( ?RiS\2VM;V( i++%
& i-$?RiS22;%
?RiS2VM;V( )
cout<< MnNe. arraD1(
-or$i2;( i<1;( i++%
cout<<?RiS<<' '(
)
O*+P*+
Enter arraD1 4 C B 5 9 C B 6 5 4
Ne. arraD1 4 C B 5 9 6 ; ; ; ;
56. Program to calculate compound interet -or 4; client
o- an in#etment companD.
Uetail $including cotume name0 code and date o- tarting0
num/er o- Dear0 interet rate and total amount% are tored
in an arraD o- tructure.
#include<iotream.!"
#include<tdio.!"
#include<mat!.!"
#include<conio.!"
truct client
&
c!ar cnameR,;S(
int ccode(
int cdaD(
int cmont!(
int cDear(
int irate(
int totalamount(
int totZDear(
)(
client cR4;S(
#oid main$%
&
clrcr$%(
-loat ciR4;S(
-or$int i2;( i<4;( i++%
&
get$cRiS.cname%(
cin""cRiS.ccode(
cin""cRiS.cdaD(
cin""cRiS.cmont!(
cin""cRiS.cDear(
cin""cRiS.totZDear(
cin""cRiS.irate(
cin""cRiS.totalamount(
)
-or $i2;( i<4;( i++%
&
-loat t0(
tRiS2$1+cRiS.irate8;0;1%(
RiS2po.$tRiS0c1RiS.Dear(
ciRiS2c1RiS.totalamount8RiS(
cout<<ciRiS(
)

)
59. Program to tore in-ormation o- 1; emploDee and
to diplaD in-ormation o- an emploDee depending
upon t!e emploDee num/er gi#en.
#include<iotream.!"
#include<conio.!"
#include<tdio.!"
#include<proce.!"
truct emploDee
&
int eno(
c!ar enameR,;S(
c!ar eaddreR,;S(
)eR1;S(
#oid main$%
&
clrcr$%(
int i0n(
c!ar an2VDV(
-or$i2;(i<1;(i++%
&
cin""eRiS.eno(
get$eRiS.ename%(
get$eRiS.eaddre%(
do&
cout<<'enter emploDee no'(
cin""n(
i-$n22eRiS.eno%
&
cout<<eRiS.eno(
put$eRiS.ename%(
put$eRiS.eaddre%(
)
cout<<'u .ant to proceed or not'(
cin""an(
)
.!ile$an22VDV%(
)
)
54. Program to create an arraD containing detail o-
,4 tudent $including Foll num/er0 name0 mar: in
t!ree u/<ect% and print out a lit o- tudent .!o
!a#e -ailed in more t!an 1 u/<ect. ?ume 9;N
mar: a pa mar:.
#include<iotream.!"
#include<conio.!"
#include<tdio.!"
truct tudent
& int rno(
c!ar nameR,;S(
int u/1(
int u/,(
int u/6(
)R,4S(
#oid main$%
&
-or$int i2;(i<,4(i++%
&
cout<<'Enter tudent Foll num/er 1 '(
cin""RiS.rno(
cout<<'Enter tudent name 1 '(
get$RiS.name%(
cout<<'Enter mar: o/tained in t!ree u/<ect 1 '(
cin""RiS.u/1""RiS.u/,""RiS.u/6(
)
cout<<'lit o- tudent -ailed in more t!an 1 u/<ect'(
int -2;(
-or$i2;(i<,4(i++%
&
i-$RiS.u/1<29;%
-++(
i-$RiS.u/,<29;%
-++(
i-$RiS.u/6<29;%
-++(
i-$-"1%
&
put$RiS.name%
cout<<RiS.rno(
)
-2;(
)
)

You might also like