Lab Manual for the Academic Year 2010-2011 I B.Tech
In!c"ar#e HOD $r%nc%&a $re&ared b'( A&&r)*ed & Re*%e+ed b'( Issued b'( +.e., Date( D.RAMBABU 08-oct-2010 1 No. Name of the Program Page No. !emar" 1 #ee" l. a$ Write a C program to find the sum of individual digits of a positive integer. b$ A Fibonacci sequence is defined as follows: the first and second terms in the sequence are 0 and 1. Subsequent terms are found b adding the preceding two terms in the sequence. Write a C program to generate the first n terms of the sequence. c$ Write a C program to generate all the prime numbers between 1 and n! where n is a value supplied b the user 1 " #ee" 2. a$ Write a C program to calculate the following Sum: Sum#1$% " &"' (% ) &)'$% * &*'(% + &+'$% 10 &10' b$ Write a C program to find the roots of a quadratic equation 11 , #ee" % a$ Write C programs that use both recursive and non$recursive functions i- .o find the factorial of a given integer. ii- .o find the /C0 1greatest common divisor- of two given integers. iii- .o solve .owers of 2anoi problem. 1+ ) #ee" & a$ .he total distance travelled b vehicle in 3t4 seconds is given b distance # ut(1&"at " where 3u4 and 3a4 are the initial velocit 1m&sec.- and acceleration 1m&sec " -. Write C program to find the distance travelled at regular intervals of time given the values of 3u4 and 3a4. .he program should provide the fle%ibilit to the user to select his own time intervals and repeat the calculations for different values of 3u4 and 3a4. b$ Write a C program! which ta5es two integer operands and one operator from the user! performs the operation and then prints the result. 1Consider the operators (!$!6! &! 7 and use Switch Statement- ,8 9 #ee" ' a$ Write a C program to find both the largest and smallest number in a list of integers. b$ Write a C program that uses functions to perform the following: i- Addition of .wo :atrices ii- :ultiplication of .wo :atrices )* " * #ee" ( a$ Write a C program that uses functions to perform the following operations: i- .o insert a sub$string in to a given main string from a given position. ii- .o delete n Characters from a given position in a given string. b$ Write a C program to determine if the given string is a palindrome or not. 9; ; #ee" ) a$ Write a C program that displas the position or inde% in the string S where the string . begins! or < 1 if S doesn4t contain .. b$ Write a C program to count the lines! words and characters in a given te%t. ;1 No. Name of the Program Page No. !emar" + #ee" * a$ Write a C program to generate =ascal4s triangle. b$ Write a C program to construct a pramid of numbers. ;8 8 #ee" + Write a C program to read in two numbers! % and n! and then compute the sum of this geometric progression: 1(%(% " (% , (>>>>.(% n For e%ample: if n is , and % is 9! then the program computes 1(9("9(1"9. =rint %! n! the sum =erform error chec5ing. For e%ample! the formula does not ma5e sense for negative e%ponents < if n is less than 0. 2ave our program print an error message if n?0! then go bac5 and read in the ne%t pair of numbers of without computing the sum. Are an values of % also illegal @ Af so! test for them too. +* 10 #ee" 10 a$ "4s complement of a number is obtained b scanning it from right to left and complementing all the bits after the first appearance of a 1. .hus "4s complement of 11100 is 00100. Write a C program to find the "4s complement of a binar number. b$ Write a C program to convert a Boman numeral to its decimal equivalent. 80 , 11 #ee" 11 Write a C program that uses functions to perform the following operations: i- Beading a comple% number ii- Writing a comple% number iii- Addition of two comple% numbers iv- :ultiplication of two comple% numbers 1Cote: represent comple% number using a structure.- 101 1" #ee" 12 a$ Write a C program which copies one file to another. b$ Write a C program to reverse the first n characters in a file. 1Cote: .he file name and n are specified on the command line.- 10* 1, #ee" 1% a$ Write a C program to displa the contents of a file. b$ Write a C program to merge two files into a third file 1 i.e.! the contents of the first file followed b those of the second are put in the third file- 110 1) #ee" 1& Write a C program that uses functions to perform the following operations on singl lin5ed list.: i- Creation ii- Ansertion iii- 0eletion iv- .raversal 11) 19 #ee" 1' Write C programs that implement stac5 1its operations- using i- Arras ii- =ointers 1)* 1* #ee" 1( Write C programs that implement Dueue 1its operations- using i- Arras ii- =ointers 1*0 No. Name of the Program Page No. !emar" 1; #ee" 1) Write a C program that uses Stac5 operations to perform the following: i- Converting infi% e%pression into postfi% e%pression ii- Evaluating the postfi% e%pression 1;) 1+ #ee" 1* Write C programs that use both recursive and non recursive functions to perform the following searching operations for a Fe value in a given list of integers : i- Ginear search ii- Hinar search 1+" 18 #ee" 1+ Write a C program that implements the following sorting methods to sort a given list of integers in ascending order i- Hubble sort ii- Selection sort "0, ) "0 #ee" 20 Write C program that implements the following sorting method to sort a given list of integers in ascending order: i- Duic5 sort "0; "1 #ee" 21 Write C program that implement the following sorting method to sort a given list of integers in ascending order: i- :erge sort "19 "" #ee" 22 Write C programs to implement the Gagrange interpolation and Cewton$ /regor forward interpolation. ""0 ", #ee" 2% Write C programs to implement the linear regression and polnomial regression algorithms. ""; ") #ee" 2& Write C programs to implement .rapeIoidal and Simpson methods. ",* 9 ,b-ecti.e / 1 .o find the sum of individual digits of a given number 0ecri1tion/ Sum of the individual digits means adding all the digits of a number E%: 1", sum of digits is 1("(,#* Algorithm/ Step 1: start Step ": read n Step ,: initialiIe the s#0 Step ): if n?0 goto Step ; Step 9: if n'#0 goto Step * else goto step ; Step *: store n710 value in p Add p value to s Assign n&10 value to n /oto Step 9 Step ;: print the output Step +:stop * 2lo3chart/
.BJE FAGSE
.BJE
; S.AB. S#0 BEA0 C AF C?0 KJ.=J . W2AGE
C' #0 S.K= =#C710 S#S(= C#C&10 Program/ Linclude?stdio.hM main1- N int n!s!pO clrscr1-O printf1Penter the vaue for n:QnP-O scanf1P7dP!Rn-O s#0O if1n?0- printf1P.he given number is not validP-O else N while1n'#0- &6 chec5 the given value #0 or not 6& N p#n710O n#n&10O s#s(pO S printf1Psum of individual digits is 7dP!s-O S getch1-O S ,ut1ut/ 1.Enter the value for n: ,,, Sum of individual digits is 8 ".Enter the value for n: );,, Sum of individual digits is 1; ,. Enter the value for n: $111 .he given number is not valid 4oncluion / .he program is error free 5I5A 6789ATI,N9/ 1- What is the mean of sum of the individual digits@ Ans: Sum of the individual digits means adding each digit in a number
"- What is positive integer@ Ans: if the integer value is grater than Iero then it is called positive integer ,- 0efine preprocessor @ Ans: Hefore compiling a process called preprocessing is done on the source code b a program called the preprocessor. + ,b-ecti.e/2 .o print the Fibonacci series for 1 to n value 0ecri1tion A fibonacci series is defined as follows .he first term in the sequence is 0 .he second term in the sequence is 1 .he sub sequent terms 1 found b adding the preceding two terms in the sequence Formula: let t1!t"!>>>>tn be terms in fibinacci sequence t1#0! t"#1 tn#tn$"(tn$1>>where nM" algorithm/ Step 1: start Step ": initialiIe the a#0! b#1 Step ,: read n Step ): if n## 1 print a go to step ;. else goto step 9 Step 9: if n## " print a! b go to step ; else print a!b Step *: initialiIe i#, i- if i?# n do as follows. Af not goto step ; c#a(b print c a#b b#c increment A value goto step *1i- Step ;: stop 8 2lo3chart/ S.AB. A#0!b#1 Bead n Af n ##1 Kutput a Af n ##" Kutput a!b Kutput a!b A#" i(( A?n C # a ( b Kutput c A # b H # c Stop .rue False False
.rue False 10 Program/ Linclude?stdio.hM void main1- N int a!b!c!n!iO clrscr1-O printf1Penter n valueP-O scanf1P7dP!Rn-O a#0O b#1O if1n##1- printf1P7dP!a-O else if1n##"- printf1P7d7dP!a!b-O else N printf1P7d7dP!a!b-O &&GKK= WAGG BJC FKB " .A:E GESS AC SEBAES AS .2ESE WAS =BAC.E0 AC A0TACCE for1i#"Oi?nOi((- N c#a(bO printf1P7dP!c-O a#bO b#cO S getch1-O S S ,ut1ut/ 1. Enter n value : 9 0 1 1 " , ". Enter n value : ; 0 1 1 " , 9 + ,. Enter n value : $* 0 1 4oncluion / .he program is error free 11 5I5A 6789ATI,N9/ 1$ #hat i 2ibonacci erie : An/ A fibonacci series is defined as follows .he first term in the sequence is 0 .he second term in the sequence is 1 .he sub sequent terms 1 found b adding the preceding two terms in the sequence Formula: let t1!t"!>>>>tn be terms in fibinacci sequence t1#0! t"#1 tn#tn$"(tn$1>>where nM" "- What are the various tpes of unconditional statements@ Ans: goto!Hrea5 and continue ,-What are the various tpes of conditional statements@ Ans: if ! if else !switch statements )- E%pand ?S.0AK.2 M@ Ans: standard input output header file 1" ,b-ecti.e /% .o print a prime numbers up to 1 to n 0ecri1tion/ =rime number is a number which is e%actl divisible b one and itself onl E%: "! ,!9!;!>>>O Algorithm/ Step 1: start Step ": read n Step ,: initialiIe i#1!c#0 Step ):if i?#n goto step 9 Af not goto step 10 Step 9: initialiIe U#1 Step *: if U?#1 do as the follow. Af no goto step ; i-if i7U##0 increment c ii- increment U iii- goto Step * Step ;: if c## " print i Step +: increment i Step 8: goto step ) Step 10: stop 1, 2lo3 chart/ Start Bead n A # 1 A?#n
A(( V # 1 V((
V?#i Af fact##" Af A 7 U ## 0 Fact (( true false true false Kutput fact false stop false 1) Program/ Linclude?stdio.hM Linclude?conio.hM void main1- N int n!i!fact!UO clrscr1-O printf1Penter the number:P-O scanf1P7dP!Rn-O for1i#1Oi?#nOi((- N fact#0O &&.2AS GKK= WAGG C2ECF A CK .K HE =BA:E CK. KB CK.. for1U#1OU?#iOU((- N if1i7U##0- fact((O S if1fact##"- printf1PQn 7dP!i-O S getch1 -O S ,ut1ut/ Enter the number : 9 " , 9 Enter the number : 10 " , 9 ; Enter the number : 1" " , 9 ; 11 4oncluion / .he program is error free 5I5A 6789ATI,N9/ 1$ #hat i 1rime number : An/ =rime number is a number which is e%actl divisible b one and itself onl "-What is an algorithm@ Ans : A step b step procedure is called algorithm ,-What is flow chart@ Ans: A pictorial representation an algorithm is called a flow chart )-What is program@ 19 Ans : A collection of statements is called ,b-ecti.e/& .o find the roots of the quadratic equation 0ecri1tion/ Cature of roots of quadratic equation can be 5nown from the quadrant # b " $)ac Af b " $)ac M0 then roots are real and unequal Af b " $)ac #0 then roots are real and equal Af b " $)ac ?0 then roots are imaginar Algorithm/ Step 1: start Step ": read the a!b!c value Step ,: if b6b$)acM0 then Boot 1# 1$b( pow11b6b$)6a6c-!0.9--&"6a Boot "# 1$b$pow11b6b$)6a6c-!0.9--&"6a Step ): if b6b$)ac#0 then Boot1 # Boot" # $b&1"6a- Step 9: Ktherwise =rint Amaginar roots. /oto step ;. Step *: print roots Step ;: stop 1* 2lo3chart/ Start Bead a!b!c 0 # pow1b6b$)6a6c-!0.9 Af d M 0 B1 # 11$b(0- & 1"6a-- B" # 11$b$0- &1"6a-- Kutput B1! B" Stop Af d## 0 B1#$b & 1" 6 a - B"# $b & 1" 6 a- Amaginar roots true false 1; Program/ Linclude?stdio.hM Linclude?math.hM void main1- N float a!b!c!r1!r"!dO clrscr1-O printf1PEnter the values for equation:P-O scanf1P7f7f7fP!Ra!Rb!Rc-O &6 chec5 the condition 6& if1a##0- printf1PEnter value should not be Iero P-O else N d#b6b$)6a6cO &6 chec5 the condition 6& if1dM0- N r1#1$b(sqrt1d-&1"6a--O r"#1$b$sqrt1d-&1"6a--O printf1Proots are real and unequalQnP-O printf1P7fQn7fQnP!r1!r"-O S else if1d##0- N r1#$b&1"6a-O r"#$b&1"6a-O printf1Proots are real and equalQnP-O printf1Proot#7fQnP!r1-O printf1Proot#7fQnP!r"-O S else printf1Proots are imaginarP-O S getch1-O S ,ut1ut/ 1. Enter the values for equation: 1! *! 8 Boots are real and equal Boot# $,.0000 Boot# $,.0000 1+ ". Enter the values for equation: "! ;! * Boots are real and unequal Boot# $*.;9 Boot# $;."9 ,. Enter the values for equation: 1! "! , Boots are imaginar 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1$ What are various tpes of loop statements@ Ans : While! do$ while! for loop statements 9- What is the difference between while and do$while statements@ Ans: An while the condition will be chec5ed first and then enter into a loop. Hut in do$ while the statements will be e%ecuted first and then finall chec5 the Condition. ,- 2ow to find the roots of qudratric equtations @ Ans: Cature of roots of quadratic equation can be 5nown from the quadrant # b " $)ac Af b " $)ac M0 then roots are real and unequal Af b " $)ac #0 then roots are real and equal Af b " $)ac ?0 then roots are imaginar )- Gist out the C features @ Ans: =ortabilit!fle%ibilit! wide acceptabilit etc..! 18 ,b-ecti.e/' .o calculate the sum. Sum#1$% " &"'( % ) &)'$ % * &*'( % + &+'$ % 10 &10' Algorithm/ main program: Step 1: start Step ": declare %!i!n!s#0!c Step ,: read % value Step ): for i#0 ! n#0O i?#10O i#i("! n(( goto step 9 Step 9: s#s(1pow1$1!n-6pow1%!i-&fact1i-- Step *: print s value Step ;: stop 9ub 1rogram/ Step 1: while %'#0 goto Step " Step ": #(%O %W Step ,: return Step ): return to main program "0 2lo3chart/ Start Bead %!A!n!c S # 0 A#0!n#0 i?#10 A # A ( "! n(( S#s(1pow1$1!n-6pow1%!i- & fact1i-- =rint s Stop Sub =rogram While %' #0 X#6% %$$ Beturn Fact 1- Beturn to main program "1 Program/ Linclude?stdio.hM Linclude?math.hM long fact1int-O void main1- N int %!i!nO float s#0!cO clrscr1-O printf1PQn enter the value of %QtP-O scanf1P7dP!R%-O &6perform the looping operation6& for1i#0!n#0Oi?#10Oi#i("!n((- s#s(1pow1$1!n-6pow1%!i-&fact1i--O printf1PQn the result is 7fP!s-O getch1-O S &6 calling sub program6& long fact1int %- N long int #1O while1%'#0- N #6%O %$$O S return O S ,ut1ut/ 1.Enter the value of % : 1 .he result is 0.9)0,0" " Enter the value of %: " .he result is $0.)1*199 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1- What is function @ Ans: A function is a sub program it returns a value. "- What is procedure @ Ans: A procedure is a sub program it does not returns a value
,- What are the basic data tpes in C @ Ans: int! char! float! double )- 2ow to define preprocessor @ Ans: H using the L smbal E%: Linclude?stdio.hM "" ,b-ecti.e/ ( =rograms that use recursive function to find the factorial of a given integer. 0ecri1tion/ Factorial of a number is nothing but the multiplication of numbers from a given number to 1 Algorithm/ main program Step 1: start Step ": read n Step ,: call sub program as f#fact1n- Step ): print f value Step 9: stop 9ub 1rogram/ Step 1: initialiIe the f Step ": if n# # 0 or n ## 1 return 1 to main program if not goto step , Step ,: return n6fact1n$1- to main program ", 2lo3chart/ Start Bead n Call subprogram F # fact1n- output Stop 9ub 1rogram Fact 1- Af n#0 YY n#1 Beturn n6fact1n$1- Beturn to main program true false ") Program/ Linclude?stdio.hM Linclude?conio.hM int fact1int n- N int fO if11n##0-YY1n##1-- && chec5 the condition for the n value return1n-O else f#n6fact1n$1-O &&calculate the factorial of n return1f-O S void main1- N int nO clrscr1-O printf1Penter the number :P-O scanf1P7dP!Rn-O printf1Pfactoria of number7dP!fact1n--O getch1-O S ,ut1ut/ 1. Enter the number : 9 Factorial of number: 1"0 ". Enter the number : , Factorial of number: * ,. Enter the number : 8 Factorial of number: $,0,,* 4oncluion/ the program is error free 5I5A 6789ATI,N9/ 1- What is the meaning of factorial number@ An / Factorial of a number is nothing but the multiplication of numbers from a given number to 1 "- What is the meaning of recusive function @ Ans: A function call it self is called recursive function ,- define librar functions @ Ans: .he functions have alread been written! compiled and placed in libraries and are called librar functions. )- 0efine formal parameters @ Ans: Formal parameters are the parameters given in the function declaration as function definition. "9 ,b-ecti.e / ) =rogram that use non recursive function to find the factorial of a given integer. 0ecri1tion/ Factorial of a number is nothing but the multiplication of numbers from a given number to 1 E%: 9' #96)6,6"61# 1"0 Algorithm/ main program Step 1: start Step ": read n Step ,: call the sub program fact1n- Step ): print the f value Step 9: stop 9ub 1rogram/ Step 1: initialiIe the f#1 Step ": if n##0 or n#1 return 1 to main program. Af not goto step , Step ,: perform the looping operation as follows For i#1 i?#nO i(( Step ): f#f6i Step 9: return f value to the main program "* 2lo3chart/ 2actorial nonrecuri.e start Bead i Call subprogram Fact1n- =rint output Talue of fact Stop 9ub 1rogram Fact 1 - F # 1! i Af n ## 0 YY n ## 1 Beturn to main
program A # 1 i(( A?#n
F # f 6 i "; Program/ Linclude?stdio.hM Linclude?conio.hM int fact1int n- &&starting of the sub program N int f#1!iO if11n##0-YY1n##1-- && chec5 the condition for n value return11-O else for1i#1Oi?#nOi((- && perform the looping operation for calculating the factorial f#f6iO return1f-O S void main1- N int nO clrscr1-O printf1Penter the number :P-O scanf1P7dP!Rn-O printf1Pfactoria of number7dP!fact1n--O getch1-O S ,ut1ut/ 1.Enter the number: ; Factorial of number: 90)0 ". Enter the number: * Factorial of number: ;"0 ,. Enter the number: + Factorial of number: $"9"1* 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1- What is meant b call b value @ Ans: passing values to the function as arguments "- What is meant b call b reference @ Ans: passing address to the function as arguments ,-define actual parameters @ Ans: .he actual parameters often 5nown as arguments are specified in the function call. "+ ,b-ecti.e/ * .o find the /C0 of two given integers b using the recursive function 0ecri1tion/ /C0 means /reatest Common 0ivisor. i.e the highest number which divides the given number E%: /C011"!")- is 1" Formula: /C0# product of numbers& GC: of numbers Algorithm/ main program Step 1: start Step ": read a!b Step ,: call the sub program /C01a!b- for print the value Step ): stop 9ub 1rogram/ Step 1: if nMm return /C01n!m- Step ": if n##0 return m else goto step , Step ,: return /C0 1n!m7n- Step ): return to main program "8 2lo3chart/ Start Bead a!b Call sub program /#gcd1a!b- =rint gcdvalue Stop /cd1 - Af nMm Beturn /cd 1n!m- Af n##0 Beturn m Call the same function Beturn gcd 1 n!m7n- Beturn to main program true false true F ,0 Program/ Linclude?stdio.hM Linclude?conio.hM int gcdrecursive1int m!int n- && starting of the sub program N if1nMm- return gcdrecursive1n!m-O if1n##0- return mO else return gcdrecursive1n!m7n-O && return to the main program S void main1- N int a!b!igcdO clrscr1-O printf1Penter the two numbers whose gcd is to be found:P-O scanf1P7d7dP!Ra!Rb-O printf1P/C0 of a!b is 7dP!gcdrecursive1a!b--O && return to the sub program getch1-O S ,ut1ut/ 1. enter the two numbers whose gcd is to be found:9!"9 /C0 of a!b is : 9 ". enter the two numbers whose gcd is to be found:,*!9) /C0 of a!b is : 1+ ,. enter the two numbers whose gcd is to be found:11!1, /C0 of a!b is : 1 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1- What is meaning of /C0 @ Ans: /C0 means /reatest Common 0ivisor. i.e the highest number which divides the given number "- 0efine scope of a variable @ Ans: .he scope of a variable can be define as the region over which the variable is accessible ,- Show an scope resolution operator @ Ans: double colon1//-
)- 0efine e%tent of a variable @ Ans: .he period of time during which memor is associated with a variable is called e%tent of the variable. ,1 ,b-ecti.e/ + .o find the /C0 of two given integers b using the non recursive function 0ecri1tion/ /C0 means /reatest Common 0ivisor. i.e the highest number which divides the given number E%: /C011"!")- is 1" Formula: /C0# product of numbers& GC: of numbers Algorithm/ Step 1: start Step ": read a!b Step ,: call sub program g#/C01a!b- Step ): print the g value Step 9: stop Sub program: Step 1: initialiIe the p#1! q! remainder Step ": remainder#p$1p&q6q- Step ,: remainder#0 return q else goto step ) Step ): /C01q!remainder- return to main program ," 2lo3chart/ start Bead a! b Call subprogram g#gcd1a!b- output stop /cd 1 - Bemainder#p$1p&q6q- Af remainder##0 /cd1q!remainder- Beturn q Beturn to main program false .rue ,, Program/ Linclude?stdio.hM Linclude?conio.hM Linclude?math.hM int gcdnonrecursive1int m!int n- N int remainderO remainder#m$1m&n6n-O if1remainder##0- return nO else gcdnonrecursive1n!remainder-O S void main1- N int a!b!igcdO clrscr1-O printf1Penter the two numbers whose gcd is to be found:P-O scanf1P7d7dP!Ra!Rb-O printf1P/C0 of 7dP!gcdnonrecursive1a!b--O getch1-O S ,ut1ut/ 1. enter the two numbers whose gcd is to be found:9!"9 /C0 of a!b is : 9 ". enter the two numbers whose gcd is to be found:,*!9) /C0 of a!b is : 1+ ,. enter the two numbers whose gcd is to be found:11!1, /C0 of a!b is : 1 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1$What is meaning of /C0 @ Ans: /C0 means /reatest Common 0ivisor. i.e the highest number which divides the given number ,) ,b-ecti.e /10 .o solve the towers of 2anoi problem b using the recursive function 0ecri1tion/ .owers of 2anoi problem means we have three towers 2ere source !intermediate and destination are the three towers. We have to transfer all the dis5s from source to destination towers. 2ere the restriction is not to place a big dis5 on smaller one . for this we use intermediate tower. Finall the arrangements in the destination tower must be as same as the dis5s in the source tower at first. Algorithm/ main 1rogram Step 1: start Step ": initialiIe the source#a! intermediate#c! destination # d Step ,: read n Step ): call the sub program 2anoi recursion 1n value!a !b! c- Step 9: stop Sub program: Step 1: if n## 1 call the sub program 2anoi recursion 1num$1! a! c! b- Step ": print the output from a to b Step ,: call the sub program 2anoi recursion1num$1! b! c! a- Step ): return to main program Source intermediate destination ,9 2lo3chart/ S.AB. SKJBCE # A AC.EB:E0AA.E # C 0ES.ACA.AKC # H BEA0 n Call subprogram 2anoi1num!source!intermediate!destination- A!C! H Stop =rint A!C Beturn to main program hanoirecursive1 - Af num##1 =rint A!C Call ubprogram 2anoi1num$1!H!C!A-- true false Call sbgroram Cum$1!source ZA[ ,* Program/ Linclude?stdio.hM Linclude?conio.hM void 2anoirecursion1int num!char ndl1!char ndl"!char ndl,- N if1num##1- N printf1P:ove top dis5 from needle 7c to needle 7cP!ndl1!ndl"-O returnO S 2anoirecursion1num$1!ndl1!ndl,!ndl"-O printf1P:ove top dis from needle 7c to needlle 7cP!ndl1!ndl"-O 2anoirecursion1num$1!ndl,!ndl"!ndl1-O S void main1- N int noO clrscr1-O printf1PEnter the no. of dis5 to be transferred:P-O scanf1P7dP!Rno-O if1no?1- printf1PQn .here\s nothing to moveP-O else printf1PQn recursiveP-O 2anoirecursion1no!\A\!\H\!\C\-O getch1-O S ,ut1ut/ 1. Enter the no. of dis5 to be transferred :, :ove top dis5 from needle a to needle b :ove top dis5 from needle a to needle c :ove top dis5 from needle b to needle c :ove top dis5 from needle a to needle b :ove top dis5 from needle c to needle a :ove top dis5 from needle c to needle b :ove top dis5 from needle a to needle b 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1$ #hat i 1ur1oe of to3er of ;anoi : An/ We have to transfer all the dis5s from source to destination towers. 2ere the restriction is not to place a big dis5 on smaller one . for this we use intermediate tower. Finall the arrangements in the destination tower must be as same as the dis5s in the source tower at first. ,; ,b-ecti.e /11 .o solve the towers of 2anoi problem b using the non recursive function 0ecri1tion/ .owers of 2anoi problem means we have three towers 2ere source !intermediate and destination are the three towers. We have to transfer all the dis5s from source to destination towers. 2ere the restriction is not to place a big dis5 on smaller one . for this we use intermediate tower. Finall the arrangements in the destination tower must be as same as the dis5s in the source tower at first. Algorithm/ Step 1: start Step ": declare the no Step ,: read the no value Step ): if 1no?1- =rint nothing to move Else =rint nonrecursion Step 9:2anoi non recursion1no!.A4!4H4!4C4- Step *:stop Sub program: Step 1: 0eclare num!sndl!indl!dndl! st5n] ^!st5sndl] ^!st5dndl ] ^!st5add] ^! temp!top!add Step ": declare the top#CJGG Step ,: one: Af1num##1-then =rint the out put value /oto four Step ): two: .op#top(1 St5n]top^#num St5sndl]top^#sndl St5indl]top^#indl St5dndl]top^#dndl St5add]top^#, Cum#num$1 Source intermediate destination ,+ Sndl#sndl .emp#indl Andl#dndl 0ndl#temp /oto one. /oto step , Step 9: .hree: =rint the output .op#top(1 St5n]top^#num St5sndl]top^#sndl St5indl]top^#indl St5dndl]top^#dndl St5add]top^#9 Cum#num$1 temp#sndl sndl#indl Andl#temp 0ndl#dndl /oto one. /oto step , Step *: Four: Af1top##CJGG- Beturn to main program Cum# st5n]top^ Sndl# st5sndl]top^ Andl# st5indl]top^ 0ndl#st5dndl]top^ Add#st5add]top^ .op#top$1 Af1add##,- /oto three. /oto step 9 Else Af1add##9- /oto four. /oto step *. Step ;: return to main program ,8 2lo3 chart/
)0 Start Bead no Af no? 1 =rint nothing to move true false =rint nonrecursion 2anoinonrecursion 1no!.A4!4H4!4C4- Stop 2anoi nonrecursion 1 - 0eclare num!sndl!indl!dndl! st5n] ^!st5sndl] ^!st5dndl ] ^!st5add] ^! temp!top!add .op # CJGG Af num##1 =rint the value true Af top#CJG G Cum# st5n]top^ Sndl# st5sndl]top^ Andl# st5indl]top^ 0ndl#st5dndl]top^ Add#st5add]top^ .op#top$1 Af add##, false Af add## 9 .op#top(1 St5n]top^#num St5sndl]top^#sndl St5indl]top^#indl St5dndl]top^#dndl St5add]top^#, Cum#num$1 Sndl#sndl .emp#indl Andl#dndl 0ndl#temp one four two =rint value .op#top(1 St5n]top^#num St5sndl]top^#sndl St5indl]top^#indl St5dndl]top^#dndl St5add]top^#9 Cum#num$1 temp#sndl sndl#indl Andl#temp 0ndl#dndl .op#top(1 )1 Program/ Linclude?stdio.hM Linclude?conio.hM void 2anoinonrecursion1int num!char sndl!char indl!char dndl- N char st5n]100^!st5sndl]100^!st5indl]100^!st5dndl]100^!st5add]100^!tempO int top!addO top#CJGGO one: if1num##1- N printf1PQn :ove top dis5 from needle 7c to needle 7cP!sndl!dndl-O goto fourO S two: top#top(1O st5n]top^#numO st5sndl]top^#sndlO st5indl]top^#indlO st5dndl]top^#dndlO st5add]top^#,O num#num$1O sndl#sndlO temp#indlO indl#dndlO dndl#tempO goto oneO three: printf1PQn :ove top dis5 from needle 7c to needle 7cP!sndl!dndl-O top#top(1O st5n]top^#numO st5sndl]top^#sndlO st5indl]top^#indlO st5dndl]top^#dndlO st5add]top^#9O num#num$1O temp#sndlO sndl#indlO indl#tempO dndl#dndlO goto oneO four: if1top##CJGG- returnO )" num#st5n]top^O sndl#st5sndl]top^O indl#st5indl]top^O dndl#st5dndl]top^O add#st5add]top^O top#top$1O if1add##,- goto threeO else if1add##9- goto fourO S void main1- N int noO clrscr1-O printf1PEnter the no. of diss to be transferred:P-O scanf1P7dP!Rno-O if1no?1- printf1PQn .here\s nothing to moveP-O else printf1PQn nonrecursiveP-O 2anoinonrecursion1no!\A\!\H\!\C\-O getch1-O S ,ut1ut/ 1.Enter the no. of diss to be transferred:, nonrecursive :ove top dis5 from needle A to needle C :ove top dis5 from needle A to needle H :ove top dis5 from needle C to needle H :ove top dis5 from needle A to needle C :ove top dis5 from needle H to needle A :ove top dis5 from needle H to needle C :ove top dis5 from needle A to needle C 4oncluion/ .he program is error freed 5I5A 6789ATI,N9/ 1$ #hat i 1ur1oe of to3er of ;anoi : An/ We have to transfer all the dis5s from source to destination towers. 2ere the restriction is not to place a big dis5 on smaller one . for this we use intermediate tower. Finall the arrangements in the destination tower must be as same as the dis5s in the source tower at first. 2$ #hat i an arra< : Ans: An arra is a sequence of memor location of same data tpe. ), ,b-ecti.e/ 12 .he total distance travelled b vehicle in \t\ seconds is given b distance # ut(1&"at" where \u\ and \a\ are the initial velocit 1m&sec.- and acceleration 1m&sec"-. Write C program to find the distance travelled at regular intervals of time given the values of \u\ and \a\. .he program should provide the fle%ibilit to the user to select his own time intervals and repeat the calculations for different values of \u\ and \a\. 0ecri1tion/ .he total distance travelled b vehicle in \t\ seconds is given b distance # ut(1&"at" where \u\ and \a\ are the initial velocit 1m&sec.- and acceleration 1m&sec"-. Algorithm/ Step 1:Start Step" : Bead t !dt Step ,: Set i to 1 Step ):Set 5 to dt Step 9: Bead u!a Step *: set s to u65(0.96d6565 Step ;: Write s Step +: Af15?#t- and i#1 then Hegin Step +.1 go to step * And Else Hegin Step +." :read Step +., :if1U#0- then Hegin Step +.,.1:Set A to 0 End Else Hegin Step +.,.": Set A to 1 Step +.,.,: go to step ) End Step 8: Stop Step 10: End )) 2lo3chart/ )9 Program/ Linclude?stdio.hM main1- N int a!u!t!t1!t"!iO float sO clrscr1-O printf1PEC.EB .2E TAGJES KF a!u!t!t1!t":P-O scanf1P7d7d7d7d7dP!Ra!Ru!Rt!Rt1!Rt"-O for1i#t1Oi?#t"Oi#i(t- && performing the looping operation for time intervals N s#1u6i-(10.96a6i6i-O && calculate the total distance printf1PQnQnthe distance travelled in 7d seconds is 7f P!i!s-O S getch1-O S In1ut=,ut1ut/ 1.EC.EB .2E TAGJES KF a!u!t!t1!t":1 " , 1 9 the distance travelled in 1 seconds is ".900000 the distance travelled in ) seconds is 1*.000000 ".EC.EB .2E TAGJES KF a!u!t!t1!t":0 1 " , ) the distance travelled in , seconds is ,.000000 concluion/ .he program is error free 5I5A 6789ATI,N9/ 1- 2ow man tpes of arras are there @ Ans: .hree tpes. .he are one dimensional !two dimensional and multi dimensional arrs )* ,b-ecti.e/1% .wo integer operands and one operator form user! performs the operation and then prints the result. 1Consider the operators (!$!6! &! 7 and use Switch Statement- 0ecri1tion/ .o ta5e the two integer operands and one operator from user to perform the some arithmetic operations b using the following operators li5e (!$!6! &! 7 E%: "(,#9 Algorithm/ Step 1: Start Step ": Bead the values of a!b and operator Step ,: if the operator is 3(4 then B#a(b /o to step + Hrea5 Step ): Else if the operator is 3$3 then B#a$b /o to step + Step 9: Else if the operator is 363 then B#a6b /o to step + Step *: Else if the operator is 3&3 then B#a&b /o to step + Step ;: Else if the operator is 373 then B#a7b /o to step + Step +: write B Step 8:End ); 2lo3chart/ )+ Program/ Linclude?stdio.hM main1- N char opO float a!b!cO clrscr1-O printf1Penter two operands:P-O scanf1P7d7dP!Ra!Rb-O printf1Penter an operator:P-O scanf1P 7cP!Rop-O switch1op- && used to select particular case from the user N case \(\:printf1Psum of two numbers 7"d 7"d is: 7dP!a!b!a(b-O brea5O case \$\:printf1Psubtraction of two numbers 7"d 7"d is: 7dP!a!b!a$b-O brea5O case \6\:printf1Pproduct of two numbers 7"d 7"d is: 7dP!a!b!a6b-O brea5O case \&\:printf1Pquotient of two numbers 7"d 7"d is: 7dP!a!b!a&b-O brea5O case \7\:printf1Preminder of two numbers 7"d 7"d is: 7dP!a!b!c-O brea5O default:printf1Pplease enter correct operatorP-O brea5O S getch1-O S In1ut=,ut1ut/ 1.enter two operands:" , enter an operator:( sum of two numbers " , is: 9 ".enter two operands:, ) enter an operator: $ subtraction of two numbers , ) is: $1 ,.enter two operands:, 9 )8 enter an operator:6 product of two numbers , 9 is: 19 ).enter two operands:9 " enter an operator:& quotient of two numbers 9 " is: " 9. enter two operands:9 " enter an operator:7 reminder of two numbers 9 " is: 1 concluion/ .he program is error free 5I5A 6789ATI,N9/ 1- What are the various tpes of arithemetic operators @ Ans: addition 1(-! multiplication16-! subtraction 1$-! division1&- ! modulo17-. "- What are the tpes of relational operators @ Ans: less than1?-! grater than1M-! less than or equal to1?#-!equal to1##-! etc..! ,- ,- What are the tpes of logical operators @ Ans: logical AC0 1RR-! logical KB1YY-! logical CK.1'- 90 ,b-ecti.e / 1& .o find both the largest and smallest number in a list of integers 0ecri1tion/ .his program contains n number of elements! in these elements we can find the largest and smallest numbers and displa these two numbers Algorithm/ Step 1: start Step ": read n Step ,: initialiIe i#0 Step ): if i?n do as follows. Af not goto step 9 Bead a]i^ Ancrement i /oto step ) Step 9: min#a]0^! ma%#a]0^ Step *: initialiIe i#0 Step ;: if i?n do as follows. Af not goto step + Af a]i^?min Assign min#a]i^ Ancrement i goto Step ; Step +: print min!ma% Step 8: stop 91 Bead n! a]i^!min!ma%! :in # a]0^ :a% # a]0^ =rint min!ma% A # 0 i(( A? n :a%?min A]i^Mma % :in#a]i^ :a%#a]i^ A# 0 A?n i((
stop Bead a]i^ Start true false true false false true 2lo3chart/ 9" Program/ Linclude?stdio.hM void main1- N int a]10^!i!n!min!ma%O clrscr1-O printf1Penter the arra siIe:P-O scanf1P7dP!Rn-O printf1PEnter the elements of arraP-O for1i#0Oi?nOi((- && read the elements of an arra scanf1P7dP!Ra]i^-O min#a]0^O ma%#a]0^O for1i#0Oi?nOi((-&& read the elements of an arra N if1a]i^?min-&& chec5 the condition for minimum value min#a]i^O if1a]i^Mma%-&&chec5 the condition for ma%imum value ma%#a]i^O S printf1Pma%imum value is:7dQnP!ma%-O printf1Pminimum value is:7dQnP!min-O getch1-O S ,ut1ut/ 1.enter the arra siIe:) Enter the elements of arra ,* 1, " )9 ma%imum value is:)9 minimum value is:" ".enter the arra siIe:9 Enter the elements of arra * " 1 , + ma%imum value is:+ minimum value is:1 ,.enter the arra siIe:9 Enter the elements of arra$* 8 $8 " 9 ma%imum value is:8 minimum value is:$8 concluion/ the program is error free 5I5A 6789ATI,N9/ 1$ What is an arra : Ans: .he collection of similar elements is called arra "- 2ow man tpes of arras are there @ Ans: .hree tpes. .he are one dimensional !two dimensional and multi dimensional arrs 9, ,b-ecti.e/1' .o perform the addition of two matrices 0ecri1tion/ program ta5es the two matri%es of same siIe and performs the addition an also ta5es the two matri%es of different siIes and chec5s for possibilit of multiplication and perform multiplication if possible. algorithm/ Step 1: start Step ": read the siIe of matrices A!H < m!n Step ,: read the elements of matri% A Step ): read the elements of matri% H Step 9: select the choice for ou want. Af ou select case 1 then goto matric addition. Else goto Step ;. Step *: print Sum of matri% A and H Step ;: if ou select case " then goto matri% multiplication Step +: chec5 if n#p! if not print matrices can not be multiplied Step 8: Ktherwise perform the multiplication of matrices Step 10: =rint the resultant matri% Step 11: Stop 9) start Bead the siIe of A!H matri% m!n A#0 A? r1 i(( 0eclare a]^]^!b]^ ]^!c]^ ]^!ch!A!U!5!m!n!p!q!r1! c1 Bead the choice ch Af ch?#" RchM0 =rintvalid choice Switch ch Bead the siIe of A matri% m!n Bead A]i^]U^ V#0 UA? c1 Ui(( A#0 A? r1 i(( U#0 UA?c1 U(( Bead H]i]U^ A#0 A? r1 i(( U#0 U?c1 U(( Bead A]i^]U^ Bead siIe of matri% H: p.q A#0 A? p i(( H Case 1 Case " 2lo3 chart/ 99 H A#0 A? r1 i(( U#0 U? c1 U(( =rint A]i^]U^(H]i^ ]U^
Stop H U#0 U? q U(( Bead H]i^]U^ Af n##p :atri% cannot be mutiplied i#0 i?m i(( U#0 U? q U(( C]i^]U^#0 50 U? n 5(( C]i^]U^#C]i^]U^(A]i^]5^6H]5^]U^ i#0 i?m i(( U(( U#0 U?q U(( =rint C]i^]U^ A 9* Program/ Linclude?stdio.hM void main1- N int ch!i!U!m!n!p!q!5!r1!c1!a]10^]10^!b]10^]10^!c]10^]10^O clrscr1-O printf1P666666666666666666666666666666666666P-O printf1PQnQtQt:ECJP-O printf1PQn6666666666666666666666666666666666P-O printf1PQn]1^A00A.AKC KF .WK :A.BACESP-O printf1PQn]"^:JG.A=GACA.AKC KF .WK :A.BACESP-O printf1PQn]0^E_A.P-O printf1PQn6666666666666666666666666666666666P-O printf1PQnQtEnter our choice:QnP-O scanf1P7dP!Rch-O if1ch?#" R chM0- N printf1PTalid ChoiceQnP-O S switch1ch- N case 1: printf1PAnput rows and columns of A R H :atri%:P-O scanf1P7d7dP!Rr1!Rc1-O printf1PEnter elements of matri% A:QnP-O for1i#0Oi?r1Oi((- N for1U#0OU?c1OU((- scanf1P7dP!Ra]i^]U^-O S printf1PEnter elements of matri% H:QnP-O for1i#0Oi?r1Oi((- N for1U#0OU?c1OU((- scanf1P7dP!Rb]i^]U^-O S printf1PQn #####:atri% Addition#####QnP-O for1i#0Oi?r1Oi((- N For1U#0OU?c1OU((- printf1P79dP!a]i^]U^(b]i^]U^-O 9; printf1PQnP-O S brea5O case ": printf1PAnput rows and columns of A matri%:P-O scanf1P7d7dP!Rm!Rn-O printf1PAnput rows and columns of H matri%:P-O scanf1P7d7dP!Rp!Rq-O if1n##p- N printf1Pmatrices can be multipliedQnP-O printf1Presultant matri% is 7d67dQnP!m!q-O printf1PAnput A matri%QnP-O read`matri%1a!m!n-O printf1PAnput H matri%QnP-O &6Function call to read the matri%6& read`matri%1b!p!q-O &6Function for :ultiplication of two matrices6& printf1PQn #####:atri% :ultiplication#####QnP-O for1i#0Oi?mO((i- for1U#0OU?qO((U- N c]i^]U^#0O for15#0O5?nO((5- c]i^]U^#c]i^]U^(a]i^]5^6b]5^]U^O S printf1PBesultant of two matrices:QnP-O write`matri%1c!m!q-O S &6end if6& else N printf1P:atrices cannot be multiplied.P-O S &6end else6& brea5O case 0: printf1PQn Choice .erminatedP-O e%it1-O brea5O default: printf1PQn Anvalid ChoiceP-O 9+ S getch1-O S &6Function read matri%6& int read`matri%1int a]10^]10^!int m!int n- N int i!UO for1i#0Oi?mOi((- for1U#0OU?nOU((- scanf1P7dP!Ra]i^]U^-O return 0O S &6Function to write the matri%6& int write`matri%1int a]10^]10^!int m!int n- N int i!UO for1i#0Oi?mOi((- N for1U#0OU?nOU((- printf1P79dP!a]i^]U^-O printf1PQnP-O S return 0O S ,ut1ut/ 1. 666666666666666666666666666666666666 :ECJ 6666666666666666666666666666666666 ]1^A00A.AKC KF .WK :A.BACES ]"^:JG.A=GACA.AKC KF .WK :A.BACES ]0^E_A. 6666666666666666666666666666666666 Enter our choice: 1 Talid Choice Anput rows and columns of A R H :atri%:" " Enter elements of matri% A: " " " 98 " Enter elements of matri% H: " " " " #####:atri% Addition##### ) ) ) ) 666666666666666666666666666666666666 :ECJ 6666666666666666666666666666666666 ]1^A00A.AKC KF .WK :A.BACES ]"^:JG.A=GACA.AKC KF .WK :A.BACES ]0^E_A. 6666666666666666666666666666666666 Enter our choice: " Talid Choice Anput rows and columns of A matri%:" , Anput rows and columns of H matri%:" " :atrices cannot be multiplied. 666666666666666666666666666666666666 :ECJ 6666666666666666666666666666666666 ]1^A00A.AKC KF .WK :A.BACES ]"^:JG.A=GACA.AKC KF .WK :A.BACES ]0^E_A. 6666666666666666666666666666666666 Enter our choice: " Talid Choice Anput rows and columns of A matri%:" " Anput rows and columns of H matri%:" " matrices can be multiplied resultant matri% is "6" Anput A matri% " " " *0 " Anput H matri% " " " " #####:atri% :ultiplication##### Besultant of two matrices: + + + + 4oncluion / .he program is error free 5I5A 6789ATI,N9/ 1- What is condition for performing an matric addition @ Ans: program ta5es the two matri%es of same siIe and performs the addition "- What is condition for performing an matric addition @ Ans: .he two matri%es of different siIes and chec5s for possibilit of multiplication and perform multiplication if possible *1 ,b-ecti.e /1(
Functions to insert a sub string into given main string from a given position 0ecri1tion/ in this program we need to insert a string into another string from a specified position. Algorithm/ Step 1: start Step ": read main string and sub string Step ,: find the length of main string1r- Step ): find length of sub string1n- Step 9: cop main string into sub string Step *: read the position to insert the sub string1 p- Step ;: cop sub string into main string from position p$1 Step +: cop temporar string into main string from position p(n$1 Step 8: print the strings Step 10: stop *" Start Bead the strings A R H A # 0 A ? r C]i^ # A]i^ A (( S # n ( r K # p ( n A #p A(( A ? s _# C]i^ Af t ? n
A
H 2lo3 chart/ *,
A A]i^ # H]t^ .#t(1 A]o^#% K # o ( 1 H =rint output Stop *) Program/ Linclude ?stdio.hM Linclude ?conio.hM Linclude ?string.hM void main1- N char a]10^O char b]10^O char c]10^O int p#0!r#0!i#0O int t#0O int %!g!s!n!oO clrscr1-O puts1PEnter First String:P-O gets1a-O puts1PEnter Second String:P-O gets1b-O printf1PEnter the position where the item has to be inserted: P-O scanf1P7dP!Rp-O r # strlen1a-O n # strlen1b-O i#0O && Coping the input string into another arra while1i ?# r- N c]i^#a]i^O i((O S s # n(rO o # p(nO && Adding the sub$string for1i#pOi?sOi((- N % # c]i^O if1t?n- N a]i^ # b]t^O t#t(1O S a]o^#%O o#o(1O *9 S printf1P7sP! a-O getch1-O S ,ut1ut/ 1.enter first string: computer ".enter second string: gec ,.enter the position where the item has to be inserted:, comgecputer concluion / the program is error free 5I5A 6789ATI,N9/ 1- What is string @ Ans: A string is an collection of characters "- Which command is used to combined the two strings @ Ans: Strcat1- ,- Which command is used to cop the strings @ Ans: H using the strcp1- function copies one string to another ** ,b-ecti.e/1) .o delete n characters from a given position in a given string 0ecri1tion/ in this program we need to delete a string from the given string at a specified position. Algorithm/ Step 1: start Step ": read string Step ,: find the length of the string Step ): read the value of number of characters to be deleted and positioned Step 9: string cop part of string from position to end! and 1position(number of characters to end- Step *: stop *; Start Bead string Bead position! no of characters 0elchar1 string! n! pos- Stop Subprogram 0elchar1 - Af 11a(b$1`?#
strlen1%-- Strcp1R%]b$1^!R%]a(b$1^- =uts1%- Beturn to mainprogram 2lo3 chart/ *+ Program/ Linclude ?stdio.hM Linclude ?conio.hM Linclude ?string.hM void delchar1char 6%!int a! int b-O void main1- N char string]10^O int n!pos!pO clrscr1-O puts1PEnter the stringP-O gets1string-O printf1PEnter the position from where to deleteP-O scanf1P7dP!Rpos-O printf1PEnter the number of characters to be deletedP-O scanf1P7dP!Rn-O delchar1string! n!pos-O getch1-O S && Function to delete n characters void delchar1char 6%!int a! int b- N if 11a(b$1- ?# strlen1%-- N strcp1R%]b$1^!R%]a(b$1^-O puts1%-O S S ,ut1ut/ 1.enter the string nagaraUu Enter the position from where to delete:) Enter the number of charcters to be deleted, nagUu ". enter the string 5aliraUu Enter the position from where to delete:0 Enter the number of charcters to be deleted) BaUu 4oncluion/ the program is error free *8 5I5A 6789ATI,N9/ 1- Which command is used to delete the strings @ Ans: delstr1-O "- What are the various tpes of string functions @ Ans: Strcat1-! strcp1-! delstr1-! substr1- !strlen1-etc..! ;0 ,b-ecti.e/ 1* .o determine if the given string is a palindrome or not 0ecri1tion/ if the reverse of a string is equal to original string then it is called palindrome Algorithm/ Step 1:start Step ": read the string Step ,: store reverse of the given string in a temporar string Step ): compare the two strings Step 9: if both are equal then print palindrome Step *: otherwise print not palindrome Step ;: stop ;1 Start Bead string Af1Aspalindro me1string- Aspalindrome1string- =rint palindrome true =rint not palindrome Stop 2lo3 chart/ ;" Aspalindrome1 - Enum Hoolean matched# true Af len## 0 Beturn 0 Geft # 0 Bight#len$1 While1left?ri ghtRRmatch ed Af1string]left^' #string]right^- :atched#false true Geft (( Bight $$ Beturn matched Beturn to main program ;, Program/ Linclude?stdio.hM Linclude?string.hM enum HooleanNfalse!trueSO enum Hoolean As=alindrome1char string]^- N int left!right!len#strlen1string-O enum Hoolean matched#trueO if1len##0- return 0O left#0O right#len$1O &6 Compare the first and last letter!second R second last R so on 6& while1left?rightRRmatched- N if1string]left^'#string]right^- matched#falseO else N left((O right$$O S S return matchedO S int main1- N char string])0^O clrscr1-O printf1P6666=rogram to test if the given string is a palindrome6666QnP-O printf1PEnter a string:P-O scanf1P7sP!string-O if1As=alindrome1string-- printf1P.he given string 7s is a palindromeQnP!string-O else printf1P.he given string 7s is not a palindromeQnP!string-O getch1-O return 0O S ;) ,ut1ut/ 1. Enter the string:malaalam .he given string malaalam is a palindrome ". Enter the string:india .he given string india is not a palindrome 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1- What is meant b palindrome @ Ans: Af the reverse of a string&number is equal to original string& number then it is called palindrome. "- What is the use of gets1- function @ Ans: .o read the string at a time ,- What is the use of puts1- function @ Ans: .o write the string at a time ;9 ,b-ecti.e/ 1+ =rogram that displas the position or inde% in the string S where the string . begins ! or $1 if S doesn4t contain . Algorithm/ Step 1: start Step ": read the string and then displaed Step ,: read the string to be searched and then displaed Step ): searching the string . in string S and then perform the following steps i. found#strstr1S!.- ii. if found print the second string is found in the first string at the position. Af not goto step 9 Step 9: print the $1 Step *: stop ;* Start AnitialiIe s] ^!t] ^! found variables Bead first string 0ispla the string Bead string to be searched 0ispla the string Found#strstr1s!t- Af found =rint $1 =rint the string Found$s Stop no es 2lo3 chart/ ;; Program/ Linclude?stdio.hM Linclude?string.hM Linclude?conio.hM void main1- N char s],0^! t]"0^O char 6foundO clrscr1-O &6 Entering the main string 6& puts1PEnter the first string: P-O gets1s-O &6 Entering the string whose position or inde% to be displaed 6& puts1PEnter the string to be searched: P-O gets1t-O &6Searching string t in string s 6& found#strstr1s!t-O if1found- printf1PSecond String is found in the First String at 7d position.QnP!found$s-O else printf1P$1P-O getch1-O S ,ut1ut/ 1.enter the first string: 5ali Enter the string to be seareched: li second string is found in the first string at"position ".enter the first string: nagaraUu Enter the string to be seareched: raUu second string is found in the first string at)position ,.enter the first string: nagarUuna Enter the string to be seareched: ma $1 4oncluion/ .he program is error free ;+ 5I5A 6789ATI,N9/ 1- What is the difference between printf1- and puts1- @ Ans: puts1- is used to displa the string at a time and it doesn4t ta5e an integers values but printf1- ta5es an values as defined b the user "- define pointer variable @ Ans: pointer variables are defined as variable that contain the memor addresses of data or e%ecutable code. ,- What is use of the strcmp1- function @ Ans: .his function compares two strings character b character and returns a value 0 if both strings are equal and non Iero value if the strings are different. ;8 ,b-ecti.e/ 20 .o count the lines!words R charcters in a given te%t 0ecri1tion/ An this program we have to count the no of lines! no of words and no of characters in a given program or given te%t b using the string function Algorithm/ Step 1: Start Step ": Bead the te%t until an empt line Step ,: Compare each character with newline char 3Qn4 to count no of lines Step ): Compare each character with tab char 3QtQ4 or space char 3 3 to count no of words Step 9: Compare first character with CJGG char 3Q04 to find the end of te%t Step *: Co of characters # length of each line of te%t Step ;: =rint no of lines! no of words! no of chars Step +: Stop +0 Start AnitialiIe end#0!chars#0!words#0!lines#0 While End## 0 C # 0 true Af 1ctr#getchar1--' #4Qn4 false Gine]c^#4Q04 Gine]c((^#ctr true Af line]0^#4Q0 4 true Words (( A # 0 A (( line]i^'#4Q0Q false Af line]i^##4 3YY Gine]i^##4Qt4 Gines(( Chars(#strlen1line- Words (( =rint lines! Words!chars stop 2lo3 chart/ +1 Program/ Linclude ?stdio.hM main1- N char line]+1^! ctrO int i!c! end # 0! characters # 0! words # 0! lines # 0O printf1PFEX AC .2E .E_..QnP-O printf1P/ATE KCE S=ACE AF.EB EAC2 WKB0.QnP-O printf1PW2EC CK:=GE.E0! =BESS \BE.JBC\.QnQnP-O while1 end ## 0- N &6 Beading a line of te%t 6& c # 0O while11ctr#getchar1-- '# \Qn\- line]c((^ # ctrO line]c^ # \Q0\O &6 counting the words in a line 6& if1line]0^ ## \Q0\- brea5 O else N words((O for1i#0O line]i^ '# \Q0\Oi((- if1line]i^ ## \ \ YY line]i^ ## \Qt\- words((O S &6 counting lines and characters 6& lines # lines (1O characters # characters ( strlen1line-O S printf 1PQnP-O printf1PCumber of lines # 7dQnP! lines-O printf1PCumber of words # 7dQnP! words-O printf1PCumber of characters # 7dQnP! characters-O S ,ut1ut 1.FEX AC .2E .E_.. /ATE KCE S=ACE AF.EB EAC2 WKB0. W2EC CK:=GE.E0! =BESS \BE.JBC\. Admiration is a ver short$lived passion. Admiration involves a glorious obliquit of vision. Alwas we li5e those who admire us but we do not +" li5e those whom we admire. Fools admire! but men of sense approve. Cumber of lines # 9 Cumber of words # ,* Cumber of characters # "09 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1- What is use of strlen1- @ Ans: to read a string length "- what is the use of getc1- function @ Ans: .o read the character one b one. ,- What is the use of strstr 1- @ Ans: .he function strstr1- searches one string for the occurrence of another.At accepts two strings as parameters and searches the first string for an occurrence of the second +, ,b-ecti.e 21/ .o generate =ascal4s triangle 0ecri1tion/ =ascal4s triangle which is used for a coefficient in the equation in polnominals. Alogrithm/ Step 1: Start Step ": AnitialiIe m#0 Step ,: Bead n Step ): Af m?n goto step 9.if not goto step 1" Step 9: initialiIe i#)0$m Step *: Af iM0 is true do as follows. Af not goto step ; i. print white space ii. decrement i iii. goto Step * Step ;: AnitialiIe U#0 Step +: Af U#m do as follows. Af not goto Step 10 i- if1U##0YYm##0- ii- AnitialiIe b#1 if not b#b61m$U(1-&U iii- =rint white space! b . iv- /oto Step 8 Step 8: increment U! goto Step + Step 10: print new line control Step 11: increment m! goto step ) Step 1": Stop +) 2lo3 chart/ Start Bead p A#0 A ? p A(( true B#)0$A r$$ rM0 =rint white space true _#0 %?#i _(( false true Af %##0 YY A##0 false true H#1 H#b61i$%(1-&% =tint b F =rint newlin e Stop false +9 Program/
Linclude?stdio.hM Linclude?conio.hM void main1- N int i!p!r!%!binom#1O clrscr1-O printf1Penter the how man lines to printP-O scanf1P7dP!Rp-O i#0O while1i?p- && chec5 the condition N for1r#)0$iOrM0Or$$- && perform the looping operation until 0 printf1P P-O for1%#0O%?#iO%((- N if11%##0-YY1i##0-- && chec5 the condition binom#1O else binom#binom61i$%(1-&%O printf1P7dP!binom-O printf1P P-O S printf1PQnP-O i((O S getch1-O S ,ut1ut/ 1.enter the how man lines to print9 1 1 1 1 " 1 1 , , 1 1 ) * ) 1 ".enter the how man lines to print, 1 1 1 1 " 1 4oncluion/ the program is error free +* 5I5A 6789ATI,N9/ 1$ What is meant b =ascal4s triangle @ An/ =ascal4s triangle which is used for a coefficient in the equation in polnominals "-define structure @ Ans: A structure in c is a heterogenous user efined data tpe. A structure ma contain different data tpes.At groups variables into a single entit. +; ,b-ecti.e 22: .o construct a pramid of numbers 0ecri1tion/ An this program the we have to construct output in the pramid shape manner Algorithm/ Step 1: Start Step": initialiIe the num!A!! %#,9 Step,: read the num Step):perform the loop operation For1#0O?#numO((- Step9:/oto%1%!(1- Step*: perform the loop operation for displaing digits towards the left and right For1i#0$Oi?#Oi((- Step;: print abs1i-O Step+: %#%$"O Step8: Stop ++ 2lo3 chart/
Start AnitialiIe num!A!!%#,9 Bead num X # 0 ?#num (( true /oto%1%!(1- A # 0 i(( A?# =rint abs1i- _#%$" Stop +8 Program/ Linclude?stdio.hM Linclude?conio.hM void main1- N int num!i!!%#,9O clrscr1-O printf1PQnEnter the number to generate the pramid:QnP-O scanf1P7dP!Rnum-O for1#0O?#numO((- N &61%$coordinate!$coordinate-6& goto%1%!(1-O &6for displaing digits towards the left and right of Iero6& for1i#0$Oi?#Oi((- printf1P7,dP!abs1i--O %#%$,O S getch1-O S ,ut1ut/
1.enter the number: 0 ) 1 0 1 " 1 0 1 " , " 1 0 1 " , ) , " 1 0 1 " , ) ".enter the number: 0 , 1 0 1 " 1 0 1 " , " 1 0 1 " , 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1- What is the use of dot operator in structures @ Ans: .he use of dot1.- operator to access the members of a structure independentl. .he dot operator connects a member with the structure variable. "- 0efine unions @ Ans: A union is a data tpe in c which allows the overla of more than one variable in the same memor area. 80 ,b-ecti.e 2%/ .o read in two numbers % and n and then compute the sum of this geometric progression 1(%(% "( % , (>>>.(% n 0ecri1tion/ An this program we have to read the two numbers and the calculate the sum of this geometric progression in above mention . Algorithm/ Step 1: Start Step ": read values of % and n! sum$1! i#1 Step ,: chec5 for n R _ i- if n?#0 YY %?#0 ii- print values are not valid iii- read values of % and n Step ): perform the loop operation i- for1i#1Oi?#nOi((- then follows ii- sum#sum(pow1%!i- Step 9: print sum Step *: Stop 81 Start AnitialiIe Sum!A!%!n Bead %!n Af n?#0YY %?#0 =rint not valid A#1 i?#n A(( Sum#sum(pow1%!i- =rint sum Stop false true false Sum # 1 true 2lo3 chart/ 8" Program/ Linclude?stdio.hM Linclude?conio.hM Linclude?math.hM void main1- N int s`sum!i!%!nO clrscr1-O printf1PEnter the values for % and n:P-O scanf1P7d 7dP!R%!Rn-O if1n?#0 YY %?#0- N printf1PTalue is not validQnP-O S else N printf1PTalue is validQnP-O s`sum#1O for1i#1Oi?#nOi((- N s`sum#s`sum(pow1%!i-O S printf1PSum of series#7dQnP!s`sum-O S getch1-O S ,ut1ut/ 1.Enter the values for % and n:" , Talue is valid Sum of series#19 ".Enter the values for % and n:) 8 Talue is valid Sum of series#"1+)9 ,.Enter the values for % and n:0 1 Talue is not valid 4oncluion/ the program is error free 8, 5I5A 6789ATI,N9/ 1- what are the difference between structures and unions @ Ans: 2ere the maUor difference is with in the structure all elements must be allocated memor. Hut in union highest memor allocation must be allocated the all these elements. 8) ,b-ecti.e 2&/ .o convert the given binar number to "4s complement 0ecri1tion/ An this program the given binar number is first covert the numbers 0 to1 and 1 to 0. And finall add the 1 to the converted number. .hen we will get the "4s complement number. Algorithm/ main program Step 1: Start Step ": declare the subprogram Zcomplement1char 6a-[ Step ,: initialiIe the variable i Step ): read the binar number Step 9: perform the loop operation. if it is true then follows. if not goto step ; i- for1i#0Oa]i^'#4Q04Oi((- ii- if1a]i^'#404RRa]i^'#414- then displaed the number is not valid. enter the correct number. iii- E%it the loop Step *: call sub program 3complemt1a-4 Step ;: stop 9ub 1rogram/ Step 1: initialiIe the variable A!c#0!b]1*0 Step ": 1#strlen1a- Step ,: perform the loop operation. if it is true then follows. if not goto i-for1i#l$1OiM#0Oi$$- ii-if1a]i^##404- then b]i^#414 else iii-b]i^#404 Step ): for1i#l$1OiM#0Oi$$- is true i- if1i##l$1- then ii- if1b]i^##404- then b]i^#414 else iii- b]i^#404!c#1 if not goto step 9 Step 9: if1c##1RRb]i^##404- is true then i- b]i^#414! c#0 if not goto Step * Step *: if1c##1RRb]i^##414- then b]i^#404!c#1 Step ;: displaed b]l^#4Q04 Step +: print b and return to main program 89 2lo3 chart/ Start AnitialiIe A! a] ^ Bead a A # 0 i(( A]i^'#4Q04 true Af a]i^' #404RRa]i^'#414 Cumber is not valid true false Call sub program Complement1a- false Stop 8* Complement1 - AnitialiIe !A!c#0!b] ^ 1#strlen1a- A#i$1 A$$ iM#0 true Af a]i^##4 04 H]i^#414 true H]i^#^0^ false A#l$1 i$$ iM#0 true Af i##l$ 1 true Af b]i^##404 H]i^#414 true b]i^#404 C#1 false Af c##1RR
H]i^##404 H]i^#414 C # 0 A H false true C 8; Program/ Linclude ?stdio.hM Linclude?conio.hM void complement 1char 6a-O void main1- N char a]1*^O int iO clrscr1-O printf1PEnter the binar numberP-O gets1a-O for1i#0Oa]i^'#\Q0\O i((- N if 1a]i^'#\0\ RR a]i^'#\1\- N printf1P.he number entered is not a binar number. Enter the correct numberP-O e%it10-O S S complement1a-O getch1-O A Af c##1 RR b]i^##1 H]i^#40^ C#1 true H C H]i^#4Q04 =rint 3b4 Beturn to main program 8+ S void complement 1char 6a- N int l! i! c#0O char b]1*^O l#strlen1a-O for 1i#l$1O iM#0O i$$- N if 1a]i^##\0\- b]i^#\1\O else b]i^#\0\O S for1i#l$1O iM#0O i$$- N if1i##l$1- N if 1b]i^##\0\- b]i^#\1\O else N b]i^#\0\O c#1O S S else N if1c##1 RR b]i^##\0\- N b]i^#\1\O c#0O S else if 1c##1 RR b]i^##\1\- N b]i^#\0\O c#1O S S S b]l^#\Q0\O printf1P.he "\s complement is 7sP! b-O S 88 ,ut1ut/ 1.Enter the binar number101010 .he "\s complement is 010110 Enter the binar number11111 .he "\s complement is 00001 Enter the binar number"""" .he number entered is not a binar number. Enter the correct number 4oncluion/ the program is error free 5I5A 6789ATI,N9/ 1- E%pand ASCAA @ Ans: American standarad code for information interchange "-What is binar number @ Ans: .he number which contains onl 0 and 1 is called binar number. ,- 0efine "[s complement @ Ans: .he given binar number is first covert the numbers 0 to1 and 1 to 0. And finall add the 1 to the converted number. .hen we will get the "4s complement number. 100 ,b-ecti.e 2'/ .o convert roman number to it4s decimal equivalent 0ecri1tion/ An this program we have to ta5e the roman value. .his value is converted into a it4s equivalent decimal number. E%: _#10 Algoritham/ Step 1: Start Step ": read the roman numerical as string Step ,: find length of roman numerical Step ): for each charcter in the string i- if1char#A- then decimal#1 ii- if1char#T- then decimal#9 iii- if1char#_- then decimal#10 iv- if1char#G- then decimal#90 v- if1char#C- then decimal#100 vi- if1char#0- then decimal#900 vii- if1char#:- then decimal#1000 viii- otherwise invalid character Step 9: repeat step ) until the length of the string Step *: 5#char]length$1^ Step ;: for each character of decimal string i- if1decimal]i^Mdec]i$1^- then 5#5$decimal]i$1^ ii- else if1decimal]i^#decimal]i$1 or decimal]i^?decimal]i$1- then 5#5(decimall]i$1^ Step +: repate step ; until the length of decimal string Step 8: print decimal value Step 10: Stop 101 2lo3 chart/ Start Bead roman value Gen#strlen1rom- A#0 i(( A? len Af rom]i^##4A4 A]i^#1 .rue false Af rom]i^##4T4 A]i^#9 true false Af rom]i^##4_4 A]i^#10 true false H C F#a]len$1^ A#len$1 iW A M 0 true A]i^ Ma]i$ 1^ true 5#5$a]i$1^ F A]i^# #a]i$ 1^YY a]i^?a ]i$1^ true 5#5(ai$1^ 10" A H Af rom]i^##4G4 A]i^#90 true false Af rom]i^##4C4 A]i^#100 true false Af rom]i^##404 A]i^#900 true Af rom]i^##4C4 A]i^#1000 false true C =rint invalid A =rint 5 Stop 10, Program/
Linclude?stdio.hM Linclude?conio.hM Linclude?string.hM Linclude?stdlib.hM void main1- N int 6a!len!i!U!5O char 6romO clrscr1-O printf1PEnter the Boman Cumeral:P-O scanf1P7sP!rom-O len#strlen1rom-O for1i#0Oi?lenOi((- && loop will continue until A is not graterthan length. N if1rom]i^##\A\- a]i^#1O else if1rom]i^##\T\- a]i^#9O else if1rom]i^##\_\- a]i^#10O else if1rom]i^##\G\- a]i^#90O else if1rom]i^##\C\- a]i^#100O else if1rom]i^##\0\- a]i^#900O else if1rom]i^##\:\- a]i^#1000O else N printf1PQnAnvalid TalueP-O getch1-O e%it10-O S S 5#a]len$1^O for1i#len$1OiM0Oi$$- && loop will continue until A lessthan Iero 10) N if1a]i^Ma]i$1^- && chec5 the condition 5#5$a]i$1^O else if1a]i^##a]i$1^ YY a]i^?a]i$1^- 5#5(a]i$1^O S printf1PQnAts 0ecimal Equivalent is:P-O printf1P7dP!5-O getch1-O S ,ut1ut/ Enter the Boman Cumeral:0 Ats 0ecimal Equivalent is:900 Enter the Boman Cumeral:_ Ats 0ecimal Equivalent is:10 Enter the Boman Cumeral:", Anvalid Talue 4oncluion/ .he program is error free 5I5A 6789ATI,N9/ 1- What is difference between structure and unions @ Ans : .he amount of memor required to store a structure variable is the sum of siIe all the members in addition to the padding btes that ma be provided b the compiler. An case of a union the amount of memor required is the same as that required b its largest member. "- What are various operations performed on union @ Ans: i-An union variable can be assigned to another union variable ii- A union variable can be passed to a function as a parameter iii- .he address of the union variable can be e%tracted b using the address of operator 1R-. 109 ,b-ecti.e 2(/ .o read the two comple% numbers and perform the addition and multiplication of these two numbers. 0ecri1tion/ An this program the comple% number means it contains the two parts . first one is real part and second one is imaginar part1"(,i-.b ta5ing these two comple% numbers we can perform the addition and multiplication operation. Algorithm/ Step 1: Start Step ": declare structure for comple% numbers Step ,: read the comple% number Step ): read choice Step 9: if choice#1 then addition operation will perform and it contains following steps i- w.realpart # w1.realpart(w".realpartO ii- w.imgpart # w1.imgpart(w".imgpartO goto step ) Step *: if choice#" then multiplication operation will perform and it contains following steps i- w.realpart#1w1.realpart6w".realpart-$1w1.imgpart6w".imgpart-O ii- w.imgpart#1w1.realpart6w".imgpart-(1w1.imgpart6w".realpart-O goto step ) Step ;: if choice#0 then e%it operation will perform Step +:if w.imgpartM0 then print realpart(imgpart else =rint realpart. Step 8: Stop 10* Start 0eclare structure Bead option Af option#1add or mul- true false Bead real part of first number image part of first number Bead real part of second number image part of second number Af option#ad d false w.realpart#w1.realpart(w".realpart w.imgpart#w1.imgpart(w".imgpart Af option#mu l w.realpart#1w1.realpart6w".realpart- w.imgpart#1w1.imgpart6w".imgpart- Af w.imgpartM 0 true =rint w.realpart(w.img part i false =rint real part Stop 2lo3 chart/ 10; Program/ Linclude?stdio.hM Linclude?math.hM void arithmetic1int opern-O struct comp N double realpartO double imgpartO SO void main1- N int opernO clrscr1-O printf1PQnQn QtQtQt66666 :AAC :ECJ 66666P-O printf1PQnQn Select our option: Qn 1 : A00Qn " : :JG.A=GXQn 0 : E_A. QnQnQtQt Enter our Kption ] ^QbQbP-O scanf1P7dP!Ropern-O if1opernM"- N printf1Pinvalid optionP-O S else N switch1opern- N case 0: e%it10-O case 1: case ": arithmetic1opern-O default: main1-O S S getch1-O S void arithmetic1int opern- N struct comp w1! w"! wO printf1PQn Enter two Comple% Cumbers 1%(i-:Qn Beal =art of First Cumber:P-O scanf1P7lfP!Rw1.realpart-O printf1PQn Amaginar =art of First Cumber:P-O scanf1P7lfP!Rw1.imgpart-O printf1PQn Beal =art of Second Cumber:P-O scanf1P7lfP!Rw".realpart-O 10+ printf1PQn Amaginar =art of Second Cumber:P-O scanf1P7lfP!Rw".imgpart-O switch1opern- N &6addition of comple% number6& case 1: w.realpart # w1.realpart(w".realpartO w.imgpart # w1.imgpart(w".imgpartO brea5O &6multiplication of comple% number6& case ": w.realpart#1w1.realpart6w".realpart-$1w1.imgpart6w".imgpart-O w.imgpart#1w1.realpart6w".imgpart-(1w1.imgpart6w".realpart-O brea5O S if 1w.imgpartM0- printf1PQn Answer # 7lf(7lfiP!w.realpart!w.imgpart-O else printf1PQn Answer # 7lf7lfiP!w.realpart!w.imgpart-O getch1-O main1-O S ,ut1ut/ 66666 :AAC :ECJ 66666 Select our option: 1 : A00 " : :JG.A=GX 0 : E_A. Enter our Kption ] 1^ Enter two Comple% Cumbers 1%(i-: Beal =art of First Cumber:" Amaginar =art of First Cumber:" Beal =art of Second Cumber:" Amaginar =art of Second Cumber:" Answer # ).000000().000000i
66666 :AAC :ECJ 66666 108 Select our option: 1 : A00 " : :JG.A=GX 0 : E_A. Enter our Kption ] "^ Enter two Comple% Cumbers 1%(i-: Beal =art of First Cumber:" Amaginar =art of First Cumber:" Beal =art of Second Cumber:" Amaginar =art of Second Cumber:" Answer # 0.000000(+.000000i 66666 :AAC :ECJ 66666 Select our option: 1 : A00 " : :JG.A=GX 0 : E_A. Enter our Kption ] ,^ invalid option 66666 :AAC :ECJ 66666 Select our option: 1 : A00 " : :JG.A=GX 0 : E_A. Enter our Kption ] 0^ 4oncluion/ .he program is error free 5I5A 6789ATI,N9/
1- 0efine structure @ Ans: Structure is amethod for pac5ing data of different tpes. Structure help to organiIe comple% data in a more meaninigful wa. "- What is use of ?math.hM header file @ Ans: At is used to access the mathematical functions in programs. 110 ,b-ecti.e 2)/ =rogram which copies one file to another 0ecri1tion/ An this program we have to use the file functions to perform the cop operation from one file to another file. Algorithm/ Step 1: Start Step ": read command line arguments Step ,: chec5 if no of arguments #, or not. Af not print invalid no of arguments Step ): open source file in read mode Step 9: if CJGG pointer! then print source file can not be open Step *: open destination file in write mode Step ;: if CJGG pointer! then print destination file can not be open Step + : read a character from source file and write to destination file until EKF Step 8: Close source file and destination file Step 10: Stop 111 Start Bead arguments from command line Af arg' #, =rint invalid no of arguments true false Fs#fopen1arg]1^![r[ Af fs#CJG G true =rint source file can not be opened false Ft#fopen1arg]"^![w[ Af ft##CJG G =rint target file can not be opened Fclose1fs- false Ch#fgetc1fs- Af ch##EK F Fclose1fs- Fclose1ft- true false Fputc1ch!ft- Stop 2lo3 chart/ 11" Program/ Linclude ?stdio.hM Linclude ?conio.hM Linclude ?process.hM void main1int argc! char 6argv]^- N FAGE 6fs!6ftO char chO clrscr1-O if1argc'#,- N puts1PAnvalid number of arguments.P-O e%it10-O S fs # fopen1argv]1^!PrP-O if1fs##CJGG- N puts1PSource file cannot be opened.P-O e%it10-O S ft # fopen1argv]"^!PwP-O if 1ft##CJGG- && chec5 the condition if the file pointer is CJGG or not N puts1P.arget file cannot be opened.P-O fclose1fs-O e%it10-O S while11- N ch#fgetc1fs-O if 1ch##EKF- && chec5 the condition if the file is end or not brea5O else fputc1ch!ft-O S fclose1fs-O fclose1ft-O getch1-O S 11, ,ut1ut/ source.c this is source te%t ouput.c Command line arguments source.c ouput.c source.c this is source te%t ouput.c this is source te%t Command line arguments source.c Anvalid number of arguments. 4oncluion/ the program is error free 5I5A 6789ATI,N9/ 1- What is file @ Ans: .he collection of alphabets is called file "- What are the various operations performed on the file @ Ans: fopen1-! fread1-! fwrite1-! fclose1- etc..! ,- What is the use of file pointer @ Ans: .he file pointer must be used in subsequent operations on the file 11) ,b-ecti.e 2*/ .o reverse the first n characters in afile 0ecri1tion/ .his program perform the reverse operation of n characters in the file Algorithm/ Step 1: Star Step ": read the command line arguments Step ,: chec5 if arguments#, or not Af not print invalid no of arguments Step ): open source file in read mode Step 9: if CJGG pointer! then print file can not be open Step *: Store no of chars to reverse in 5 F# 6argv]"^$)+ Step ;: read the item from file stream using fread Step +: Store chars from last position to initial position in another string1temp- Step 8: print the temp string Step 10: Stop 119 Start Bead command line args Af argc' #, false Fp#fopen1argv]1^![r [ =rint invalid no of args Af fp##CJG G =rint file can not be opened true false 5#6argv]"^$)+ n # fread1a!1!5!fp- a]n^#\Q0\ len#strlen1a- A # len$1 iW A M#0 true S]U^#a]i^ =rint s]U^ V(( false S]U(1^#4Q04 Stop 2lo3 chart/ 11* Program/ Linclude ?stdio.hM Linclude ?conio.hM Linclude ?string.hM Linclude ?process.hM void main1int argc! char 6argv]^- N char a]19^O char s]"0^O char nO int 5O int U#0O int iO int lenO FAGE 6fpO if1argc'#,- N puts1PAmproper number of arguments.P-O e%it10-O S fp # fopen1argv]1^!PrP-O if1fp ## CJGG- N puts1PFile cannot be opened.P-O e%it10-O S 5#6argv]"^$)+O n # fread1a!1!5!fp-O a]n^#\Q0\O len#strlen1a-O for1i#len$1OiM#0Oi$$- N s]U^#a]i^O printf1P7cP!s]U^-O U#U(1O S s]U(1^#\Q0\O getch1-O S 11; ,ut1ut/ source.c this is source ouput.c Command line arguments source.c ouput.c source.c this is source ecruos si siht Command line arguments source.c Anvalid number of arguments. 4oncluion/ the program is error free 5I5A 6789ATI,N9/ 1- Gist out the file handling functions @ Ans: fopen1-! fprintf1-!fclose1-!fscanf1-!fgetc1-!fputc1-! etc..! "- What is the use of fsee51- function @ Ans: .he function fsee5 sets the file pointer associated with a stream to a new position ,- What is use of the fflush1- function @ Ans: Af the given stream has a buffered output! fflush writes the output of the stream to the associate file. 11+ ,b-ecti.e 2+/ =rogram that uses functions to perform the following operations on single lin5ed lists. i- creation ii- insertion iii- deletion iv- traversal 0ecri1tion/ An this program we have to create a single lin5ed list! insert the elements into that list !delete the some elements from that list and then perform the sorting operation and traversal operation on that created lin5edlist Algorithm / Step 1: Start Step ": 0eclare a structure named lin5ed$list Step ,: 0eclare the pointers ne%t! first! fresh! ptr Step ): =rint main menu Step 9: Bead choice Step *: Switch1choice- Step ;: Af1choice##1- ;.1 Assign fresh#malloc1siIe of 1node-- ;." Bead the element fresh$Mdata ;., Bead the choice where to insert ;.):Switch1choice- ;.).1: Af choice##1 ;..).": Call the function AHegin1- ;.).,: Af choice##" ;.).): Call the function Aend1- ;.).9: Af choice##, ;.).*: Call the function Amiddle1- Step +: Af1choice##"- +.1: Bead the position to delete +.": Switch1choice- +.".1: Af choice##1 +..".": Call the function 0Hegin1- +.".,: Af choice##" +.".): Call the function 0end1- +.".9: Af choice##, +.".*: Call the function 0middle1- Step 8: Af choice##, 8.1 Call function view 118 Step 10: Af choice##) 10.1 E%it1- Step 11: Start insert function Step 1": Af1first##null- Step 1,: First$Mdata#e Step 1): First$Mne%t#null Step 19: Else declare new node Step 1*:fresh$Mdata#e Step 1;: Af choice#1 Step 1+: frsh$Mne%t#first Step 18: first#fresh Step "0:if choice#" Step "1: ptr#first Step "": ptr$Mne%t#fresh Step ",: fresh$Mne%t#full Step "): Af choice #, Step "9: Enter the position Step "*:at p$1 node Step ";: fresh$Mne%t# ptr$Mne%t Step "+: ptr$Mne%t#fresh Step "8: for delete function Step ,0: Af first'#null Step ,1: Enter the position to delete Step ,": Af choice#1 1"0 Step ,,: d#first$Mdata Step ,): first#first$Mne%t Step ,9: if choice#" Step ,*: ptr#first Step ,;: .raverse to last node Step ,+: d#ptr$Mne%t$Mdata Step ,8: ptr $Mne%t#ptr$Mne%t$Mne%t Step )0: =rint d value Step )1: for function view Step )": for ptr#first and ptr'#null and ptr#ptr$Mne%t Step ),: =rint ptr$Mdata Step )): End 1"1 2lo3chart/ 1"" Program/
L include?stdio.hM L include?malloc.hM int ch!i!n!U!p!itemO &6 TABAAHGE 0ECGABA.AKC 6& &6 S.AB. KF S.BJC.JBE 0EFACA.AKC 6& struct lin5 N int dataO struct lin5 6ne%tO S6start!6new!6l!6l1!6start1!6tO &6 EC0 KF S.BJC.JBE 0EFACA.AKC 6& &6 S.AB. KF :AAC FJCC.AKC 6& main1- N clrscr1-O start#CJGGO start1#CJGGO printf1P 6666 :ECJ 6666 P-O printf1PQn 1.AnsertionQn ".0eletionQn ,..raverseQn ).SearchQn 9.SortQn *.:ergeQn ;.BeverseQnP-O while11- N printf1Penter the choice:P-O scanf1P7dP!Rch-O switch1ch- N case 1: insert1-O brea5O case ": delete1-O brea5O case ,: traverse1-O brea5O case ): search1-O brea5O case 9: sort1-O brea5O case *: merge1-O brea5O case ;: reverse1-O 1", brea5O case +:e%it1-O S S getch1-O S &6 EC0 KF :AAC FJCC.AKC 6& &6 S.AB. KF ACSEB. FJCC.AKC 6& insert1- N l#startO printf1Penter the item to be inserted:P-O scanf1P7dP!Ritem-O new#malloc1siIeof1struct lin5--O new$Mdata#itemO if1start##CJGG- N new$Mne%t#CJGGO start#newO S else N printf1P1.startQn".middleQn,.endQnP-O printf1Penter the place to place the item:P-O scanf1P7dP!Rch-O if1ch##1- N new$Mne%t#startO start#newO S if1ch##"- N printf1Penter the position to place item:P-O scanf1P7dP!Rp-O for1i#1Oi?p$1Oi((- l#l$Mne%tO new$Mne%t#l$Mne%tO l$Mne%t#newO S if1ch##,- N while1l$Mne%t'#CJGG- l#l$Mne%tO 1") new$Mne%t#CJGGO l$Mne%t#newO S S S &6 EC0 KF ACSEB. FJCC.AKC 6& &6 S.AB. KF 0AS=GAX FJCC.AKC 6& traverse1- N if1start##CJGG- printf1PGAS. AS E:=.XQnP-O else N for1l#startOl$Mne%t'#CJGGOl#l$Mne%t- if1l##start- printf1PQnstart:7d$MP!l$Mdata-O else printf1PQn7;d$MP!l$Mdata-O if1l$Mne%t##CJGG- printf1PQn last:7d$MQnP!l$Mdata-O S S &6 EC0 KF 0AS=GAX FJCC.AKC 6& &6 S.AB. KF 0EGE.E FJCC.AKC 6& delete1- N l#startO if1start##CJGG- printf1PCK A.E:S AC .2E GAS.QnP-O else N printf1P1.startQn".middleQn,.endQnP-O printf1Penter the place to delete the item:P-O scanf1P7dP!Rch-O if1ch##1- N item#start$MdataO printf1Pdeleted item is:7dQnP!item-O start#start$Mne%tO S if1ch##"- 1"9 N printf1Penter the position to delete item:P-O scanf1P7dP!Rp-O if1l$Mne%t##CJGG- N item#l$MdataO printf1Pdeleted item is:7dQnP!item-O l#start#CJGGO S else N for1i#1Oi?p$1Oi((- l#l$Mne%tO item#l$Mne%t$MdataO printf1Pdeleted item is:7dQnP!item-O l$Mne%t#l$Mne%t$Mne%tO S S if1ch##,- N if1l$Mne%t##CJGG- N item#l$MdataO printf1Pdeleted item is:7dQnP!item-O l#start#CJGGO S else N while1l$Mne%t$Mne%t'#CJGG- l#l$Mne%tO item#l$Mne%t$MdataO printf1Pdeleted item is:7dQnP!item-O l$Mne%t#CJGGO l#l$Mne%tO S S S S &6 EC0 KF 0EGE.E FJCC.AKC 6& &6 S.AB. KF SEABC2 FJCC.AKC 6& search1- N int f#0O 1"* printf1Penter the search item:P-O scanf1P7dP!Ritem-O if1start##CJGG- printf1PGAS. AS E:=.XP-O else N for1l#start!i#1Ol'#CJGGOl#l$Mne%t!i((- if1l$Mdata##item- N f#1O brea5O S if1f##1- printf1Pitem 7d found at position :7dQnP!item!i-O else printf1Pitem 7d not foundQnP!item-O S S &6 EC0 KF SEABC2 FJCC.AKC 6& &6 S.AB. KF SKB. FJCC.AKC 6& sort1- N int tO if1start##CJGG- printf1PGAS. AS E:=.XP-O else N for1l1#startOl1$Mne%t'#CJGGOl1#l1$Mne%t- N for1l#startOl$Mne%t'#CJGGOl#l$Mne%t- if1l$Mdata M l$Mne%t$Mdata- N t#l$MdataO l$Mdata#l$Mne%t$MdataO l$Mne%t$Mdata#tO S S printf1P.2E SKB.E0 KB0EB AS:P-O for1l#startOl'#CJGGOl#l$Mne%t- printf1P7,dP!l$Mdata-O S printf1PQnP-O S 1"; &6 EC0 KF SKB. FJCC.AKC 6& &6 S.AB. KF :EB/E FJCC.AKC 6& merge1- N printf1Penter no of elements to be inserted in second list :P-O scanf1P7dP!Rn-O for1U#1OU?#nOU((- N l1#start1O printf1Penter the item to be inserted:P-O scanf1P7dP!Ritem-O new#malloc1siIeof1struct lin5--O new$Mdata#itemO new$Mne%t#CJGGO if1start1##CJGG- start1#newO else N printf1P1.startQn".middleQn,.endQnP-O printf1Penter the place to place the item:P-O scanf1P7dP!Rch-O if1ch##1- N new$Mne%t#start1O start1#newO S if1ch##"- N printf1Penter the position to place item:P-O scanf1P7dP!Rp-O for1i#1Oi?p$1Oi((- l1#l1$Mne%tO new$Mne%t#l1$Mne%tO l1$Mne%t#newO S if1ch##,- N while1l1$Mne%t'#CJGG- l1#l1$Mne%tO l1$Mne%t#newO S S S 1"+ if1start##CJGG- start#start1O else N l#startO while1l$Mne%t'#CJGG- l#l$Mne%tO for1l1#start1Ol1$Mne%t'#CJGGOl1#l1$Mne%t- N l$Mne%t#l1O l#l$Mne%tO S S printf1P 666 GAS. AS :EB/E0 666 QnP-O S &6 EC0 KF :EB/E FJCC.AKC 6& &6 S.AB. KF BETEBSE FJCC.AKC 6& reverse1- N if1start##CJGG- printf1PGAS. AS E:=.XQnP-O else N l#startO l1#t#CJGGO while1l'#CJGG- N l1#tO t#lO l#l$Mne%tO t$Mne%t#l1O S start#tO printf1P 666 GAS. AS BETEBSE0 666QnP-O S S &6 EC0 KF BETEBSE FJCC.AKC 6& 66666 KJ.=J. 66666 6666 :ECJ 6666 1.Ansertion 1"8 ".0eletion ,..raverse ).Search 9.Sort *.:erge ;.Beverse enter the choice:1 enter the item to be inserted:1 enter the choice:1 enter the item to be inserted:" 1.start ".middle ,.end enter the place to place the item:1 enter the choice:1 enter the item to be inserted:, 1.start ".middle ,.end enter the place to place the item:, enter the choice:1 enter the item to be inserted:) 1.start ".middle ,.end enter the place to place the item:" enter the position to place item:, enter the choice:, start:"$M 1$M )$M last:,$M enter the choice:) enter the search item:) item ) found at position :, enter the choice:* enter no of elements to be inserted in second list :, enter the item to be inserted:9 enter the item to be inserted:* 1.start ".middle ,.end enter the place to place the item:1 enter the item to be inserted:; 1.start 1,0 ".middle ,.end enter the place to place the item:" enter the position to place item:" 666 GAS. AS :EB/E0 666 enter the choice:, start:"$M 1$M )$M ,$M *$M ;$M last:9$M enter the choice:; 666 GAS. AS BETEBSE0 666 enter the choice:, start:9$M ;$M *$M ,$M )$M 1$M last:"$M enter the choice:) enter the search item:1 item 1 found at position :* enter the choice:9 .2E SKB.E0 KB0EB AS: 1 " , ) 9 * ; enter the choice:" 1.start ".middle ,.end enter the place to delete the item:1 deleted item is:1 enter the choice:" 1.start ".middle ,.end enter the place to delete the item:, deleted item is:; enter the choice:" 1.start ".middle ,.end 1,1 enter the place to delete the item:" enter the position to delete item:) deleted item is:9 enter the choice:, start:"$M ,$M )$M last:*$M enter the choice:" 1.start ".middle ,.end enter the place to delete the item:1 deleted item is:" enter the choice:" 1.start ".middle ,.end enter the place to delete the item:" enter the position to delete item:" deleted item is:) enter the choice:, start:,$M last:*$M enter the choice:" 1.start ".middle ,.end enter the place to delete the item:" enter the position to delete item:" deleted item is:* enter the choice:" 1.start ".middle ,.end enter the place to delete the item:1 deleted item is:, enter the choice:, GAS. AS E:=.X enter the choice:" CK A.E:S AC .2E GAS. enter the choice:+ concluion/ the program is error free 5I5A 6789ATI,N9/ 1," 1- Gist out the memor allocation functions @ Ans: malloc1-! calloc1-!free1-! realloc1- etc..! "- 0efine lin5ed list @ Ans: Gin5ed list is list whose order is given b lin5s from one item to the ne%t ,- Gist out the advantages of lin5ed list @ An/ i- 0anamic data structure ii- no waste memor space iii- fle%ibilit 1,, ,b-ecti.e %0/ =rogram that uses functions to perform the following operations on doubl lin5ed list i- creation ii- insertion iii- deletion iv- traversal 0ecri1tion / An this program we have to create a doubl lin5ed list! insert the elements in to a doubl lin5ed list! delete the elements from that list and finall perform the traversal operation AL>,!IT;M / Step 1: Start Step ": 0eclare a structure with 6ne%t! 6pre Step ,: 0eclare 6start! 6new !6l as structure pointers Step ): =rint main menu Step 9: Bead choice Step *: Switch choice *.1: call insert function if choice##1 *.": call delete function if choice##" *.,: call view function if choice##, Step ;: Stop Step +: Start of insert function Step 8: Bead e Step 10: Af start##null Step 11: Create a new node Step 1": Start$Mdata#e Step 1,: Start$Mne%t#null Step 1): Start$Mpre#null Step 19: read choice! where to insert Step 1*: if choice##1
Step 1*.1: Create a new mode
Step 1*.": new $M data#e 1,)
Step 1*.,: new $M ne%t#start Step 1*.): start$Mpre#new Step 1*.9: new$Mpre#null Step 1*.*: Start$Mnew Step 1;: otherwise if choice##" 1;.1: read position p 1;.": l#start 1;.,: while i?1p$1- 1;.): incrent i 1;.9: l#l$Mne%t 1;.*: new $M data #e 1;.;: new $M pre#l 1;.+: new$Mne%t#new 1;.8: l$M ne%t#new 1;.10: l$Mne%t$Mpre#new Step 1+: if choice##, 1+.1: l#start 1+.": while l$Mne%t'#null 1+.,: l#l$Mne%t 1+.): create a new mode 1+.9: new$Mdata#e 1+.*: new$Mne%t#null 1+.;: l$Mne%t#new 1,9 1+.+: new$Mpre#l Step18: end of insert function Step"0: start of deletion function Step"1: write menu Step"": read choice Step",: if choice##1 ",.1: temp#start$Mdata ",.": start#start$Mne%t ",.,: start$Mpre#null Step"): if choice##" ").1: read position ").": l#start ").,: while 1i#1 ?p$1- ").): l#l$Mne%t ").9: increment A b 1 ").*: temp#l$ne%t$Mdata ").;: l$Mne%t#l$Mne%t$Mne%t ").+: l$Mne%t$Mpre#l Step"9: if choice##, "9.1: read l#start "9.": while l$Mne%t$Mne%t'# null "9.,: l#l$Mne%t "9.): temp#l$Mne%t$Mdata 1,* "9.9: l$Mne%t#null Step"*: end of delete function Step";: start of view function Step"+: read choice Step"8: if choice##1 "8.1: l#ne%t "8.": while 1l$Mne%t'# null- "8.,: write l$M data! l#l$Mne%t "8.): write l$Mdata Step,0: if choice##" ,0.1: l#start ,0.": while l'#start ,0.,: write l$Mdata ,0.): l#l$Mpre ,0.9: write l$Mdata Step,1: end of function view 2lo3chart/ 1,; Program/ 1,+ Linclude?stdio.hM Linclude?malloc.hM &6 S.AB. KF S.BJC.JBE 0EFACA.AKC 6& struct lin5 N int dataO struct lin5 6ne%tO struct lin5 6prevO S6start!6new!6temp!6l!6l1!6t!6start1O &6 EC0 KF S.BJC.JBE 0EFACA.AKC 6& int item!ch!i!U!p!nO &6 TABAAHGE 0ECGABA.AKC 6& &6 S.AB. KF :AAC FJCC.AKC 6& main1- N start#CJGGO start1#CJGGO clrscr1-O printf1P 6666 :ECJ 6666P-O printf1PQn1.AnsertionQn".0eletionQn,..raverseQn).searchQn9.sortQn*.mergeQn ;.reverseQn+.e%itQnP-O while11- N printf1Penter our choice:P-O scanf1P7dP!Rch-O switch1ch- N case 1:insert1-O brea5O case ":delete1-O brea5O case ,:displa1-O brea5O case ):search1-O brea5O case 9:sort1-O brea5O 1,8 case *:merge1-O brea5O case ;:reverse1-O brea5O case +:e%it1-O S S getch1-O S &6 EC0 KF :AAC FJCC.AKC 6& &6 S.AB. KF ACSEB. FJCC.AKC 6& insert1- N l#startO printf1Penter an item to be inserted:P-O scanf1P7dP!Ritem-O new#malloc1siIeof1struct lin5--O new$Mdata#itemO if1start##CJGG- N new$Mprev#CJGGO new$Mne%t#CJGGO start#newO S else N printf1P1.startQn".middleQn,.endQnP-O printf1Penter the place to insert item:P-O scanf1P7dP!Rch-O if1ch##1- N new$Mne%t#startO new$Mprev#CJGGO start#newO S if1ch##"- N printf1Penter the position to place item:P-O scanf1P7dP!Rp-O for1i#1Oi?p$1Oi((- l#l$Mne%tO new$Mprev#lO 1)0 new$Mne%t#l$Mne%tO l$Mne%t#newO S if1ch##,- N while1l$Mne%t'#CJGG- l#l$Mne%tO new$Mprev#lO new$Mne%t#CJGGO l$Mne%t#newO S S S &6 EC0 KF ACSEB. FJCC.AKC 6& &6 S.AB. KF 0EGE.E FJCC.AKC 6& delete1- N l#startO if1start##CJGG- printf1P666 GAS. AS E:=.X 666P-O else N printf1P1.startQn".middleQn,.endP-O printf1Penter the place to delete the item:P-O scanf1P7dP!Rch-O if1ch##1- N item#start$MdataO printf1Pdeleted item is :7dP!item-O start#start$Mne%tO start$Mprev#CJGGO S if1ch##"- N printf1Penter the position to delete an item:P-O scanf1P7dP!Rp-O if1l$Mne%t##CJGG- N item#l$MdataO printf1Pdeleted item is:7dP!item-O l#start#CJGGO S else 1)1 N for1i#1Oi?p$1Oi((- l#l$Mne%tO item#l$Mne%t$MdataO printf1Pdeleted item is:7dP!item-O l$Mne%t#l$Mne%t$Mne%tO l$Mne%t$Mprev#lO S S if1ch##,- N if1l$Mne%t##CJGG- N item#l$MdataO printf1Pdeleted item is :7dP!item-O l$Mprev#CJGGO l#start#CJGGO S else N while1l$Mne%t$Mne%t'#CJGG- l#l$Mne%tO item#l$Mne%t$MdataO printf1Pdeleted item is:7dP!item-O l$Mne%t#CJGGO S S S S &6 EC0 KF 0EGE.E FJCC.AKC 6& &6 S.AB. KF 0AS=GAX FJCC.AKC 6& displa1- N if1start##CJGG- printf1P666 GAS. AS E:=.X 666QnP-O else N for1l#startOl$Mne%t'#CJGGOl#l$Mne%t- if1l##start- printf1PQnstart:7dP!l$Mdata-O else printf1PQn 7+dP!l$Mdata-O if1l$Mne%t##CJGG- printf1PQn last:7dP!l$Mdata-O 1)" S S &6 EC0 KF 0AS=GAX FJCC.AKC 6& &6 S.AB. KF SEABC2 FJCC.AKC 6& search1- N int f#0O if1start##CJGG- printf1P 666 GAS. AS E:=.X 666 P-O else N printf1Penter the search item:P-O scanf1P7dP!Ritem-O for1l#start!i#1Ol'#CJGGOl#l$Mne%t!i((- if1item##l$Mdata- N f#1O brea5O S if1f##1- printf1Pitem 7d found at position 7dP!item!i-O else printf1Pitem 7d not found in listP!item-O S S &6 EC0 KF SEABC2 FJCC.AKC 6& &6 S.AB. KF SKB. FJCC.AKC 6& sort1- N int tO if1start##CJGG- printf1P 666 GAS. AS E:=.X 666 P-O else N for1l1#startOl1$Mne%t'#CJGGOl1#l1$Mne%t- for1l#startOl$Mne%t'#CJGGOl#l$Mne%t- if1l$Mdata M l$Mne%t$Mdata- N t#l$Mne%t$MdataO l$Mne%t$Mdata#l$MdataO l$Mdata#tO 1), S printf1P.2E SKB.E0 KB0EB AS:P-O for1l#startOl'#CJGGOl#l$Mne%t- printf1P7,dP!l$Mdata-O S printf1PQnP-O S &6 EC0 KF SKB. FJCC.AKC 6& &6 S.AB. KF :EB/E FJCC.AKC 6& merge1- N printf1Penter number items to be inserted in second list:P-O scanf1P7dP!Rn-O for1U#1OU?#nOU((- N l1#start1O printf1Penter an item:P-O scanf1P7dP!Ritem-O new#malloc1siIeof1struct lin5--O new$Mdata#itemO if1start1##CJGG- N new$Mprev#CJGGO new$Mne%t#CJGGO start1#newO S else N printf1P1.startQn".middleQn,.endQnP-O printf1Penter the place to insert item:P-O scanf1P7dP!Rch-O if1ch##1- N new$Mne%t#start1O new$Mprev#CJGGO start1#newO S if1ch##"- N printf1Penter the position to place item:P-O scanf1P7dP!Rp-O for1i#1Oi?p$1Oi((- 1)) l1#l1$Mne%tO new$Mprev#l1O new$Mne%t#l1$Mne%tO l1$Mne%t#newO S if1ch##,- N while1l1$Mne%t'#CJGG- l1#l1$Mne%tO new$Mprev#l1O new$Mne%t#CJGGO l1$Mne%t#newO S S S if1start##CJGG- start#start1O else N l#startO while1l$Mne%t'#CJGG- l#l$Mne%tO for1l1#start1Ol1$Mne%t'#CJGGOl1#l1$Mne%t- N l$Mne%t#l1O l#l$Mne%tO S S printf1P 666 GAS. AS :EB/E0 666 QnP-O S &6 EC0 KF :EB/E FJCC.AKC 6& &6 S.AB. KF BETEBSE FJCC.AKC 6& reverse1- N if1start##CJGG- printf1P 666 GAS. AS E:=.X 666Qn P-O else N l#startO l1#t#CJGGO while1l'#CJGG- N l1#tO 1)9 t#lO l#l$Mne%tO t$Mne%t#l1O S start#tO printf1P 666 GAS. AS BETEBSE0 666 QnP-O S S &6 EC0 KF BETEBSE FJCC.AKC 6& In1ut=,ut1ut/ 6666 :ECJ 6666 1.Ansertion ".0eletion ,..raverse ).search 9.sort *.merge ;.reverse +.e%it enter our choice:1 enter an item to be inserted:10 enter our choice:1 enter an item to be inserted:"0 1.start ".middle ,.end enter the place to insert item:1 enter our choice:1 enter an item to be inserted:,0 1.start ".middle ,.end enter the place to insert item:, enter our choice:1 enter an item to be inserted:)0 1.start ".middle ,.end 1)* enter the place to insert item:" enter the position to place item:, enter our choice:1 enter an item to be inserted:90 1.start ".middle ,.end enter the place to insert item:" enter the position to place item:" enter our choice:, start: "0 90 10 )0 last: ,0 enter our choice:* enter number items to be inserted in second list:, enter an item:*0 enter an item:;0 1.start ".middle ,.end enter the place to insert item:, enter an item:+0 1.start ".middle ,.end enter the place to insert item:1 666 GAS. AS :EB/E0 666 enter our choice:, start:"0 90 10 )0 ,0 +0 *0 last:;0 enter our choice:) enter the search item:+0 1); item +0 found at position * enter our choice:) enter the search item:10 item 10 found at position , enter our choice:; 666 GAS. AS BETEBSE0 666 enter our choice:, start:;0 *0 +0 ,0 )0 10 90 last: "0 enter our choice:9 .2E SKB.E0 KB0EB AS: 10 "0 ,0 )0 90 *0 ;0 +0 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:1 deleted item is :10 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:, deleted item is:+0 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:" enter the position to delete an item:, deleted item is:)0 enter our choice:, start:"0 ,0 90 *0 last: ;0 enter our choice:" 1.start ".middle 1)+ ,.end enter the place to delete the item:" enter the position to delete an item:) deleted item is:*0 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:) enter our choice:, start:"0 ,0 90 last: ;0 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:" enter the position to delete an item:, deleted item is:90 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:" enter the position to delete an item:, deleted item is:90 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:" enter the position to delete an item:1 deleted item is:,0 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:1 deleted item is :"0 enter our choice:, 1)8 last:;0 enter our choice:" 1.start ".middle ,.end enter the place to delete the item:1 deleted item is :;0 enter our choice:, 666 GAS. AS E:=.X 666 enter our choice:" 666 GAS. AS E:=.X 666 enter our choice:+ concluion/ the program is error free 5I5A 6789ATI,N9/ 1$ Gist out the pes of lin5ed lists @ Ans: i- circular lin5ed lists ii- doubl lin5ed lists! iii- circular doubl lin5ed list "- What are the various operations performed on the lin5ed lists @ Ans: i- creating a list! ii- traversing the list iii- inserting an item etc..! ,- Another name for doubl lin5ed list @ Ans: two$wa lin5ed list. ,b-ecti.e %1/ 190 =rogram that implement stac5 and its operation b using the arras 0ecri1tion: An this program we have to implement the stac5 operation b using the arras. 2ere the stac5 operation are push and pop. =ush operation is used to insert the elements into a stac5 and pop operation is used to remove the elements in to a stac5 AL>,!IT;M 2,! IN98!TIN> AN 8L8M8NT IN A 9TA4?/ Function =ush1s!top!%- Step 1: ]Chec5 for stac5 overflow^ Af topM#n .hen printf1Zstac5 overflow[- Beturn Step ": ]Ancrement .op^ .op?$top(1 Step ,: ] Ansert element^ S]top^?$% Step ):]finished^ Beturn AL>,!IT;M 2,! 08L8TIN> AN 8L8M8NT 2!,M A 9TA4?/ Function =K=1s!top- Step 1: ]Chec5 for stac5 underflow^ Af top#0 .hen printf1Zstac5 underflow[- E%it Step ": ]0ecrement .op^ .op?$top$1 Step ,: ]Beturn former top element of stac5wwwww^ Beturn1S]top(1^- Step ):]finished^ Beturn 2lo3chart/ 191 Program/ 19" L include ?stdio.hM L define siIe ) int choice!top#0!a]siIe^!itemO main1- N clrscr1-O while11- N printf1P 666 :ECJ 666Qn 1. =JS2Qn ". =K=Qn ,. .BATEBSEQn ). E_A.QnP-O printf1Penter our choice from menu:P-O scanf1P7dP!Rchoice-O switch1choice- N case 1:push1-O brea5O case ":pop1-O brea5O case ,:traverse1-O brea5O case ):e%it1-O default:printf1Pwrong choiceQnP-O S S getch1-O S push1- N if1siIe##top- printf1P666 stac5 is full 666QnP-O else N printf1Penter the item to be pushed into the stac5:P-O scanf1P7dP!Ritem-O top((O a]top^#itemO S S pop1- N if1top##0- printf1P666 stac5 is empt 666QnP-O else N 19, item#a]top^O top$$O printf1Pthe deleted item from stac5 is 7dQnP!item-O S S traverse1- N int iO if1top##0- printf1P6666 stac5 is empt 6666P-O else N printf1P666 stac5 displa 666QnP-O for1i#1Oi?#topOi((- if1i##top- printf1P7d at 7d $MtopQnP!a]i^!i-O else printf1P7d at 7dQnP!a]i^!i-O S S In1ut=,ut1ut/ 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:1 enter the item to be pushed into the stac5:11 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:1 enter the item to be pushed into the stac5:1" 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:1 enter the item to be pushed into the stac5:1, 666 :ECJ 666 1. =JS2 19) ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:1 enter the item to be pushed into the stac5:1) 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:1 666 stac5 is full 666 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:, 666 stac5 displa 666 11 at 1 1" at " 1, at , 1) at ) $Mtop 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:" the deleted item from stac5 is 1) 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:" the deleted item from stac5 is 1, 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:" the deleted item from stac5 is 1" 666 :ECJ 666 199 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:" the deleted item from stac5 is 11 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:" 666 stac5 is empt 666 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:, 6666 stac5 is empt 6666 666 :ECJ 666 1. =JS2 ". =K= ,. .BATEBSE ). E_A. enter our choice from menu:) concluion/ the program is error free 5I5A 6789ATI,N9/ 1$ 0efine Stac5 @ Ans: A stac5 is a linear data structure in which a data item is inserted and deleted at one end "- 0efine data structure @ An/ A data structure is a collection of organiIed data that are related to each other %$ What are the various operation performed on the stac5 @ Ans: push1-! pop1- ,b-ecti.e %2/ 19* =rogram that implement stac5 operations b using the pointers. 0ecri1tion/ An this program we have to implement the stac5 operation b using the pointers. 2ere the stac5 operation are push and pop. =ush operation is used to insert the elements into a stac5 and pop operation is used to remove the elements in to a stac5. Algorithm/ Step 1: Start Step ": 0eclare the structure for the stac5 pointers. Step ,: 0efine the push function Step ): 0efine the pop function Step 9: 0efine the displa function Step *: Bead the choice Step ;: if choice # push Create a cell for the .K= cell in the stac5. =lace the date in the .K= cell =lace the .K= pointer to the new cell Step +: if choice#pop Chec5 if empt stac5. Af so! print stac5 is empt. Ktherwise! remove the .K= cell. Step 8: if choice#displa 0ispla all the elements in the Stac5. Step 10: Stop 19;
=JS21 - Bead element!st`point er :#1struct st`point6-malloc1siIeof1struct st`point-- : $Melec#U : $M l#t .#m Beturn to main program =op 1 - Af t#CJGG A # t$Mele . #t $M l Beturn i =rint stac5 is empt Beturn to main program F . 198
Program/ Linclude?stdio.hM Linclude?conio.hM struct st`point N int eleO struct st`point 6lO S 6tO int iO 0ispla 1 - 0efine st`point 6 pointer# CJGG =ointer # t While1pointer' # CJGG- =rint the element =ointer#pointer$M1 Beturn to main program true 1*0 void push`ele1int U-O int pop`ele1-O void displa`ele1-O void main1- N char choice!num1#0!num"#0O int iO while11- N clrscr1-O printf1P######################################P-O printf1PQnQtQt :ECJ P-O printf1PQn######################################P-O printf1PQn]1^ Jsing =ush FunctionP-O printf1PQn]"^ Jsing =op FunctionP-O printf1PQn],^ Elements present in Stac5P-O printf1PQn])^ E%itQnP-O printf1PQnQtEnter our choice: P-O fflush1stdin-O scanf1P7cP!Rchoice-O switch1choice$\0\- N case 1: N printf1PQnQtElement to be pushed:P-O scanf1P7dP!Rnum1-O push`ele1num1-O brea5O S case ": N num"#pop`ele11-O printf1PQnQtElement to be popped: 7dQnQtP!num"-O getch1-O brea5O S case ,: N printf1PQnQtElements present in the stac5 are:QnQtP-O displa`ele1-O getch1-O 1*1 brea5O S case ): e%it11-O brea5O default: printf1PQnXour choice is invalid.QnP-O brea5O S S S &6Anserting the elements using push function6& void push`ele1int U- N struct st`point 6mO m#1struct st`point6-malloc1siIeof1struct st`point--O m$Mele#UO m$Ml#tO t#mO returnO S &6Bemoving the elements using pop function6& int pop`ele1- N if1t##CJGG- N printf1PQnQS.ACF is Empt.P-O getch1-O e%it11-O S else N int i#t$MeleO t#t$MlO return 1i-O S return 0O S &60isplaing the elements 6& void displa`ele1- N struct st`point 6pointer#CJGGO 1*" pointer#tO while1pointer'#CJGG- N printf1P7dQtP!pointer$Mele-O pointer#pointer$MlO S S Kutput: ###################################### :ECJ ###################################### ]1^ Jsing =ush Function ]"^ Jsing =op Function ],^ Elements present in Stac5 ])^ E%it Enter our choice: 1 Element to be pushed:", ###################################### :ECJ ###################################### ]1^ Jsing =ush Function ]"^ Jsing =op Function ],^ Elements present in Stac5 ])^ E%it Enter our choice: , Elements present in the stac5 are: ", ###################################### :ECJ ###################################### ]1^ Jsing =ush Function ]"^ Jsing =op Function ],^ Elements present in Stac5 ])^ E%it Enter our choice: " Element to be popped: ", 1*, ###################################### :ECJ ###################################### ]1^ Jsing =ush Function ]"^ Jsing =op Function ],^ Elements present in Stac5 ])^ E%it Enter our choice: ) E%it the program 5I5A 6789ATI,N9/ 1$ 0efine Stac5 @ Ans: A stac5 is a linear data structure in which a data item is inserted and deleted at one end "- 0efine data structure @ An/ A data structure is a collection of organiIed data that are related to each other %$ What are the various operation performed on the stac5 @ Ans: push1-! pop1- 1*) ,b-ecti.e %%/ =rogram that implement Dueue operation b using the arras 0ecri1tion/ An this program we have to implement the Dueue operation b using the arras. 2ere the Dueue operation are push and pop. =ush operation is used to insert the elements into a Dueue and pop operation is used to remove the elements in to a Dueue. AL>,!IT;M 2,! IN98!TIN> AN 8L8M8NT IN T, A 67878/ Function DACSEBE.1D!F!B!C!X- Step 1: ]overflow^ Af BM#C .hen printf1Z overflow[- Beturn Step ": ]Ancrement rear pointer^ B?$B(1 Step ,: ] Ansert element^ D]B^?$ Step ): ]As front pointer properl set@^ Af F#0 .hen f?$1 Beturn AL>,!IT;M 2,! 08L8TIN> AN 8L8M8NT 2!,M A 9TA4?/ Function D0EGE.E1D!F!B- Step 1: ]Jnderflow^ Af F#0 .hen printf1ZDueue underflow[- Beturn10- Step ": ]0elete element^ ?$q]f^ Step ,: ]As Dueue Empt@^ Af F#B .hen F#B#0 Else F#F(1 Step ):]Beturn element^ Beturn1r- 1*9 2lo3chart/ 1** Program/ L include ?stdio.hM L define siIe ) int front#0!rear#$1!item!choice!a]siIe^O main1- N clrscr1-O while11- N printf1P666 :ECJ 666Qn 1. ACSEB.AKCQn ". 0EGE.AKCQn ,..BATEBSEQn ). E_A.QnP-O printf1Penter our choice:P-O scanf1P7dP!Rchoice-O switch1choice- N case 1:insertion1-O brea5O case ":deletion1-O brea5O case ,:traverse1-O brea5O case ):e%it1-O default:printf1P666 wrong choice 666QnP-O S S getch1-O S insertion1- N if1rear##siIe$1- printf1P666 queue is full 666QnP-O else N printf1Penter item into queue:P-O scanf1P7dP!Ritem-O rear((O a]rear^#itemO S S deletion1- N if1front##rear(1- printf1P666 queue is empt 666QnP-O else N 1*; item#a]front^O front((O printf1Pthe deleted item from queue is 7dQnP!item-O S S traverse1- N int iO if1front##rear(1- printf1P666 queue is empt 666QnP-O else N for1i#frontOi?#rearOi((- if1i##front RR rear##i- printf1P7d at 7d $Mfront#rearQnP!a]i^!i-O else if1i##rear- printf1P7d at 7d $MrearQnP!a]i^!i-O else if1i##front- printf1P7d at 7d $MfrontQnP!a]i^!i-O else printf1P7d at 7dQnP!a]i^!i-O S S In1ut=,ut1ut/ 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:1 enter item into queue:11 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:1 enter item into queue:1" 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC 1*+ ,. .BATEBSE ). E_A. enter our choice:1 enter item into queue:1, 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:1 enter item into queue:1) 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:1 666 queue is full 666 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:, 11 at 0 $Mfront 1" at 1 1, at " 1) at , $Mrear 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:" the deleted item from queue is 11 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:" the deleted item from queue is 1" 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE 1*8 ). E_A. enter our choice:" the deleted item from queue is 1, 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:" the deleted item from queue is 1) 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:" 666 queue is empt 666 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:, 666 queue is empt 666 666 :ECJ 666 1. ACSEB.AKC ". 0EGE.AKC ,. .BATEBSE ). E_A. enter our choice:) concluion/ the program is error free 5I5A 6789ATI,N9/ 1$ 0efine queue @ An/ A queue is a linear! sequential list of that are accessed in the oeder first in first out1FAFK-. "- 0efine circular queues @ An/ A queue can also be circular in which case! it is called as a circular queue ,- What are the various stac5 oriented notations @ An/ i- infi% ii- prefi% iii- postfi% 1;0 ,b-ecti.e %&/ =rogram that implement Dueue operation b using the pointers 0ecri1tion : An this program we have to implement the Dueue operation b using the pointers. 2ere the Dueue operation are push and pop. =ush operation is used to insert the elements into a Dueue and pop operation is used to remove the elements in to a Dueue. Algorithm/ Step 1: Start Step ": define structure for queue Step ,: read choice Step ): if choice # insert i- read the element ii- create a data structure iii- if empt queue then front of queue pinter points to newl created data structure iv- otherwise end of the queue points to newl created data structure Step 9: if choice# remove i- chec5 if queue is empt . if so! print queue is empt ii- otherwise read the element pointed b front of the queue temp pointer points to front of queue iii- front of queue points to ne%t element iv- free the element pointed b temp pointer v- return the element vi- print the element Step *: if choice # displa i- chec5 of empt queue if so! print queue empt ii- otherwise print the elements from front of the queue until the end of the queue step ;: if choice#e%its stop 1;1
start 0efine the structure for queue Bead the choice Af choice#inse rt Bead the element to be inserted Af choice#remo ve Af ' e`que1- =rint queue is empt H =tr$Mn#queue Dueue $Mele#ele Dueue $Mn#CJGG Af f`ptr#CJG G F(ptr#queue H =tr#f`ptr ptr $Mn'#CJGG =tr # ptr $M n Af choice#displ a =tr#f`ptr A Af choice#e% it stop =rint invalid choice =rint U H H . F F . F . . F . . F . F 2lo3chart/ 1;" 1rogram/ Ldefine true 1 Ldefine false 0 Linclude?stdio.hM Linclude?conio.hM Linclude?process.hM struct q`point N int eleO struct q`point6 nO SO struct q`point 6f`ptr # CJGGO int e`que1void-O void add`ele1int-O int rem`ele1void-O void show`ele1-O &6main function6& void main1- N A Af empt queue =rint empt queue H Af ptr' #CJGG =rint ptr $M ele =tr# ptr$M n . F . 1;, int ele!choice!UO while11- N clrscr1-O printf1PQnQn6666A:=GE:EC.A.AKC KF DJEJE JSAC/ =KAC.EBS6666QnP-O
printf1P##############################################P-O printf1PQnQt]1^ .o insert an elementP-O printf1PQnQt]"^ .o remove an elementP-O printf1PQnQt],^ .o displa all the elementsP-O printf1PQnQt])^ E%itP-O printf1PQnQnQtEnter our choice:P-O scanf1P7dP! Rchoice-O switch1choice- N case 1: N printf1PQnQtElement to be inserted:P-O scanf1P7dP!Rele-O add`ele1ele-O getch1-O brea5O S case ": N if1'e`que1-- N U#rem`ele1-O printf1PQnQt7d is removed from the queueP!U-O getch1-O S else N printf1PQnQtDueue is Empt.P-O getch1-O S brea5O S case ,: 1;) show`ele1-O getch1-O brea5O case ): e%it11-O brea5O default: printf1PQnQtAnvalid choice.P-O getch1-O brea5O S S S &6 Function to chec5 if the queue is empt6& int e`que1void- N if1f`ptr##CJGG- return trueO return falseO S &6 Function to add an element to the queue6& void add`ele1int ele- N struct q`point 6queue # 1struct q`point6-malloc1siIeof1struct q`point--O queue$Mele # eleO queue$Mn # CJGGO if1f`ptr##CJGG- f`ptr # queueO else N struct q`point6 ptrO ptr # f`ptrO for1ptr#f`ptr Optr$Mn'#CJGGO ptr#ptr$Mn-O ptr$Mn # queueO S S &6 Function to remove an element from the queue6& int rem`ele1- N struct q`point6 queue#CJGGO 1;9 if1e`que1-##false- N int U # f`ptr$MeleO queue#f`ptrO f`ptr # f`ptr$MnO free 1queue-O return UO S else N printf1PQnQtDueue is empt.P-O return $8888O S S &6 Function to displa the queue6& void show`ele1- N struct q`point 6ptr#CJGGO ptr#f`ptrO if1e`que1-- N printf1PQnQtDJEJE is Empt.P-O returnO S else N printf1PQnQtElements present in Dueue are:QnQtP-O while1ptr'#CJGG- N printf1P7dQtP!ptr$Mele-O ptr#ptr$MnO S S S ,ut1ut/ 6666A:=GE:EC.A.AKC KF DJEJE JSAC/ =KAC.EBS6666 ############################################## :ECJ ############################################## ]1^ .o insert an element ]"^ .o remove an element ],^ .o displa all the elements 1;* ])^ E%it Enter our choice:1 Element to be inserted:",
6666A:=GE:EC.A.AKC KF DJEJE JSAC/ =KAC.EBS6666 ############################################## :ECJ ############################################## ]1^ .o insert an element ]"^ .o remove an element ],^ .o displa all the elements ])^ E%it Enter our choice: , Elements present in Dueue are: ",
6666A:=GE:EC.A.AKC KF DJEJE JSAC/ =KAC.EBS6666 ############################################## :ECJ ############################################## ]1^ .o insert an element ]"^ .o remove an element ],^ .o displa all the elements ])^ E%it Enter our choice:" ", is removed from the queue 6666A:=GE:EC.A.AKC KF DJEJE JSAC/ =KAC.EBS6666 ############################################## :ECJ ############################################## ]1^ .o insert an element ]"^ .o remove an element ],^ .o displa all the elements ])^ E%it Enter our choice:) E%it 4oncluion / the program is error free 1;; 5I5A 6789ATI,N9/ 1$ 0efine queue @ An/ A queue is a linear! sequential list of that are accessed in the oeder first in first out1FAFK-. "- 0efine circular queues @ An/ A queue can also be circular in which case! it is called as a circular queue ,- What are the various stac5 oriented notations @ An/ i- infi% ii- prefi% iii- postfi% 1;+ ,b-ecti.e %'/ =rogram that uses the stac5 operation to perform the following i- converting infi% e%pression into postfi% e%pression ii- evaluating the postfi% e%pression 0ecri1tion/ An this program we have to covert the given infi% e%pression to postfi% e%pression and the finall evaluating that postfi% e%pression. 2ere we made use of stac5 operations. .he propert of stac5s is last in first out. i.e.! the item that is inserted last will be the firt item remove. AL>,!IT;M/ Step 1. start Step ". first initialiIe the stac5 to be empt Step ,. for each character in the input string Af input string is an operand! append to the output if the input string is a left paranthesis ! push it onto the stac5 else if stac5 is empt or the operator has higher priorit than the operator on the topof stac5 or the top of the stac5 is opening parenthesis then push the operator onto the stac5 else pop the operator from the stac5 and append to the output Step ). if the input string is a closing parenthesis ! pop operators from the stac5 and append the operators to the output until an opening parenthesis is encountered. =op the opening parenthesis from the stac5 and discard it. Step 9. if the end of the input string is encountered ! then iterate the loop until the stac5 is not empt. =op the stac5 and append the remaining input string to the output. Step *. stop 1;8 " ( 19$+-&, # "9+$,&( Anput " input 9 input + Anput pop +!9 push result input , " 9 " + 9 " 1+0
Anput 1 input ( 9 " " $, " , $, " 9 " $1 " 1 1+1 Program/ Linclude?stdio.hM Linclude?ctpe.hM Linclude?string.hM static char str]"0^O int top#$1O main1- N char in]"0^!post]"0^!chO int i!U!lO clrscr1-O printf1Penter the stringP-O gets1in-O l#strlen1in-O for1i#0!U#0Oi?lOi((- if1isalpha1in]i^-- post]U((^#in]i^O else N if1in]i^##\1\- push1in]i^-O else if1in]i^##\-\- while11ch#pop1--'#\1\- post]U((^#chO else N while1priorit1in]i^-?#priorit1str]top^-- post]U((^#pop1-O push1in]i^-O S S 1+" while1top'#$1- post]U((^#pop1-O post]U^#\Q0\O printf1PQn equivalent infi% to postfi% is:7sP!post-O getch1-O S priorit 1char c- N switch1c- N case\(\: case\$\: return 1O case\6\: case\&\: return "O case\a\: return ,O S return 0O S push1char c- N str]((top^#cO S pop1- N return1str]top$$^-O S In1ut=,ut1ut/ enter the string1a(b-$1c$d-6e&f equivalent infi% to postfi% is:ab(cd$e6f&$ enter the stringa(b&c6d equivalent infi% to postfi% is:abc&d6( 4oncluion/ the program is error free. 1+, ii$AL>,!IT;M/ 9te1 1/ 9tart Step ": Assign top#$1 Step ,: Bead the input e%pression Step ): for i#0Os]i^'#4Q04 in steps of 1 Step 9: Af isdigit1ch- Step 9.1:=ush1ch- Step *: otherwise Step *.1:op1#pop1- Step *.": op"#pop1- Step ;: c#op"(op1 Step +: =ush1c- Step 8: c#op"$op1 Step 10: =ush1c- Step 11: c#pow1op"!op1- Step 1": =ush1c- Step 1,: c#op"&op1 Step 1):=ush1c- Step 19: =rint the result Step 1*:=ush1int %- Step 1;:Ancrement top b 1 1+) Step 1+: s1.item1s1.top,-#% Step 18:pop1- Step "0: Bead % Step "1: %1#s1.item]s1.top^ Step "":s1.topW Step ",:return % Step "): Stop 2lo3chart/ a(b # ab( =ush a =op a a 1+9 =ush ( =ush b =op ab( ( b ( 1+* Program/ Linclude?stdio.hM Linclude?ctpe.hM int st5]10^!top#0!op1!op"!iO main1- N char poste%p]10^O clrscr1-O printf1Penter the postfi% e%pression:P-O gets1poste%p-O for1i#0Oposte%p]i^'#\Q0\Oi((- N if1isdigit1poste%p]i^-- push1poste%p]i^$)+-O else N op1#pop1-O op"#pop1-O switch1poste%p]i^- N case \(\:push1op1(op"-O brea5O case \$\:push1op1$op"-O brea5O case \6\:push1op16op"-O brea5O case \&\:push1op1&op"-O brea5O case \7\:push1op17op"-O brea5O case \.\:e%it1-O S S S printf1Pthe result of postfi%e%pression is: 7dP!pop1--O 1+; getch1-O S pop1- N return1st5]top$$^-O S push1int %- N top((O st5]top^#%O S In1ut=,ut1ut/ enter the postfi% e%pression:",)($ the result of postfi% e%pression is: 9 4oncluion/ the program is error free. 5I5A 6789ATI,N9/ 1$ 0efine Stac5 @ Ans: A stac5 is a linear data structure in which a data item is inserted and deleted at one end "- 0efine data structure @ An/ A data structure is a collection of organiIed data that are related to each other %$ What are the various operation performed on the stac5 @ Ans: push1-! pop1- 1++ ,b-ecti.e %(/ =rogram to i- create a binar tree of integers ii- .raversing the above binar tree in preorder! inorder and post order
0ecri1tion: .he data structure tree is of non linear tpe. Hinar tree is bit special. .he propart of a binar tree is the value at the root must be grater than the left node and less than the right node. .he binar tree consist of almost two childrens. .ree is a recursive data structure and recursive programming techniques are popularl used in trees. A tree can can be traversed in three maUor was i- Anorder traversal: here left child is visited first followed b root and finall b right child. ii- =reorder traversal: 2ere root is visitedfirst follwed b left child and finall b right child. iii- =ostorder traversal: 2ere left child is visited first followed b right child finall b the root. AL>,!IT;M/ Step 1: Start Step ": 0efine a structure btree Step ,: .pe define struct btree as node Step ): While1tree-! begin Step 9: =rint :ECJ Step *: Write our choice Step ;: Af choice#1 Step +: Enter our no of nodes Step 8:Bead nodes n 1+8 Step 10: for i#1 to n in steps of 1 do Step 11: =rint enter item Step 1": Bead item Step 1,: Boot #call create 1root! item-.end for Step 1): if choice#" Step19: Bead element to be deleated Step 1*: Call delete1root! item- end for Step 1;: Af choice#, Step 1+: Call preorder1root- Step 18: Call postorder1root- Step "0: Call inorder1root- Step "1: Hrea5! end of switch Step "": Stop
For insert function Step 1: Start Step ": Af t# null Step ,: Allocate memor to temp Step ): .emp$Mdata #item Step 9: .emp$M lc#null Step *: .emp$Mrc#null Step ;: return t to main and end Step +: Af item? 1l$Mdata- Step 8: .$Mlc#call insert1e$Mlc! t- 180 Step 10: .$Mrc#call isert1e$Mlc!t- Step 11:Beturn t Step 1": Stop For DELETION function Step 1: Start Step ": %#d Step ,: while %'#null Step ): Af %$Mdata #t Strep 9:Hrea5 Step *: =arent #% Step ;: if t?%$Mdata Step +: t#tlc Step 8: t#lrc Step 10: Af %lc'#null RR%rc'#null Step11: parent #% Step1": Af parent##null Step 1,: parentlc##null Step 1): parentrc##null Step 19: Af p$Mlc#%$Mrc Step 1*: Af p$Mrc#%$Mrc Step 1;: While insert$Mlc#null Step 1+: Ansert#insert$Mla Step 18:%$Mdata#insert$Mdata 181 Step "0:%#insert Step "1: Beturn d Step "": Stop For ACKB0EB function Step 1: Start Step ": Af t'#null Step ,: Call inorder1t$Mlc- Step ): Write t$Mdata Step 9: Call inorder1t$Mrc- Step *: Stop For =KS.KB0EB function Step 1: Start Step ": Af t'#null Step ,: Call postorder1t$Mlc- Step ): Call postorder1t$Mrc- Step 9: Write data Step *: Stop For =BEKB0EB function Step 1: Start Step ": Af t'#null 18" Step ,: Write data Step ): Call postorder1t$Mlc- Step 9: Call postorder1t$Mrc- Step *: Stop 2lo3chart/ 18, 18) Program/ 189 Linclude?stdio.hM Linclude?alloc.hM struct bstnode N int dataO struct bstnode 6lc!6rcO S6root!6a]"0^!6b]"0^O int top#$1!top1#$1!n!iO main1- N int ch!eleO struct bstnode 6t!6insert1-!6pop1-O clrscr1-O t#root#CJGGO while11- N printf1PQn 6666 : E C J 6666 QnP-O printf1P1.ACSEB.Qn".BECJBSSATE .BATEBSEQn,.CKC$BECJBSATE .BATEBSEQn).E_A.QnP-O printf1PEnter our choice: P-O scanf1P7dP!Rch-O switch1ch- N case 1: printf1PEnter how man elements u want to insert:P-O scanf1P7dP!Rn-O printf1PEnter tree elements: P-O for1i#1Oi?#nOi((- N scanf1P7dP!Rele-O t#insert1t!ele-O S brea5O case ": &6 BECJBSSATE .BATEBSE 6& if1t##CJGG- printf1P6666 .BEE AS E:=.X 6666P-O else N printf1PACKB0EB :P-O inorder1t-O printf1PQn=BEKB0EB :P-O preorder1t-O printf1PQn=KS.KB0EB :P-O postorder1t-O S brea5O 18* case ,: &6 CKC$BECJBSSATE .BATEBSE 6& if1t##CJGG- printf1P.BEE AS E:=.XP-O else N printf1PACKB0EB :P-O nrinorder1t-O printf1PQn=BEKB0EB :P-O nrpreorder1t-O printf1PQn=KS.KB0EB :P-O nrpostorder1t-O S brea5O case ): e%it1-O S S S struct bstnode 6insert1struct bstnode 6%!int - N if1%##CJGG- N %#malloc1siIeof1struct bstnode--O %$Mdata#O %$Mlc#CJGGO %$Mrc#CJGGO S else N if1?%$Mdata- %$Mlc#insert1%$Mlc!-O else %$Mrc#insert1%$Mrc!-O return1%-O S S inorder1struct bstnode 6%- N if1%'#CJGG- N inorder1%$Mlc-O printf1P7,dP!%$Mdata-O inorder1%$Mrc-O S S preorder1struct bstnode 6%- 18; N if1%'#CJGG- N printf1P7,dP!%$Mdata-O preorder1%$Mlc-O preorder1%$Mrc-O S S postorder1struct bstnode 6%- N if1%'#CJGG- N postorder1%$Mlc-O postorder1%$Mrc-O printf1P7,dP!%$Mdata-O S S nrinorder1struct bstnode 6%- N struct bstnode 6lO l#%O do N while1l'#CJGG- N push1l-O l#l$MlcO S while1topM$1- N l#pop1-O printf1P7dP!l$Mdata-O if1l$Mrc'#CJGG- N l#l$MrcO brea5O S else l#CJGGO S Swhile1l'#CJGG-O S nrpreorder1struct bstnode 6%- N struct bstnode 6lO l#%O 18+ do N printf1P7dP!l$Mdata-O if1l$Mrc'#CJGG- push1l$Mrc-O l#l$MlcO if1l##CJGGRRtopM$1- l#pop1-O Swhile1l'#CJGG-O S nrpostorder1struct bstnode 6%- N struct bstnode 6lO l#%O do N while1l'#CJGG- N push1l-O if1l$Mrc'#CJGG- N push1l$Mrc-O b]((top1^#l$MrcO S l#l$MlcO S do N l#pop1-O if1l'#b]top1^- printf1P7,dP!l$Mdata-O else N top1$#1O brea5O S S while1topM$1-O Swhile1l'#CJGGRRtopM$1-O S push1struct bstnode 6- N top(#1O a]top^#O S struct bstnode 6pop1- N 188 return a]top$$^O S In1ut=,ut1ut/ Enter our choice 1.Ansert ".0elete ,..raversal Enter the element 8" Enter our choice 1. Ansert ".0elete ,. .raversal Enter the element "* Enter our choice 1.Ansert ".0elete ,..raversal Enter the element 1" Enter our choice 1.Ansert ".0elete ,..raversal Enter the element 1", Enter our choice 1.Ansert ".0elete ,..raversal Enter the element 1,9 Enter our choice 1.Ansert ".0elete ,..raversal Enter the element 1"+ Enter our choice 1.Ansert ".0elete ,..raversal , AnorderSequence: 1" "* 8" 1", 1"+ 1,9 =reorder sequence:8" "* 1" 1", 1,9 1"+ =ostorder sequence: 1" "* 1"+ 1,9 1" 8" 4oncluion/ the program is error free. 5I5A 6789ATI,N9/ 1- 0efine Hinar tree @ Ans: Hinar tree is a bit special! because whan the are in the sorted form! the facilitate quic5 search! insertion! and deletion. "- 2ow man was a tree can be traversed @ Ans: An three was. .he are i- An$order ii- pre$order iii- post$order ,- define graph @ Ans: A graph is a set of nodes1vertices- and a set of arcs1edges-. A graph is connected if there is a path between an two nodes of the graph. ,b-ecti.e %)/ "00 .o perform the linear search operation 0ecri1tion/ .he linear search is most simple serching method. At does not e%pect the list to be sorted. .he 5e which is to be searched is compared with each element of the list one b one. Af a match e%ists! the search is terminated. Af the end of list is reached it means that the search has failed and 5e has no matching in the list. AL>,!IT;M/ LIN8A! 98A!4; 1. Start ". Bead the value of n ,. for i#1 to n increment in steps of 1 Bead the value of ith element into arra ). Bead the element1%- to be searched 9. search?$$linear1a!n!%- *. if search equal to 0 goto step ; otherwise goto step + ;. print unsuccessful search +. print successful search 8. stop GACEAB FJCC.AKC 1. start ". for i#1 to n increment in steps of 1 ,. if m equal to 5]i^ goto step ) otherwise goto step " ). return i 9. return 0 *. stop 2lo3chart/ "01 start Bead n i#1 i?#n i(( Bead a]i^ Bead b C#linear search1a!b- Af c' #0 =rint c Print element i not found stop . F "0" start For1i#1Oi?nOi((- Af m##5]i^ . F stop F . "0, Program/ Linclude?stdio.hM main1- N int i!U!n!a]10^!5eO clrscr1-O printf1Penter range for arra:P-O scanf1P7dP!Rn-O printf1Penter elements into arra:P-O for1i#0Oi?#nOi((- scanf1P7dP!Ra]i^-O printf1Penter the search element:P-O scanf1P7dP!R5e-O for1i#0Oi?#nOi((- N if15e##a]i^- N printf1Pelement 7d found at 7dP!5e!i-O brea5O S else if1i##n- printf1Pelement 7d not found in arraP!5e-O S getch1-O S In1ut=,ut1ut/ enter range for arra:) enter elements into arra:9* ), 1" ++ 8 enter the search element:8 element 8 found at ) enter range for arra:9 enter elements into arra:", 1" 9* ,) , + enter the search element:, element , found at ) concluion/ the program is error free "0) 5I5A 6789ATI,N9/ 1- 0efine linear search @ Ans : .he linear search is most simple serching method. At does not e%pect the list to be sorted. .he 5e which is to be searched is compared with each element of the list one b one. Af a match e%ists! the search is terminated. Af the end of list is reached it means that the search has failed and 5e has no matching in the list. "09 ,b-ecti.e %*/ .o perform the binar search operation 0ecri1tion/ Hinar search is a vast improvement over the sequential search. For binar search to wor5! the item in the list must be in assorted order. .he approach emploed in the binar search is divid and conquer. Af the list to be sorted for a specific item is not sorted! binar search fails. AL>,!IT;M/ HACABX SEABC2 1. Start ". Bead the value of n ,. for i#1 to n increment in steps of 1 Bead the value of ith element into arra ). Bead the element1%- to be searched 9. search?$$binar1a!n!%- *. if search equal to 0 goto step ; otherwise goto step + ;. print unsuccessful search +. print successful search 8. stop HACABX SEABC2 FJCC.AKC 1. start ". initialise low to 1 !high to n! test to 0 ,. if low?# high repeat through steps ) to 8 otherwise goto step 10 ). assign 1low(high-&" to mid 9. if m?5]mid^ goto step * otherwise goto step ; *. assign mid$1 to high goto step , ;. if mM5]mid^ goto step + otherwise goto step 8 +. assign mid(1 to low 8. return mid 10. return 0 11.stop "0* 2lo3chart/ "0; "0+ Program/ Linclude?stdio.hM main1- N int i!n!5e!a]10^!low!high!midO clrscr1-O printf1Penter range for arra:P-O scanf1P7dP!Rn-O printf1Penter elements into arra:P-O for1i#0Oi?nOi((- scanf1P7dP!Ra]i^-O printf1Pthe search element:P-O scanf1P7dP!R5e-O low#0O high#n$1O for1i#0Oi?nOi((- N mid#1low(high-&"O if1a]mid^##5e- N printf1Pelement 7d found at 7dP!5e!mid-O brea5O S if15e?a]mid^- high#midO else low#mid(1O if1i##n$1- printf1Pelement 7d not found in arraP!5e-O S getch1-O S In1ut=,ut1ut/ enter range for arra:) enter elements into arra:1" ", ,) )9 the search element:)9 element )9 found at , enter range for arra:9 enter elements into arra:1 ,) 9* ;+ ++ the search element:)9 element )9 not found in arra concluion/ the program is error free "08 5I5A 6789ATI,N9 1$ 0efine Hinar search @ An/ Hinar search is a vast improvement over the sequential search. For binar search to wor5! the item in the list must be in assorted order. .he approach emploed in the binar search is divid and conquer. Af the list to be sorted for a specific item is not sorted! binar search fails. "10 ,b-ecti.e %+/ =rogram that implements the bubble sort method 0ecri1tion: Hubble sort is the simplest and oldest sorting technique. .his method ta5es two elements at a time. At compare these two elements. Af first elements is less than second one! the are left undistrurbed. Af the first element is greater then second one then the are swapped. .he procedure continues with the ne%t two elements goes and ends when all the elements are sorted. Hut bubble sort is an inefficient algorithm. .he order of bubble sort algorithm is K1n " -. Algorithm/ i-Hubble Sort: 1. start ". read the value of n ,. for i# 1 to n increment in steps of 1 Bead the value of ith element into arra ). call function to sort 1bubble`sort1a!n-- 9. for i# 1 to n increment in steps of 1 print the value of ith element in the arra *. stop HJHHGE SKB. FJCC.AKC 1. start ". initialise last to n ,. for i# 1 to n increment in steps of 1 begin ). initialise e% to 0 9. for i# 1 to last$1 increment in steps of 1 begin *. if 5]i^M5]i(1^ goto step ; otherwise goto step 9 begin ;. assign 5]i^ to temp assign 5]i(1^ to 5]i^ assign temp to 5]i(1^ increment e% b 1 end$if end inner for loop 11. if e%'#0 assign last$1 to last end for loop 1". stop "11 2lo3chart/ "1" Program/ Linclude?stdio.hM main1- N int i!U!t!a]9^!nO clrscr1-O printf1Penter the range of arra:P-O scanf1P7dP!Rn-O printf1Penter elements into arra:P-O for1i#0Oi?nOi((- scanf1P7dP!Ra]i^-O for1i#0Oi?n$1Oi((- for1U#i(1OU?nOU((- if1a]i^Ma]U^- N t#a]i^O a]i^#a]U^O a]U^#tO S printf1Pthe sorted order is:P-O for1i#0Oi?nOi((- printf1PQt7dP!a]i^-O getch1-O S In1ut=,ut1ut/ enter the range of arra:, enter elements into arra:, " 1 the sorted order is: 1 " , enter the range of arra:9 enter elements into arra:9* ", ,) 1" + the sorted order is: + 1" ", ,) 9* concluion/ .he program is error free 5I5A 6789ATI,N9 "1, 1- 0efine bubble sort @ Ans: : Hubble sort is the simplest and oldest sorting technique. .his method ta5es two elements at a time. At compare these two elements. Af first elements is less than second one! the are left undistrurbed. Af the first element is greater then second one then the are swapped. .he procedure continues with the ne%t two elements goes and ends when all the elements are sorted. "- displa the efficienc of bubble sort @ An / K1n " - ,b-ecti.e &0/ "1) =rogram that implements the Duic5 sort method 0ecri1tion: .his method is invented b hoare! considered to be fast method to sort the elements. .he method is also called partition e%change sorting. .he method is based on divide and conquer technique. i.e.! the entire list is divided into various partitions and sorting is applied again and again on the partition. An this method the list is divided into two baesd on an element called pivot element. Jsuall the first element is considerd to be the pivot element. Cow move the pivot element to its correct position in the list. .he elements to the left and pivot element are less that this while the elements to the right of pivot are greater than the pivot. .he process is reapplied to each of these partitions till we got the sorted list of elements. Algorithm/ 6uic" 9ort/ 1. start ". if lowerbound ? upperbound repeat through steps , to 1, otherwise goto step 1) begin ,. assign lowerbound to i!upperbound to U! i to pivot ). if i?U repeat through steps 9 to 10 otherwise goto step ` Hegin 9. if a]i^?#5]pivot^ and i? upperbound repeat through step * otherwise goto step ; begin *. assign i(1 to i end if ;. if 5]U^ M 5]pivot^ repeat through step + otherwise goto step 8 begin +. assign U$1 to U end if 8. if i? U goto step 10 other wise goto step ) Hegin 10. call function to swap 5]i^ and 5]U^ end if end if 11. call function to swap 5]pivot^ and 5]U^ 1". call function qsort1%!lowerbound!U$1- 1,. call function qsort1%!U(1!upperbound- end if 1). stop 2lo3chart/ "19
Program/ "1* Linclude?stdio.hM main1- N int %]10^!i!nO clrscr1-O printf1Penter no of elements:P-O scanf1P7dP!Rn-O printf1Penter 7d elements:P!n-O for1i#1Oi?#nOi((- scanf1P7dP!R%]i^-O quic5sort1%!1!n-O printf1Psorted elements are:P-O for1i#1Oi?#nOi((- printf1P7,dP!%]i^-O getch1-O S quic5sort1int %]10^!int first!int last- N int pivot!i!U!tO if1first?last- N pivot#firstO i#firstO U#lastO while1i?U- N while1%]i^?#%]pivot^ RR i?last- i((O while1%]U^M%]pivot^- U$$O if1i?U- N t#%]i^O %]i^#%]U^O %]U^#tO S S t#%]pivot^O %]pivot^#%]U^O %]U^#tO quic5sort1%!first!U$1-O quic5sort1%!U(1!last-O S S "1; 66666 KJ.=J. 66666 enter no of elements:* enter * elements:", 1" )9 ,) "1 +; sorted elements are: 1" "1 ", ,) )9 +; concluion/ .he program is error free 5I5A 6789ATI,N9 1$ 0efine quic5 sort @ An/ .his method is invented b hoare! considered to be fast method to sort the elements. .he method is also called partition e%change sorting. .he method is based on divide and conquer technique. i.e.! the entire list is divided into various partitions and sorting is applied again and again on the partition. An this method the list is divided into two baesd on an element called pivot element. Jsuall the first element is considerd to be the pivot element. Cow move the pivot element to its correct position in the list. .he elements to the left and pivot element are less that this while the elements to the right of pivot are greater than the pivot. .he process is reapplied to each of these partitions till we got the sorted list of elements. 2$ Efficienc of quic5 sort @ An/ K1n log n- ,b-ecti.e &1/Program that implements the insertion sort method "1+ 0ecri1tion/ Ansertion sort is similar to plaing cards. .o sort the cards in ourhand ou e%trat a card shift the remaining cards and then insert the e%tracted card in its correct place. .he efficienc of insertion sort is K1n " -. Algorithm/ ii- Ansertion Sort: 1. start ". for i# 1 to n increment in steps of 1 begin assign 5]i^ to temp ,. forU#i$1 down to UM#0 and temp?5]U^ begin assign 5]U^ to 5]U(1^ end inner for loop ). assign temp to 5]U(1^ end for loop 9. stop 2lo3chart/ "18 Program/ ""0 Linclude?stdio.hM main1- N int i!U!t!a]10^!n!p#0O clrscr1-O printf1Penter the range of arra:P-O scanf1P7dP!Rn-O printf1Penter elements into arra:P-O for1i#0Oi?nOi((- scanf1P7dP!Ra]i^-O for1i#1Oi?nOi((- N t#a]i^O for1p#iOpM0 RR a]p$1^MtOp$$- a]p^#a]p$1^O a]p^#tO S printf1Pthe sorted order is:P-O for1i#0Oi?nOi((- printf1PQt7dP!a]i^-O getch1-O S 66666 KJ.=J. 66666 enter the range of arra:9 enter elements into arra:9 ) , " 1 the sorted order is: 1 " , ) 9 enter the range of arra:* enter elements into arra:", 1" +8 )9 *; ,) the sorted order is: 1" ", ,) )9 *; +8 concluion/ .he program is error free 5I5A 6789ATI,N9 ""1 1$ 0efine insertion sort @ An/ Ansertion sort is similar to plaing cards. .o sort the cards in ourhand ou e%trat a card shift the remaining cards and then insert the e%tracted card in its correct place. 2$ Efficienc of the insertion sort @ An/ .he efficienc of insertion sort is K1n " -. ,b-ecti.e &2/ """ Program to implement the merge sort method Descr%&t%)n( .he merge sort splits the list to be sorted into two equal halves! and places them in separate arras. Each arra is recursivel sorted! and then merged bac5 together to form the final sorted list. Gi5e most recursive sorts! the merge sort has an algorithmic comple%it of O1n log n-. Algorithm/ main program Step1: Start Step": declare the merge sort function Step,: 0eclare the arra and their siIe and initailaIe the U#0 Step): read the arra elements and then sort these elements. Step9: read the arra elements before the merge sort and then displa the elements. Step*: call the merge sort function Step;: displa the arra elements after merge sort b using the following stament. for1 U#0OU?:a%`arOU((- Step+: Stop 9ub1rogram Step1:initialiIe the arra e%cuting]:A_`ABX^ and U#0!mid#0!mrg1#0!mrg"#0!siIe#start$end(1 Step": chec5 the condition if1end##start- then return Step,: calculate the mid value :id#1end(start-&" Step): call themerge`sort1%!end!mid- Step9:merge`sort1%!mid(1!start- Step*: performing the looping operation For1U#0OU?SAbEOU((- then its true E%ecuting]U^#%]end(1^ :rg1#0O Step;: calculate the mrg"#mid$end(1 Step+: performing the looping operation For1U#0OU?SAbEOU((- then its true then goto step8 Step8: chec5 the condition i- if1mrg"?#start$end- is true goto ii-. Af not goto Step1". ii- Af1mrg1?#mid$end- is true goto iii-. Af not goto step11 iii- Af1e%ecuting]mrg1^Me%ecuting]mrg"^- is true then follows. Af not goto step10. _]U(end^# e%ecuting]mrg"((^ Step10: %]U(end^#e%ecuting]mrg1((^. Af not goto Step11 Step11: %]U(end^# e%ecuting]mrg"((^ Step1": %]U(end^#e%ecuting]mrg1((^ Step1,: return to main program 2lo3 chart/ "", Start 0eclare the arra and arra siIe Bead the arra elements 0efine merge`sort function V#0 U(( U?:A_`ABX 0ispla the elements before merge sort :ergesort1ar!0!:A_`ABX$1- V#0 U(( U?:A_`ABX 0ispla the elements after merge sort .rue False .rue False Stop "") :erge`sort1- SiIe#start$end(1 :id#0 :rg1#0 :rg"#0 Af end##start :id#1end(start-&" Call merge`sort1%!end!mid- Call merge`sort1%!mid(1!start- U#0 U(( U?siIe E%ecuting]U^#%]end(U^ :rg1#0 .rue U(( U#0 U?siIe False Af mrg"?#start$ end False _]U(end^#e%ecuting]mrg1((^ .rue Af mrg1?#mid$ end False _]U(end^#e%ecuting]mrg"((^ Af e%ecuting]mrg1^M e%ecuting]mrg"^ False _]U(end^#e%ecuting]mrg1((^ .rue _]U(end^#e%ecuting]mrg"((^ .rue Beturn to main program . F ""9 Program/ Linclude ?stdio.hM Linclude ?stdlib.hM Ldefine :A_`ABX 10 void merge`sort1int %]^! int end! int start-O int main1void- N int ar]:A_`ABX^O int U # 0O printf1PQnQnEnter the elements to be sorted: QnP-O for1U#0OU?:A_`ABXOU((- scanf1P7dP!Rar]U^-O &6 arra before mergesort 6& printf1PHefore :P-O for1U # 0O U ? :A_`ABXO U((- printf1P 7dP! ar]U^-O printf1PQnP-O merge`sort1ar! 0! :A_`ABX $ 1-O &6 arra after mergesort 6& printf1PAfter :erge Sort :P-O for1U # 0O U ? :A_`ABXO U((- printf1P 7dP! ar]U^-O printf1PQnP-O getch1-O S &6 :ethod to implement :erge Sort6& void merge`sort1int %]^! int end! int start- N int U # 0O const int siIe # start $ end ( 1O int mid # 0O int mrg1 # 0O int mrg" # 0O int e%ecuting]:A_`ABX^O if1end ## start- returnO ""* mid # 1end ( start- & "O merge`sort1%! end! mid-O merge`sort1%! mid ( 1! start-O for1U # 0O U ? siIeO U((- e%ecuting]U^ # %]end ( U^O mrg1 # 0O mrg" # mid $ end ( 1O for1U # 0O U ? siIeO U((- N if1mrg" ?# start $ end- if1mrg1 ?# mid $ end- if1e%ecuting]mrg1^ M e%ecuting]mrg"^- %]U ( end^ # e%ecuting]mrg"((^O else %]U ( end^ # e%ecuting]mrg1((^O else %]U ( end^ # e%ecuting]mrg"((^O else %]U ( end^ # e%ecuting]mrg1((^O S S ,ut1ut/ Enter the elements to be sorted: + " , ) 1 9 ; * 8 0 Hefore : + " , ) 1 9 ; * 8 0 After :erge Sort : 0 1 " , ) 9 * ; + 8 Enter the elements to be sorted: ; * 9 ) + ) , " 1 , Hefore : ; * 9 ) + ) , " 1 , After :erge Sort : 1 " , , ) ) 9 * ; + 4oncluion/ the program is error free 5I5A 6789ATI,N9 1- 0efine merge sort @ Ans: .he merge sort splits the list to be sorted into two equal halves! and places them in separate arras. Each arra is recursivel sorted! and then merged bac5 together to form the final sorted list. "- Efficienc of merge sort @ Ans: O1n log n-. ""; ,b-ecti.e &%/ .o implements the Gagrange interpolation and Cewton /regor forward interpolation Lagrange Inter1olation / Algorithm/ Step 1. Bead %!n Step". for i#1 to 1n(1- is steps of 1 do Bead %i!fi end for Nthe above statements reads %!s and the corresponding values of f is S Step ,. Sum#0 Step ). for i#1 to 1n(1- in steps of 1 do Step 9. =rofvnc#1 Step *. for V#1 to 1n(1- in steps of 1 do Step ;. Af 1Uci- then prodfunc#prodfunc _1%$%U- & 1%i$%U- endfor Step +. Sum#Sum(fi % =rodfunc Nsum is the value of f at %S end for Step 8. Write %! sum Step 10. S.K= ""+ 2lo3 chart/ ""8 Program/ @includeAtdio.hB Linclude?math.hM :ain1- N Float ! %]"0^!f]"0^!sum!pfO Ant A!U!nO =rintf1Zenter the value of n[-O Scanf1Z7d[!Rn-O =rintf1Zenter the value to be found[-O Scanf1Z7f[!R-O =rintf1Zenter the values of %i4s R fi4s[-O For1i#0Oi?nOi((- N =f#1O For1U#0OU?nOU((- N Af1U'#i- =f 6# 1$%]U^-&1%]i^ < %]U^-O S Sum (# f]i^ 6pfO S =rintf1ZQn% # 7f [!-O =rintf1ZQn sum #7f [!sum-O S Anput&Kutput: Enter the value of n ) Enter the value to be found ".9 Enter the values for %i4s R fi4s 1 1 " + , "; ) *) _ # ".900000 Sum # 19.*"9000 4oncluion/ .he program is error free 5I5A 6789ATI,N9 1- 0efine storage class @ Ans: Storage class specifiers inform the complier how to store the variableO the storage clas specifiers in the c language are : auto! register! static!e%tern! tpedef ",0 Ne3ton gregor< for3ard inter1olation. Algorithm/ Step1: S.AB. Step": Bead n Step,: for i#0 to 1n$1- do read %i!i Step): read % Step9: hd%i$%0 Step*: pd1%$%o-&n Step;: for U#0 to n$" do e1UdU(1$ei$1 Step+: 5dn$" Step8: for i#" to 1n$1-do Step8.1: 5d5$1 Step8.":for U#0 to 5 do eiUdei$1 U(1$ei$1U Step10: Sumd0 Step11: =valued1 Step1": Fact valued1 Step1,: for l#1 to 1n$1- do Step1,.1: =valuedpvalue % 1p$1l$1-- Step1,.": factvaluedfactvalue%1 Step1,.,: termd1pvalue % el- & factvalue Step1,.): SumdSum(term Step1): =rint %!SJ:X Step19: S.K= 2lo3chart/ ",1 Program/ "," Linclude?stdio.hM Linclude?math.hM :ain1- N Ant i! U! n! 5! lO Float sum! h! term! p! I! pvalueO Float %]"9^! ]"9^! d]"9^]"9^! factvalueO =rintf1Zenter the value of n[-O Scanf1Z7d[!Rn-O =rintf1Zenter 7d values for %! Qn[!n-O For1i#0Oi?nOi((- Scanf1Z7f 7f[! R%]i^! R]i^-O =rintf1ZQn enter I[-O Scanf1Z7f[!RI-O h # %]1^ < %]0^O p # 1I $ %]0^ -& hO for1U#0O U?n$"O U((- d]i^]U^ #]U(1^ < ]U^O 5#n$"O for1i#"O i?nO i((- N 5((O for1U#0O U?#5O U((- d]i^]U^ #d]i$1^]U(1^ < d]i$1^]U^O S For1l#1O l?nO l((- N =value 6# 1p$1l $ 1--O Factvalue 6# 1O .erm # pvalue6 d]l^]0^ & factvalueO Sum (# termO S =rintf1ZQn value at I # 7f is 7f[! I! sum-O S In1ut=,ut1ut/ ",, Enter n ; Enter ; data values for %! 18"1 ,9 18,1 )" 18)1 9+ 1891 +) 18*1 1"0 18;1 1*9 18+1 ""0 Enter I 18"9 X value at I # 18"9.000000 is ,*.;9*;10 4oncluion/ .he program is error free 5I5A 6789ATI,N9 1$ What is the use of goto statement @ An/ .he goto statement is used to alter the normal sequence of the program e%ecution b unconditionall transferring control to some other part of the program. 2$ What is the use of continue statement @ An/ .he continue statement is used to bpass the remainder of the current pass through a loop ,b-ecti.e &&/ ",) Amplement in 3C4 the linear regression and polnomial regression algorithms Linear regreion Algorithm/ Step 1. Bead n Step ". Sum%#0 Step ,. Sum%sq#0 Step ). Sum#0 Step 9. Sum%#0 Step *. fori#1 to n do Step ;. Bead %! Step +. Sum%#sum%(% Step 8.Sum%sq#Sum%sq(%" Step 10.Sum#Sum( Step 11.Sum%#sum%(% % end for Step 1". denom#n % sum%sq < sum% % sum% Step 1,. a0#1sum % sum%sq < sum% % sum%- & denom Step 1). a1#1n % sum%$sum% % sum-& denonm Step 19. Write a1!a0 Step 1*. S.K= ",9 ",* Program/ Linclude?stdio.hM Linclude?math.hM :ain1- N Ant n!AO Float sum%! sum%sq! sum! sum%! %! ! a0! a1! denomO =rintf1Zenter the n value[-O Scanf1Z7d[!Rn-O Sum%#0O Sumsq#0O Sum#0O Sum%#0O For1i#0Oi?nOi((- N Scanf1Z7f 7f[!R%! R-O Sum% (#%O Sumsq (# pow1%! "-O Sum (#O Sum% (#% 6 O S 0enom # n 6 sum%sq < pow1sum%! "-O A0 # 1sum 6 sum%sq <sum% 6sum%-&denomO A1 # 1n 6 sum% <sum% 6sum-&denomO =rintf1Z# 7f% ( 7f[!a1!a0-O S In1ut=,ut1ut/ Enter the n value ; 1 " " 9 ) ; 9 10 * 1" + 19 8 18 X # 1.8+0;*8% ( 0.08*19) 4oncluion/ .he program is error free 5I5A 6789ATI,N9 1$ What is the use of goto statement @ An/ .he goto statement is used to alter the normal sequence of the program e%ecution b unconditionall transferring control to some other part of the program. 2$ What is the use of continue statement @ An/ .he continue statement is used to bpass the remainder of the current pass through a loop ",; Pol<nomial regreion Algorithm/ Sep 1: Strart Step ": Bead n Step ,: AnitialiIe sum% # 0! sum%sq # 0! sum # 0! sum% # 0! sum%, # 0! sum%) # 0! sum%sq #0 Step ): AntialiIe i#0 Step 9: Bepeat steps 9 to ; until i?n Step *: Bead %! Step ;: Sum% # sum% ( % Sum%sq #sum%sq ( pow1%!"- Sum%, # sum%, ( pow1%!,- Sum%) # sum%) ( pow1%!)- Sum # sum ( Sum% # Sum% ( %6 Sum%sq # Sum%sq ( pow1%!"- 6 Step +: Ancrement A b 1 Step 8: Assign a]0^]0^ # n a]0^]1^ # n a]0^]"^ # n a]0^],^ # n a]1^]0^ # n a]1^]1^ # n a]1^]"^ # n a]1^],^ # n a]"^]0^ # n a]"^]1^ # n a]"^]"^ # n a]"^],^ # n
Step 10: AntialiIe i#0 Step 11: Bepeat steps 11 to 19 until i?, ",+ Step 1": AntialiIe U#0 Step 1,: Bepeat step 1, to 1) until U?#, Step 1): Write a]i^]U^ Step 19: Ancrement U b 1 Step 1*: Ancrement A b 1 Step 1;: AnitialiIe 5 #0 Step 1+: Bepeat steps 1+ to "; until 5?#" Step 18: AntialiIe i#0 Step "0: Bepeat step "0 to "* until i?#" Step "1: Af A not equal to 5 Step "": Asign u#a]i^]5^&a]5^]5^ Step ",: AntialiIe U#5 Step "): Bepeat steps ") and "9 until U?#, Step "9: Assign a]i^]U^ # a]i^]U^ < u 6a]5^]U^ Step "*: Ancrement U b 1 Step ";: Ancrement i b 1 Step "+: Ancrement 5 b 1 Step "8: AnitialiIe A #0 Step ,0: Bepeat steps ,1 to ,, until i?, Step ,1: Assign b]i^ # a]i^],^&a]i^]i^ Step ,": Write A! b]i^ Step ,,: Ancrement A b 1 Step ,): Write b]"^!b]i^!b]0^ Step ,9: Stop ",8 2lo3chart/ ")0 Program/ Linclude?stdio.hM Linclude?math.hM main1- N Ant n! A! U! 5O Float sum%! sum%sq! sum! sum%! %! O Float sum%,! sum%)! sum%sq! a]"0^]"0^! u#0.0! b]"0^O =rintf1ZQn Enter the n value[-O Scanf1Z7d[! Rn-O Sum% # 0O Sum%sq # 0O Sum # 0O Sum% # 0O Sum%, # 0O Sum%) # 0O Sum%sq # 0O For1i#0O i?nO i((- N Scanf1Z7f 7f[! R%! R-O Sum% (#%O Sum%sq (# pow1%!"-O Sum%, (# pow1%!,-O Sum%) (# pow1%!)-O Sum (#O Sum% (# % 6 O Sum%sq (# pow1%!"- 6O S A]0^]0^ # nO A]0^]1^ # sum%O A]0^]"^ # sum%sqO A]0^],^ # sumO A]1^]0^ # sum%O A]1^]1^ # sum%sqO A]1^]"^ # sum%,O A]1^],^ # sum%O A]"^]0^ # sum%sqO A]"^]1^ # sum%,O A]"^]"^ # sum%)O A]"^],^ # sum%sqO for1i#0O i?,O i((- N for1U#0O U?#,O U((- =rintf1Z710."f[!a]i^]U^-O ")1 =rintf1ZQn[-O S For15#0O 5?#"O 5((- N For1i#0Oi?#"Oi((- N Af1i'#5- J#a]i^]5^&a]5^]5^O For1U # 5O U?#,O U((- A]i^]U^#a]i^]U^ < u 6 a]5^]U^O S S For1i#0Oi?,Oi((- N H]i^ # a]i^],^&a]i^]i^O =rintf1ZQn%]7d^ # 7f[! A! b]i^-O S =rintf1ZQn[-O =rintf1Z# 710.)f% (10.) f% (710.)f[!b]"^!b]i^!b]0^-O S In1ut=,ut1ut/ Enter the n value 10 $) "1 $, 1" $" ) $1 1 0 " 1 ; " 19 , ,0 ) )9 9 *; 10.00 9.00 +9.00 "0).00 9.00 +9.00 1"9.00 91,.00 +9.00 1"9.00 1,,,.00 ,18,.00 _]0^ # ".0,0,0, _]1^ # ".88*8;0 _]"^ # 1.8+)+)+ X # 1.8+)+%sq ( ".88;8% ( ".0,0, Conclusion: .he program is error free ")" 5I5A 6789ATI,N9 1$ 0efine insertion sort @ An/ Ansertion sort is similar to plaing cards. .o sort the cards in ourhand ou e%trat a card shift the remaining cards and then insert the e%tracted card in its correct place. 2$ Efficienc of the insertion sort @ An/ .he efficienc of insertion sort is K1n " -. "), ,b-ecti.e &'/ =rogram to Amplement .raeIodial and simpson methods. TraeCodial method/ Algorithm/ Step 1. Bead %1! %"! e N %1 and %" are the two end points of the internal the allowed error in integral is eS Step ". h#%"$%1 Step ,. SA # 1f1%1- ( f1%"--&"O Step ). A # h$si Step 9. i#1 Bepeat Step *. %#%1 ( h&" Step ;. for V# 1 to A do Step +. SA# SA ( f1%- Step 8. %#%(h Endfor Step 10. i#"1 Step 11. h#h&" N Cote that the internal has been halved above and the number of points where the function has to be computed is doubledS Step 1".i0#i1 Step 1,. i1 # h.si Step 1). until & A1$i0 & ?#c.&i1& Step 19. Write A1!h!i Step 1*. Stop ")) 2lo3chart/ ")9 Program/ Linclude?stdio.hM Linclude?math.hM main1- N float h!a!b!n!%]"0^!]"0^!sum#0!integralO int iO clrscr1-O printf1Penter the value ofa!b!n:P-O scanf1P7f 7f 7fP!Ra!Rb!Rn-O printf1Penter the values of %:P-O for1i#0Oi?#1n$1-Oi((- N scanf1P7fP!R%]i^-O S printf1PQn enter the values of :P-O for1i#0Oi?#1n$1-Oi((- N scanf1P7fP!R]i^-O S h#1b$a-&nO %]0^#aO for1i#1Oi?#n$1Oi((- N %]i^#%]i$1^(hO sum#sum("6]i^O S sum#sum(]b^O integral#sum61h&"-O printf1Pappro%imate integral value is: 7fP!integral-O getch1-O S ")* In1ut=,ut1ut/ Enter the values of a!b!n 1 " , Enter the values of %: 1 " , Enter the values of : 1 " , Appro%imate integral value is ".1****; 4oncluion/ .he program is error free "); 9im1on Method/ Algorithm/ Step 1. Bead %1!%"!e Step ". h#1%"$%1-&" Step ,. i#" Step ). si#f1%1- ( f1%"- Step 9. s"#0 Step *. s)#f1%1(h- Step ;. A0#0 Step +. An #1s()s)-. 1h&,- Bepeat Step 8. s"#s"(s) Ns" stores alread computed functional value and s) the value computed in the new nitration S Step 10. s)#0 Step 11. %#%1(h&" Step 1". for U#1 to A do Step 1,. s)#s)(f1%- Step 1). %#%(h Step 19. h#h&" Step 1*. i#"i Step 1;. io#in Step 1+. in# 1s1("s"()s)- . 1h&,- Step 18. until YAn$AoYfe. &in Step "0. Write An!h!i Step "1. S.K= ")+ 2lo3chart/ ")8
Program/ Linclude?stdio.hM Linclude?conio.hM Linclude?math.hM main1- N float h!a!b!n!%]"0^!]"0^!sum#0!itglO int iO clrscr1-O printf1Penter the values of a!b!nP-O scanf1P7f7f7fP!Ra!Rb!Rn-O printf1Penter the values of %P-O for1i#0Oi?#nOi((- N scanf1P7fP!R%]i^-O S printf1PQn enter the values of P-O for1i#0Oi?#nOi((- N scanf1P7fP!R]i^-O S h#1b$a-&nO a#%]0^O b#%]n^O for1i#0Oi?#1n$"-Oi((- N %]i^#%]i^(hO if1i7"##0- N sum#sum()6]i^O S else N sum#sum("6]i^O S S itgl#sum61h&,-O printf1Pintegral value7fP!itgl-O getch1-O S "90 In1ut=,ut1ut/ Enter the values of a!b!n 1 " , Enter the value of % ) 9 * ; Enter the values of + 8 1 " Antegral value is 9.99999* 4oncluion/ .he program is error free 5I5A 6789ATI,N9 1$ 0efine Hinar search @ An/ Hinar search is a vast improvement over the sequential search. For binar search to wor5! the item in the list must be in assorted order. .he approach emploed in the binar search is divid and conquer. Af the list to be sorted for a specific item is not sorted! binar search fails. "91 A00ITI,NAL LAB 8DP8!IM8NT9 ,b-ecti.e &(/ Write a c program for heap sort 0ecri1tion/ In this method! a tree structure caed heap is used. A heap is tpe of a binar tree. An ordered baanced binar tree is caed a min$heap where the vaue at the roo of an sub tree is ess than or equa to the vaue of either of its chidern. 2eap sort is basicall an improvement over the binar tree sort.
Algorithm/ ;ea1 ort SWA= FJCC.AKC 1. start ". assign 6a to temp ,. assign 6b to 6a ). assign temp to 6b 9. stop 2EA= SKB. 1. start ". assign n to i and a]n^ to item ,. if i M 1 and a]i&"^? item repeat through step ) other wise goto step 9 begin ). assign a]i&"^ to a]i^ and i&" to i end if 9. assign item to a]i^ *. stop "9" 2lo3chart/
"9, Program/ Linclude?stdio.hM int a]"0^O main1- N int n!iO clrscr1-O printf1PEnter number of elements: P-O scanf1P7dP!Rn-O printf1PEnter 7d elements: P!n-O for1i#1Oi?#nOi((- scanf1P7dP!Ra]i^-O heapsort1n-O printf1PSorted elements are: QnP-O for1i#1Oi?#nOi((- printf1P7,dP!a]i^-O getch1-O S heapsort1int n- N int tO while1nM1- N ma%heap1n-O t#a]1^O a]1^#a]n^O a]n^#tO n#n$1O S S ma%heap1int n- N int i!t!UO for1i#"Oi?#nOi((- N t#a]i^O U#iO while1a]U&"^?tRRUM1- N a]U^#a]U&"^O U#U&"O S a]U^#tO S S "9) In1ut=,ut1ut/ Enter number of elements: ) Enter ) elements: ", ) 1" + Sorted elements are: ) + 1" ", Enter number of elements: * Enter * elements: *; ", * )9 88 ;+ Sorted elements are: * ", )9 *; ;+ 88 Conclusion:
.he program is error free 5I5A 6789ATI,N9 1$ 0ra3bac" of the binar< tree : Ans: Additional space is required for building the tree "- .he comple%it of the heap sort algorithm @ An/ ,En og n$ "99 ,b-ecti.e &)/ Write a c program for selectioon sort 0ecri1tion/ .his is the simplest method of sorting. An this method! to sort the data in ascending order! the 0 th element is compared with all other eements. Af the 0 th element is found to be greater than the compared element then the are interchanged. Algorithm/ 1- Start "- AnitiliaIe the variables A!U!temp and arr]^ ,- Bead the loop and chec5 the condition. Af the condition is true print the arra elements and increment the A value. Else goto step ) )- Bead the loop and chec5 the condition. Af the condition true then goto ne%t loop. 9- Bead the loop and chec5 the condition. Af the condition true then goto if condition *- Af the condition if1arr]i^Marr]U^- is true then do the following steps i- temp#arr]i^ ii- arr]i^#arr]U^ iii- arr]U^#temp ;- increment the U value +- perform the loop operation for the displaing the sorted elements. 8- print the sorted elements 10- stop "9* satrt AnitialiIe the i!U!temp!arr]^ A#0 i(( A?#) =rint the arr]i^ elements A#0 i(( A?#, V#U(1 U(( V?#) Af arr]i^Marr]U^ .emp#arr]i^ Arr]i^#arr]U^ Arr]U^#temp =rint arr]i^ stop A#0 A(( A?#) 2L,# 4;A!T "9; Program/ Lincude?stdio.hM Lincude?conio.hM Toid main1- N Ant arr]9^#N"9!1;!,1!1,!"SO Ant A!U!tempO Clrscr1-O =rintf1Zselection sortQn[-O =rintf1ZQn arra before sorting:Qn[-O For1i#0Oi?#,Oi((- =rintf1Z7dQt!arr]i^[-O For1i#0Oi?#,Oi((- N For1U#U(1OU?#)OU((- N Af1arr]i^Marr]U^- N .emp#arr]i^O Arr]i^#arr]U^O Arr]U^#tempO S S "9+ S =rintf1ZQnQn arra after sortong:Qn[-O For1i#0Oi?#)Oi((- =rintf1Z7dQt[!arr]i^-O /etch1-O S Sampe input R output: 1- Section sort Arra before sorting: "9 1; ,1 1, " Arra after sorting: " 1, 1; "9 ,1 "- section sort Arra before sort "9 ,1 ,0 1" 1 Arra after sort 1 1" "9 ,0 ,1 Concusion: this program is error free 5I5A 6789ATI,N9 1- .he comple%it of the section sort algorithm @ Ans: K1n " - "- 1- 0rawbac5 of the binar tree @ Ans: Additional space is required for building the tree ,- .he comple%it of the heap sort algorithm @ Ans: K1n og n- "98