Upload
hello
View
217
Download
0
Embed Size (px)
Citation preview
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 1/16
/*
Program No : 1
Developed by : Karan Aggarwal, Kshitiz Agrawal, Kushagra upta
Pra!ti!al "ist : 1
Date : #th April $%1&
*/
'in!lude(iostream)h
'in!lude(!onio)h
void +eries-
.
int !h
!out((0nter the !orre!t inde230((endl
!out((01)+eries 14546$5467)))-8n$)+eries $9596$/$35967/73)))-0((endl
!out((07)+eries 7$5$5;<5$5;5=<)))n terms-0((endl
!in!h
swit!h!h-
. !ase 1:
.
long int N
long >loat 4,temp?1,sum?%
!out((0nter the value o> 4:0
!in4
!out((0nter the number o> terms:0
!inN
>orint i?1i(?Ni55-
.temp*?4
sum5?temp
@
!out((0he sum o> series 1 with 4?0((4((0 and number o> terms?0((N((0
is:0((sum((endl
breaB
@
!ase $:
.
long >loat 9,temp?1,sum?%long int N
!out((0nter the value o> 9:0
!in9
!out((0nter the number o> terms:0
!inN
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 2/16
>orint i?1i(?Ni55-
.
temp*?9/i-
sum5?temp
@
!out((0he sum o> series $ with 9?0((9((0 and number o> terms?0((N((0
is:0((sum((08n0
breaB
@
!ase 7:
.
long >loat temp?%,sum?%
long int N
!out((0nter the number o> terms:0
!inN
>orint i?$i(?$*N-i5?$-
. temp5?i
sum5?temp
@
!out((0he sum o> series 7 with number o> terms?0((N((0 is:0((sum((endl
breaB
@
de>ault:!out((0Cnvalid Cnput30
@
@
void main-.
!lrs!r-
!out((08t8t8t8tel!ome to series30((endl
!har !h
>orint i?%!h3?ENE-
.
!out((0Do you want to !ontinueFG/N-0((endl
!in!h
i>!h??EGE-
+eries-@
get!h-
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 3/16
/*
Developed by : Karan Aggarwal, Kshitiz Agrawal, Kushagra upta
Date : $% April $%1&
Program no : $
Pra!ti!al "ist : 1
*/
'in!lude(iostream)h
'in!lude(!onio)h
void primeint N-
.
int B?%
>orint i?1i(?N/$i55-
i>NHi??%-
B55
i>B??1-
!out((N((0 is a prime number0((endl
else!out((N((0 is not a prime number0((endl
@
void palindromeint N-
.
int temp?N,rev?%,temp1
do
.
temp1?tempH1%
rev?rev*1%5temp1
temp?temp/1%@
whiletemp3?%-
i>rev??N-
!out((N((0 is a palindrome number)0((endl
else
!out((N((0 is not a palindrome number)0((endl
@
void evenint N-
.
int temp?N,sum?%,temp1do
.
temp1?tempH1%
sum5?temp1
temp?temp/1%
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 4/16
whiletemp3?%-
i>sumH$??%-
!out((0he sum o> digits o> 0((N((0 is even)0((endl
else
!out((0he sum o> digits o> 0((N((0 is odd)0((endl
@
void menu-
.
int !h
!out((0Ihoose the inde2 !orresponding to the desired option:0((endl
!out((01)o !he!B whether a number entered by the user is prime or
not)0((endl
!out((0$)o !he!B whether a number is a palindrome or not)0((endl
!out((07)o !he!B i> the sum o> the digits o> a number entered by8n the user is
even or not)0((endl
!in!h
swit!h!h-.
!ase 1:
.
int N
!out((0nter the desired number:0
!inN
primeN-
breaB
@
!ase $:.
int N
!out((0nter the desired number:0
!inN
palindromeN-
breaB
@
!ase 7:
.
int N!out((0nter the desired number:0
!inN
evenN-
breaB
@
de>ault:
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 5/16
.
!out((0Cnvalid input30((endl
@
@
@
void main-
.
!lrs!r-
!out((08t8t8t8tel!ome330((endl
!har !h
>or !h3?ENE-
.
!out((0Do you want to !ontinueFG/N-0((endl
!in!h
i>!h??EGE-
menu-
else!out((0oodbye0
@
get!h-
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 6/16
/*
Developed by : Karan Aggarwal, Kshitiz Agrawal, Kushagra upta
Date : $1 April $%1&
Program no : 7
Pra!ti!al "ist : 1
*/
'in!lude(iostream)h
'in!lude(!onio)h
void inputint A<,int N-
.
!out((0nter the elements >or the array30((endl
>orint i?%i(Ni55-
.
!out((0A0((i((0<?0
!inAi<
@
@ void displayint A<,int N-
.
!out((0he array A is as >ollows30((endl
>orint i?%i(Ni55-
!out((0A0((i((0<?0((Ai<((endl
@
void sear!hint A<,int N-
.
int sear!h!out((0nter the element you want to sear!h the array >or:0
!insear!h
int >ound?J1
>orint i?%i(Ni55-
i>Ai<??sear!h-
>ound?i
i>>ound3?J1-
!out((sear!h((0 was >ound at subs!ript 0((>ound((0 in the array30((endl
else
!out((sear!h((0 is not there in the array30((endl@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 7/16
void sortint A<,int N-
.
>orint i?1i(Ni55-
.
int emp?Ai<,?iJ1
whileemp(A<LL?%-
A51<?AJJ<
A51<?emp
@
!out((0he sorted array is as >ollows30((endl
displayA,N-
@
void main-
.
!lrs!r-
int A1%%<,N!out((0nter the size o> the array:0
!inN
inputA,N-
displayA,N-
sear!hA,N-
sortA,N-
get!h-
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 8/16
/*
Developed by : Karan Aggarwal, Kshitiz Agrawal, Kushagra upta
Date : $1 April $%1&
Program no : ;
Pra!ti!al "ist : 1
*/
'in!lude(iostream)h
'in!lude(!onio)h
void inputint A<,int N-
.
!out((0nter the elements >or the array30((endl
>orint i?%i(Ni55-
.
!out((0A0((i((0<?0
!inAi<
@
@ void displayint A<,int N-
.
!out((0he array A is as >ollows30((endl
>orint i?%i(Ni55-
!out((0A0((i((0<?0((Ai<((endl
@
void sear!hint A<,int N-
.
int sear!h!out((0nter the element to be sear!hed >or:0
!insear!h
int "M?%,9M?NJ1,CD,>ound?%
while"M(?9MLL 3>ound-
.
CD?"M59M-/$
i>ACD<sear!h-
9M?CDJ1
else
i>ACD<(sear!h-"M?CD51
else
>ound55
@
!out((sear!h((0 was >ound at subs!ript 0((CD((0 in the array30((endl
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 9/16
void sortint A<,int N-
.
>orint i?%i(NJ1i55-
.
int small?i
>orint ?i51(N55-
i>A<(Asmall<-
small?
i>small3?i-
.
int temp?Asmall<
Asmall<?Ai<
Ai<?temp
@
@
!out((0he sorted array is as >ollows:0((endl
@ void main-
.
!lrs!r-
int A1%%<,N
!out((0nter the size o> the array:0
!inN
inputA,N-
displayA,N-
sortA,N-
displayA,N-sear!hA,N-
get!h-
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 10/16
/*
Developed by : Karan Aggarwal, Kshitiz Agrawal, Kushagra upta
Date : $1 April $%1&
Program no : &
Pra!ti!al "ist : 1
*/
'in!lude(iostream)h
'in!lude(!onio)h
void inputint A<1%<,int N,int -
.
>orint i?%i(Ni55-
>orint ?%(55-
.
!out((0A0((i((0<0((((0<?0
!inAi<<
@
@
void displayint A<1%<,int N,int -
.
>orint i?%i(Ni55-
.
>orint ?%(55-
!out((Ai<<((0 0
!out((endl
@
@ void addint A<1%<,int M<1%<,int I<1%<,int N,int , int O, int P-
.
i>N??OLL??P-
.
>orint i?%i(Ni55-
>orint ?%(55-
Ii<<?Ai<<5Mi<<
@
else
!out((0atri2 addition is not de>ined30((endl@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 11/16
void subtra!tint A<1%<,int M<1%<,int I<1%<,int N,int , int O, int P-
.
i>N??OLL??P-
.
>orint i?%i(Ni55-
>orint ?%(55-
Ii<<?Ai<<JMi<<
@
else
!out((0atri2 subtra!tion is not de>ined30((endl
@
void main-
.
!lrs!r-
int A1%<1%<,M1%<1%<,I1%<1%<,N,,O,P
!out((0nter the number o> rows and !olumns >or array A:0
!inN!out((0nter the number o> rows and !olumns >or array M:0
!inOP
!out((0nter values >or array A:0((endl
inputA,N,-
!out((0nter values >or array M:0((endl
inputM,O,P-
addA,M,I,N,,O,P-
i>N??OLL??P-
.
!out((0he array obtained a>ter addition is:0((endldisplayI,O,P-
@ subtra!tA,M,I,N,,O,P-
i>N??OLL??P-
.
!out((0he array obtained a>ter subtra!tion is:0((endl
displayI,O,P-
@
get!h-
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 12/16
/*
Developed by : Karan Aggarwal, Kshitiz Agrawal, Kushagra upta
Date : $1 April $%1&
Program no : =
Pra!ti!al "ist : 1
*/
'in!lude(iostream)h
'in!lude(!onio)h
'in!lude(stdio)h
'in!lude(string)h
int length!har A<-
.
int N?%
>orint i?%Ai<3?E8%Ei55-
N55
return N
@ void !ontents!har A<,int N-
.
int vowels?%,digits?%,!onsonants?%,spe!ial?%
>orint i?%i(Ni55-
i>Ai<??EAEAi<??EEAi<??ECEAi<??EQEAi<??E9EAi<??EaEAi<??EeE
Ai<??EiEAi<??EoEAi<??EuE-
vowels55
else
i>int-Ai<?;RLLint-Ai<(?&S-
digits55else
i>int-Ai<?=&LLint-Ai<(?#%-
!onsonants55
else
i>int-Ai<?#SLLint-Ai<(?1$$-
!onsonants55
else
spe!ial55
!onsonants5?vowels
!out((0he number o> vowels in 0((A((0 are :0((vowels((endl!out((0he number o> !onsonants in 0((A((0 are :0((!onsonants((endl
!out((0he number o> digits in 0((A((0 are :0((digits((endl
!out((0he number o> spe!ial !hara!ters in 0((A((0 are :0((spe!ial((endl
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 13/16
void reverse!har A<,int N-
.
!har I1%%<
>orint i?%i(Ni55-
Ii<?ANJ1Ji<
IN<?E8%E
!out((0he reverse o> the string is:0((I((endl
@
void main-
.
!lrs!r-
!har A1%%<
!out((0nter a string:0
getsA-
int N?lengthA-
!ontentsA,N-reverseA,N-
get!h-
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 14/16
/*
Developed by : Karan Aggarwal, Kshitiz Agrawal, Kushagra upta
Date : $1 April $%1&
Program no : S
Pra!ti!al "ist : 1
*/
'in!lude(iostream)h
'in!lude(!onio)h
'in!lude(string)h
'in!lude(stdio)h
void input!har A<1%%<,int N-
.
>orint i?%i(Ni55-
.
!out((0Iountry 0((i51((0:0
getsAi<-
@
@
void display!har A<1%%<,int N-
.
!out((0he !ountries entered by the user:0((endl
>orint i?%i(Ni55-
!out((i51((0)Iountry 0((i51((0:0((Ai<((endl
@
void sort!har A<1%%<,int N-
.>orint i?%i(NJ1i55-
.
int small?i
>orint ?i51(N55-
i>str!mpiA<,Asmall<-%-
small?
i>small3?i-
.
!har temp1%%<
str!pytemp,Asmall<-str!pyAsmall<,Ai<-
str!pyAi<,temp-
@
@
!out((0+orting in Des!ending Qrder is Iomplete30((endl
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 15/16
void sear!h!har A<1%%<,int N-
.
!har sear!h1%%<
int pos?J1
!out((0nter the !ountry to be sear!hed:0
!insear!h
>orint i?%i(Ni55-
i>str!mpiAi<,sear!h-??%-
pos?i
i>pos3?J1-
!out((0Iountry registered30((endl
else
!out((0Iountry not registered30((endl
@
void main-
.
!lrs!r-!har A1%%<1%%<
int N
do
.
!out((0nter the number o> !ountries you wish to enter:0
!inN
@
whileN(?%N1%%-
inputA,N-
displayA,N-sortA,N-
displayA,N-
sear!hA,N-
get!h-
@
7/23/2019 Computer Practical List 1
http://slidepdf.com/reader/full/computer-practical-list-1 16/16