Sei sulla pagina 1di 98

1 Week 1 a) To find the sum of individual digits of a given number Description: Sum of the individual digits means adding

all the digits of a number Ex: 123 sum of digits is 1+2+3=6 Algorithm: Step 1: start Step 2: read n Step 3: initiali e the s=! Step ": if n#! goto Step $ Step %: if n&=! goto Step 6 else goto step $ Step 6: store n'1! value in p (dd p value to s (ssign n)1! value to n *oto Step % Step $: print s Step +:stop Flowchart: ST(,T

s=!

,E(2 1

T,-E

0. 1#!

.(/SE

3rint S

0. 1& =!

T,-E ST43 3=1'1!

S=S+3 1=1)1!

2 Program: 5in6lude#stdio7h8 main9) : int n;s;p< 6lrs6r9)< printf9=enter the vaue for n:>n=)< s6anf9='d=;?n)< s=!< if9n#!) printf9=The given number is not valid=)< else : @hile9n&=!) )A 6he6B the given value =! or not A) : p=n'1!< n=n)1!< s=s+p< C printf9=sum of individual digits is 'd=;s)< C get6h9)< C Output: 17Enter the value for n: 333 Sum of individual digits is D 27Enter the value for n: "$33 Sum of individual digits is 1$ 37 Enter the value for n: E111 The given number is not valid Conclusion : The program is error free VIVA QU !A"IO#!: 1) Fhat is the mean of sum of the individual digitsG (ns: Sum of the individual digits means adding ea6h digit in a number 2) Fhat is positive integerG (ns: if the integer value is grater than ero then it is 6alled positive integer 3) 2efine prepro6essor G (ns: Hefore 6ompiling a pro6ess 6alled prepro6essing is done on the sour6e 6ode bI a program 6alled the prepro6essor7

b) To print the .ibona66i series for 1 to n value Description ( fibona66i series is defined as follo@s The first term in the seJuen6e is ! The se6ond term in the seJuen6e is 1 The sub seJuent terms 1 found bI adding the pre6eding t@o terms in the seJuen6e .ormula: let t1;t2;KKKKtn be terms in fibina66i seJuen6e t1=!; t2=1 tn=tnE2+tnE1KK@here n82 algorithm: Step 1: start Step 2: initiali e the a=!; b=1 Step 3: read n Step ": if n== 1 print a go to step $7 else goto step % Step %: if n== 2 print a; b go to step $ else print a;b Step 6: initiali e i=3 i) if i#= n do as follo@s7 0f not goto step $ 6=a+b print 6 a=b b=6 in6rement 0 value goto step 69i)

Step $: stop

" Flowchart: ST(,T

(=!;b=1

,ead n True 0f n ==1 .alse

True 0f n ==2

.alse

4utput a

4utput a;b

4utput a;b

.alse

0=3

i++

0#=n

L = a+b

4utput

Stop
(=b H= 6

% Program: 5in6lude#stdio7h8 void main9) : int a;b;6;n;i< 6lrs6r9)< printf9=enter n value=)< s6anf9='d=;?n)< a=!< b=1< if9n==1) printf9='d=;a)< else if9n==2) printf9='d'd=;a;b)< else : printf9='d'd=;a;b)< ))/443 F0// ,-1 .4, 2 T0ME /ESS 01 SE,0ES (S TNESE F(S 3,01TE2 01 (2O(1LE for9i=3<i#=n<i++) : 6=a+b< printf9='d=;6)< a=b< b=6< C get6h9)< C C Output: 17 Enter n value : % !1 1 2 3 27 Enter n value : $ ! 1 1 2 3 % + 37 Enter n value : E6 ! 1 Conclusion : The program is error free VIVA QU !A"IO#!: 1$ What is Fi%onacci series & Ans: ( fibona66i series is defined as follo@s The first term in the seJuen6e is ! The se6ond term in the seJuen6e is 1 The sub seJuent terms 1 found bI adding the pre6eding t@o terms in the seJuen6e .ormulae : let t1;t2;KKKKtn be terms in fibina66i seJuen6e t1=!; t2=1 tn=tnE2+tnE1KK@here n82 2) Fhat are the various tIpes of un6onditional statementsG (ns: goto;HreaB and 6ontinue 3)Fhat are the various tIpes of 6onditional statementsG (ns: if ; if else ;s@it6h statements

6 6) To print a prime numbers up to 1 to n Description: 3rime number is a number @hi6h is exa6tlI divisible bI one and itself onlI Ex: 2; 3;%;$;KKK< Algorithm: Step 1: start Step 2: read n Step 3: initiali e i=1;6=! Step ":if i#=n goto step % 0f not goto step 1! Step %: initiali e P=1 Step 6: if P#=i do the follo@ing7 0f no goto step $ i)if i'P==! in6rement 6 ii) in6rement P iii) goto Step 6 Step $: if 6== 2 print i Step +: in6rement i Step D: goto step " Step 1!: stop

$ Flow chart:

Start

,ead n

false

0=1 0#=n 0++

false

Q = 1
Q#=i

Q++

false

true false
0f 0 ' P == !

0f fa6t==2 4utput i

true .a6t ++

stop

+ Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 void main9) : int n;i;fa6t;P< 6lrs6r9)< printf9=enter the number:=)< s6anf9='d=;?n)< for9i=1<i#=n<i++) : fa6t=!< ))TN0S /443 F0// LNELR ( 14 T4 HE 3,0ME 147 4, 14T7 for9P=1<P#=i<P++) : if9i'P==!) fa6t++< C if9fa6t==2) printf9=>n 'd=;i)< C get6h9 )< C Output: Enter the number : % 2 3 % Enter the number : 1! 2 3 % $ Enter the number : 12 2 3 % $;11 Conclusion : The program is error free VIVA QU !A"IO#!: 1$ What is prime num%er & Ans: 3rime number is a number @hi6h is exa6tlI divisible bI one and itself onlI 2)Fhat is an algorithmG (ns : ( step bI step pro6edure is 6alled algorithm 3)Fhat is flo@ 6hartG (ns: ( pi6torial representation an algorithm is 6alled a flo@ 6hart ")Fhat is programG (ns : ( 6olle6tion of statements is 6alled

Week ' a) To @rite a L program to 6al6ulate the follo@ing Sum7 Sum= x2)2&+x")"&Ex6)6&+x+)+&Ex1!)1!&
(lgorithm: 17 27 37 "7 0nput value of x sum = 17! sign = E1 ,epeat the follo@ing for i=2 to 1! @ith step 27 i7 nu=po@9x; i) ii7 de = fa6t 9i) iii7 term = nu)de iv7 term A= sign v7 sum += term vi7 signA=E1 %7 3rint sum 67 Stop7 (lgorithm for fa6t9) 91) 92) 93) 9") 9%) ,e6eive n value p=1 ,epeat for n times 9i = 1 to n) p = p A i7 ,eturn p7

1! .lo@6hart:

3rogram: 5in6lude#stdio7h8 5in6lude#6onio7h8 5in6lude#math7h8 main9) : float x; term; nu; de; sum=1< int fa6t9int n)< int i; n< int sign=E1< 6lrs6r9)< printf9=Enter the value of x:=)< s6anf9='f=; ?x)< for9i=2<i#=1!<i+=2) : nu=po@9x; i)<

11 de=fa6t9i)< term=nu)de< termA=sign< signA=E1< sum+=term< C printf9=Sum='f=;sum)< get6h9)< C int fa6t9int n) : int i; P< int p=1< for9i=1< i#=n< i++) pA=i< return9p)< C

Output: 17 Enter the value of x:" Sum=E"$7$3$!!! 27 Enter the value of x:2 Sum=E!7"$""+!

12

b) To find the roots of the Juadrati6 eJuation Description: 1ature of roots of Juadrati6 eJuation 6an be Bno@n from the Juadrant = b2E"a6 0f b2E"a6 8! then roots are real and uneJual 0f b2E"a6 =! then roots are real and eJual 0f b2E"a6 #! then roots are imaginarI Algorithm: Step 1: start Step 2: read the a;b;6 value Step 3: if 9bAbE"a6)8! then ,oot 1= 9Eb+ po@99bAbE"AaA6);!7%)))2Aa ,oot 2= 9EbEpo@99bAbE"AaA6);!7%)))2Aa Step ": if 9bAbE"a6)=! then ,oot1 = ,oot2 = Eb)92Aa) Step %: 4ther@ise 3rint 0maginarI roots7 *oto step $7 Step 6: print roots Step $: stop

13 Flowchart:
Start

,ead a;b;6

2 = po@9bAbE"AaA6);!7%

false
0f d 8 ! true 0f d== ! ,1 = 99Eb+2) ) 92Aa)) ,2 = 99EbE2) )92Aa)) ,1=Eb ) 92 A a ) ,2= Eb ) 92 A a) 4utput ,1; ,2 3rint imaginarI roots

Stop

1" Program: 5in6lude#stdio7h8 5in6lude#math7h8 void main9) : float a;b;6;r1;r2;d< 6lrs6r9)< printf9=Enter the values for eJuation:=)< s6anf9='f'f'f=;?a;?b;?6)< )A 6he6B the 6ondition A) if9a==!) printf9=Enter value should not be ero =)< else : d=bAbE"AaA6< )A 6he6B the 6ondition A) if9d8!) : r1=9Eb+sJrt9d))92Aa))< r2=9EbEsJrt9d))92Aa))< printf9=roots are real and uneJual>n=)< printf9='f>n'f>n=;r1;r2)< C else if9d==!) : r1=Eb)92Aa)< r2=Eb)92Aa)< printf9=roots are real and eJual>n=)< printf9=root='f>n=;r1)< printf9=root='f>n=;r2)< C else printf9=roots are imaginarI=)< C get6h9)< C Output: 17 Enter the values for eJuation: 1; 6; D ,oots are real and eJual ,oot= E37!!!! ,oot= E37!!!! 27 Enter the values for eJuation: 2; $; 6 ,oots are real and uneJual ,oot= E67$% ,oot= E$72% 37 Enter the values for eJuation: 1; 2; 3 ,oots are imaginarI Conclusion: The program is error free

1%

VIVA QU !A"IO#!: 1$ Fhat are various tIpes of loop statementsG (ns : Fhile; doE @hile; for loop statements ") Fhat is the differen6e bet@een @hile and doE@hile statementsG (ns: 0n @hile the 6ondition @ill be 6he6Bed first and then enter into a loop7 Hut in doE @hile the statements @ill be exe6uted first and then finallI 6he6B the Londition7 3) No@ to find the roots of Judratri6 eJutations G (ns: 1ature of roots of Juadrati6 eJuation 6an be Bno@n from the Juadrant = b2E"a6 0f b2E"a6 8! then roots are real and uneJual 0f b2E"a6 =! then roots are real and eJual 0f b2E"a6 #! then roots are imaginarI ") /ist out the L features G (ns: 3ortabilitI;flexibilitI; @ide a66eptabilitI et677;

16

Week ( a) The total distan6e travelled bI vehi6le in StS se6onds is given bI distan6e = ut+1)2at2 @here SuS and SaS are the initial velo6itI 9m)se67) and a66eleration 9m)se62)7 Frite L program to find the distan6e travelled at regular intervals of time given the values of SuS and SaS7 The program should provide the flexibilitI to the user to sele6t his o@n time intervals and repeat the 6al6ulations for different values of SuS and SaS7 Description: The total distan6e travelled bI vehi6le in StS se6onds is given bI distan6e = ut+1)2at2 @here SuS and SaS are the initial velo6itI 9m)se67) and a66eleration 9m)se62)7 Algorithm: Step 1:Start Step2 : ,ead t ;dt Step 3: Set i to 1 Step ":Set B to dt Step %: ,ead u;a Step 6: set s to uAB+!7%AdABAB Step $: Frite s Step +: 0f9B#=t) and i=1 then Hegin Step +71 go to step 6 (nd Else Hegin Step +72 :read Step +73 :if9P=!) then Hegin Step +7371:Set 0 to ! End Else Hegin Step +7372: Set 0 to 1 Step +7373: go to step " End Step D: Stop Step 1!: End

1$ Flowchart:

1+ Program: 5in6lude#stdio7h8 main9) : int a;u;t;t1;t2;i< float s< 6lrs6r9)< printf9=E1TE, TNE O(/-ES 4. a;u;t;t1;t2:=)< s6anf9='d'd'd'd'd=;?a;?u;?t;?t1;?t2)< for9i=t1<i#=t2<i=i+t) )) performing the looping operation for time intervals : s=9uAi)+9!7%AaAiAi)< )) 6al6ulate the total distan6e printf9=>n>nthe distan6e travelled in 'd se6onds is 'f =;i;s)< C get6h9)< C Input)Output: 17E1TE, TNE O(/-ES 4. a;u;t;t1;t2:1 2 3 1 % the distan6e travelled in 1 se6onds is 27%!!!!! the distan6e travelled in " se6onds is 167!!!!!! 27E1TE, TNE O(/-ES 4. a;u;t;t1;t2:! 1 2 3 " the distan6e travelled in 3 se6onds is 37!!!!!! conclusion: The program is error free VIVA QU !A"IO#!: 1) No@ manI tIpes of arraIs are there G (ns: Three tIpes7 TheI are one dimensional ;t@o dimensional and multi dimensional arrIs

1D %$ T@o integer operands and one operator form user; performs the operation and then prints the result7 9Lonsider the operators +;E;A; ); ' and use S@it6h Statement) Description: To taBe the t@o integer operands and one operator from user to perform the some arithmeti6 operations bI using the follo@ing operators liBe +;E;A; ); ' Ex: 2+3=% Algorithm: Step 1: Start Step 2: ,ead the values of a;b and operator Step 3: if the operator is T+U then ,=a+b *o to step + HreaB Step ": Else if the operator is TET then ,=aEb *o to step + Step %: Else if the operator is TAT then ,=aAb *o to step + Step 6: Else if the operator is T)T then ,=a)b *o to step + Step $: Else if the operator is T'T then ,=a'b *o to step + Step +: @rite , Step D:End

2! Flowchart:

21 Program: 5in6lude#stdio7h8 main9) : 6har op< float a;b;6< 6lrs6r9)< printf9=enter t@o operands:=)< s6anf9='d'd=;?a;?b)< printf9=enter an operator:=)< s6anf9= '6=;?op)< s@it6h9op) )) used to sele6t parti6ular 6ase from the user : 6ase S+S:printf9=sum of t@o numbers '2d '2d is: 'd=;a;b;a+b)< breaB< 6ase SES:printf9=subtra6tion of t@o numbers '2d '2d is: 'd=;a;b;aEb)< breaB< 6ase SAS:printf9=produ6t of t@o numbers '2d '2d is: 'd=;a;b;aAb)< breaB< 6ase S)S:printf9=Juotient of t@o numbers '2d '2d is: 'd=;a;b;a)b)< breaB< 6ase S'S:printf9=reminder of t@o numbers '2d '2d is: 'd=;a;b;6)< breaB< default:printf9=please enter 6orre6t operator=)< breaB< C get6h9)< C Input)Output: 17enter t@o operands:2 3 enter an operator:+ sum of t@o numbers 2 3 is: % 27enter t@o operands:3 " enter an operator: E subtra6tion of t@o numbers 3 " is: E1 37enter t@o operands:3 % enter an operator:A produ6t of t@o numbers 3 % is: 1%

22 "7enter t@o operands:% 2 enter an operator:) Juotient of t@o numbers % 2 is: 2 %7 enter t@o operands:% 2 enter an operator:' reminder of t@o numbers % 2 is: 1 conclusion: The program is error free

VIVA QU !A"IO#!: 1) Fhat are the various tIpes of arithemeti6 operators G (ns: addition 9+); multipli6ation9A); subtra6tion 9E); division9)) ; modulo9')7 2) Fhat are the tIpes of relational operators G (ns: less than9#); grater than98); less than or eJual to9#=);eJual to9==); et677; 3) 3) Fhat are the tIpes of logi6al operators G (ns: logi6al (12 9??); logi6al 4,9VV); logi6al 14T9&)

23 Week *
b) OerifIing a string for its palindrome propertI7

Description: ,ead a string; 6ompare first and last 6hara6ters of a string; if eJual 6ontinue up to middle of the string7 0f the 6omparison fails at anI 6hara6ter the string is not a palindrome other@ise palindrome propertI satisfies7 Description: Algorithm: Step 1:start Step 2: read the string Step 3: store reverse of the given string in a temporarI string Step ": 6ompare the t@o strings Step %: if both are eJual then print palindrome Step 6: other@ise print not palindrome Step $: stop

2"

Flow chart:

Start

,ead string

0spalindrome9string)

true 3rint not palindrome 0f90spalindro me9string) 3rint palindrome

Stop

2%

0spalindrome9 )

Enum Hoolean mat6hed= true

0f len== !

,eturn !

/eft = !

,ight=lenE1

if9left#right? ?mat6hed 0f9stringWleftX& =stringWrightX) true /eft ++ ,ight EE Mat6hed=false

,eturn mat6hed ,eturn to main program

26 Program: enum Hoolean:false;trueC< enum Hoolean 0s3alindrome96har stringWX) : int left;right;len=strlen9string)< enum Hoolean mat6hed=true< if9len==!) return !< left=!< right=lenE1< )A Lompare the first and last letter;se6ond ? se6ond last ? so on A) @hile9left#right??mat6hed) : if9stringWleftX&=stringWrightX) mat6hed=false< else : left++< rightEE< C C return mat6hed< C int main9) : 6har stringW"!X< 6lrs6r9)< printf9=AAAA3rogram to test if the given string is a palindromeAAAA>n=)< printf9=Enter a string:=)< s6anf9='s=;string)< if90s3alindrome9string)) printf9=The given string 's is a palindrome>n=;string)< else printf9=The given string 's is not a palindrome>n=;string)< get6h9)< C Output: 17 Enter the string:malaIalam The given string malaIalam is a palindrome 27 Enter the string:india The given string india is not a palindrome Conclusion: The program is error free VIVA QU !A"IO#!: 1) Fhat is meant bI palindrome G (ns: 0f the reverse of a string)number is eJual to original string) number then it is 6alled palindrome7 2) Fhat is the use of gets9) fun6tion G (ns: To read the string at a time 3) Fhat is the use of puts9) fun6tion G (ns: To @rite the string at a time

2$ a) .un6tions to insert a sub string into given main string from a given position

Description: in this program @e need to insert a string into another string from a spe6ified position7 Algorithm: Step 1: start Step 2: read main string and sub string Step 3: find the length of main string9r) Step ": find length of sub string9n) Step %: 6opI main string into sub string Step 6: read the position to insert the sub string9 p) Step $: 6opI sub string into main string from position pE1 Step +: 6opI temporarI string into main string from position p+nE1 Step D: print the strings Step 1!: stop

2+

Flow chart:

Start

,ead the strings ( ? H

0=!

0#r

LWiX = (WiX

0 ++

S=n+r 4=p+n 0 =p 0#s 0++ H

Y= LWiX

0f t # n

2D

H ( (WiX = HWtX

T=t+1

(WoX=x

4=o+1

3rint output

Stop

3! Program: 5in6lude #stdio7h8 5in6lude #6onio7h8 5in6lude #string7h8 void main9) : 6har aW1!X< 6har bW1!X< 6har 6W1!X< int p=!;r=!;i=!< int t=!< int x;g;s;n;o< 6lrs6r9)< puts9=Enter .irst String:=)< gets9a)< puts9=Enter Se6ond String:=)< gets9b)< printf9=Enter the position @here the item has to be inserted: =)< s6anf9='d=;?p)< r = strlen9a)< n = strlen9b)< i=!< )) LopIing the input string into another arraI @hile9i #= r) : 6WiX=aWiX< i++< C s = n+r< o = p+n< )) (dding the subEstring for9i=p<i#s<i++) : x = 6WiX< if9t#n) : aWiX = bWtX< t=t+1< C aWoX=x< o=o+1< C printf9='s=; a)< get6h9)< C

31

Output: 17enter first string: 6omputer 27enter se6ond string: ge6 37enter the position @here the item has to be inserted:3 6omge6puter conclusion : the program is error free VIVA QU !A"IO#!: 1) Fhat is string G (ns: ( string is an 6olle6tion of 6hara6ters 2) Fhi6h 6ommand is used to 6ombined the t@o strings G (ns: Str6at9) 3) Fhi6h 6ommand is used to 6opI the strings G (ns: HI using the str6pI9) fun6tion 6opies one string to another

32 %$ To delete n 6hara6ters from a given position in a given string Description: I n this program @e need to delete a string from the given string at a spe6ified position7 Algorithm: Step 1: start Step 2: read string Step 3: find the length of the string Step ": read the value of number of 6hara6ters to be deleted and positioned Step %: string 6opI part of string from position to end; and 9position+number of 6hara6ters to end) Step 6: stop
Flow chart: Start

,ead string ,ead position; no of 6hara6ters

2el6har9 string; n; pos)

Stop

Subprogram 2el6har9 )

0f 99a+bE 1Z#= strlen9x))

Str6pI9?xWbE1X;?xWa+bE1X) 3uts9x)

,eturn to mainprogram

33 Program: 5in6lude #stdio7h8 5in6lude #6onio7h8 5in6lude #string7h8 void del6har96har Ax;int a; int b)< void main9) : 6har stringW1!X< int n;pos;p< 6lrs6r9)< puts9=Enter the string=)< gets9string)< printf9=Enter the position from @here to delete=)< s6anf9='d=;?pos)< printf9=Enter the number of 6hara6ters to be deleted=)< s6anf9='d=;?n)< del6har9string; n;pos)< get6h9)< C )) .un6tion to delete n 6hara6ters void del6har96har Ax;int a; int b) : if 99a+bE1) #= strlen9x)) : str6pI9?xWbE1X;?xWa+bE1X)< puts9x)< C C Output: 17enter the string nagaraPu Enter the position from @here to delete:" Enter the number of 6har6ters to be deleted3 nagPu 27 enter the string BaliraPu Enter the position from @here to delete:! Enter the number of 6har6ters to be deleted" ,aPu Conclusion: the program is error free VIVA QU !A"IO#!: 1) Fhi6h 6ommand is used to delete the strings G (ns: delstr9)< 2) Fhat are the various tIpes of string fun6tions G (ns: Str6at9); str6pI9); delstr9); substr9) ;strlen9)et677;

3"

Week 11
To read the t@o 6omplex numbers and perform the addition and multipli6ation of these t@o numbers7 Description: 0n this program the 6omplex number means it 6ontains the t@o parts 7 first one is real part and se6ond one is imaginarI part92+3i)7bI taBing these t@o 6omplex numbers @e 6an perform the addition and multipli6ation operation7 Algorithm: Step 1: Start Step 2: de6lare stru6ture for 6omplex numbers Step 3: read the 6omplex number Step ": read 6hoi6e Step %: if 6hoi6e=1 then addition operation @ill perform and it 6ontains follo@ing steps i) @7realpart = @17realpart+@27realpart< ii) @7imgpart = @17imgpart+@27imgpart< goto step " Step 6: if 6hoi6e=2 then multipli6ation operation @ill perform and it 6ontains follo@ing steps i) @7realpart=9@17realpartA@27realpart)E9@17imgpartA@27imgpart)< ii) @7imgpart=9@17realpartA@27imgpart)+9@17imgpartA@27realpart)< goto step " Step $: if 6hoi6e=! then exit operation @ill perform Step +:if @7imgpart8! then print realpart+imgpart else 3rint realpart7 Step D: Stop

3%

Flow chart:

Start 2e6lare stru6ture

,ead option false 0f option=9add or mul) true ,ead real part of first number image part of first number ,ead real part of se6ond number image part of se6ond number

false 0f option=ad d @7realpart=@17realpart+@27realpart @7imgpart=@17imgpart+@27imgpart 0f option=mu l @7realpart=9@17realpartA@27realpart) @7imgpart=9@17imgpartA@27imgpart) 3rint real part

false 0f @7imgpart8 ! true 3rint @7realpart+@7img part i Stop

36 Program: 5in6lude#stdio7h8 5in6lude#math7h8 void arithmeti69int opern)< stru6t 6omp : double realpart< double imgpart< C< void main9) : int opern< 6lrs6r9)< printf9=>n>n >t>t>tAAAAA M(01 ME1- AAAAA=)< printf9=>n>n Sele6t Iour option: >n 1 : (22>n 2 : M-/T03/[>n ! : EY0T >n>n>t>t Enter Iour 4ption W X>b>b=)< s6anf9='d=;?opern)< if9opern82) : printf9=invalid option=)< C else : s@it6h9opern) : 6ase !: exit9!)< 6ase 1: 6ase 2: arithmeti69opern)< default: main9)< C C get6h9)< C void arithmeti69int opern) : stru6t 6omp @1; @2; @< printf9=>n Enter t@o Lomplex 1umbers 9x+iI):>n ,eal 3art of .irst 1umber:=)< s6anf9='lf=;?@17realpart)< printf9=>n 0maginarI 3art of .irst 1umber:=)< s6anf9='lf=;?@17imgpart)< printf9=>n ,eal 3art of Se6ond 1umber:=)< s6anf9='lf=;?@27realpart)< printf9=>n 0maginarI 3art of Se6ond 1umber:=)< s6anf9='lf=;?@27imgpart)< s@it6h9opern) :

3$ )Aaddition of 6omplex numberA) 6ase 1: @7realpart = @17realpart+@27realpart< @7imgpart = @17imgpart+@27imgpart< breaB< )Amultipli6ation of 6omplex numberA) 6ase 2: @7realpart=9@17realpartA@27realpart)E9@17imgpartA@27imgpart)< @7imgpart=9@17realpartA@27imgpart)+9@17imgpartA@27realpart)< breaB< C if 9@7imgpart8!) printf9=>n (ns@er = 'lf+'lfi=;@7realpart;@7imgpart)< else printf9=>n (ns@er = 'lf'lfi=;@7realpart;@7imgpart)< get6h9)< main9)< C Output: AAAAA M(01 ME1- AAAAA Sele6t Iour option: 1 : (22 2 : M-/T03/[ ! : EY0T Enter Iour 4ption W 1X Enter t@o Lomplex 1umbers 9x+iI): ,eal 3art of .irst 1umber:2 0maginarI 3art of .irst 1umber:2 ,eal 3art of Se6ond 1umber:2 0maginarI 3art of Se6ond 1umber:2 (ns@er = "7!!!!!!+"7!!!!!!i AAAAA M(01 ME1- AAAAA Sele6t Iour option: 1 : (22 2 : M-/T03/[ ! : EY0T Enter Iour 4ption W 2X

3+ Enter t@o Lomplex 1umbers 9x+iI): ,eal 3art of .irst 1umber:2 0maginarI 3art of .irst 1umber:2 ,eal 3art of Se6ond 1umber:2 0maginarI 3art of Se6ond 1umber:2 (ns@er = !7!!!!!!++7!!!!!!i AAAAA M(01 ME1- AAAAA Sele6t Iour option: 1 : (22 2 : M-/T03/[ ! : EY0T Enter Iour 4ption W 3X invalid option AAAAA M(01 ME1- AAAAA Sele6t Iour option: 1 : (22 2 : M-/T03/[ ! : EY0T Enter Iour 4ption W !X Conclusion: The program is error free VIVA QU !A"IO#!: 1) 2efine stru6ture G (ns: Stru6ture is amethod for pa6Bing data of different tIpes7 Stru6ture help to organi e 6omplex data in a more meaninigful @aI7 2) Fhat is use of #math7h8 header file G (ns: 0t is used to a66ess the mathemati6al fun6tions in programs7

3D Week + b) i) To perform the addition of t@o matri6es ii) multipli6ation of t@o matri6es bI 6he6Bing 6ompatabilitI7 Description: program taBes the t@o matrixes of same si e and performs the addition an also taBes the t@o matrixes of different si es and 6he6Bs for possibilitI of multipli6ation and perform multipli6ation if possible7 algorithm: Step 1: start Step 2: read the si e of matri6es (;H \ m;n Step 3: read the elements of matrix ( Step ": read the elements of matrix H Step %: sele6t the 6hoi6e for Iou @ant7 0f Iou sele6t 6ase 1 then goto matri6 addition7 Else goto Step $7 Step 6: print Sum of matrix ( and H Step $: if Iou sele6t 6ase 2 then goto matrix multipli6ation Step +: 6he6B if n=p; if not print matri6es 6an not be multiplied Step D: 4ther@ise perform the multipli6ation of matri6es Step 1!: 3rint the resultant matrix Step 11: Stop

"!

Flow chart:

start

2e6lare aWXWX;bWX WX;6WX WX;6h;0;P;B;m;n;p;J;r1; 61 ,ead the 6hoi6e 6h

0f 6h#=2 ?6h8!

Lase 1

3rintvalid 6hoi6e

Lase 2
S@it6h 6h ,ead the si e of ( matrix m;n 0=! i++ 0# r1 i++

,ead the si e of (;H matrix m;n 0=! 0# r1

P=! Q=! P0# 61 Pi++ P#61 P++

,ead (WiXWPX

,ead (WiXWPX

0=! 0# r1 i++

,ead si e of matrix H: p7J

0=! P=! P0#61 P++ 0# p i++

H
,ead HWiWPX

"1

( H
0=! 0# r1 i++ P=! P# J P=! P# 61 P++ ,ead HWiXWPX P++

3rint (WiXWPX+HWiX WPX Matrix 6annot be mutiplied

0f n==p i=! i#m i++

Stop

P=! P# J P++

LWiXWPX=!

B! P# n B++

3rint LWiXWPX
LWiXWPX=LWiXWPX+(WiXWBXAHWBXWPX

P=! P#J P++

i=! i#m P++ i++

"2 Program: 5in6lude#stdio7h8 void main9) : int 6h;i;P;m;n;p;J;B;r1;61;aW1!XW1!X;bW1!XW1!X;6W1!XW1!X< 6lrs6r9)< printf9=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=)< printf9=>n>t>tME1-=)< printf9=>nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=)< printf9=>nW1X(220T041 4. TF4 M(T,0LES=)< printf9=>nW2XM-/T03/0L(T041 4. TF4 M(T,0LES=)< printf9=>nW!XEY0T=)< printf9=>nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=)< printf9=>n>tEnter Iour 6hoi6e:>n=)< s6anf9='d=;?6h)< if96h#=2 ? 6h8!) : printf9=Oalid Lhoi6e>n=)< C s@it6h96h) : 6ase 1: printf9=0nput ro@s and 6olumns of ( ? H Matrix:=)< s6anf9='d'd=;?r1;?61)< printf9=Enter elements of matrix (:>n=)< for9i=!<i#r1<i++) : for9P=!<P#61<P++) s6anf9='d=;?aWiXWPX)< C printf9=Enter elements of matrix H:>n=)< for9i=!<i#r1<i++) : for9P=!<P#61<P++) s6anf9='d=;?bWiXWPX)< C printf9=>n =====Matrix (ddition=====>n=)< for9i=!<i#r1<i++) : .or9P=!<P#61<P++) printf9='%d=;aWiXWPX+bWiXWPX)< printf9=>n=)< C breaB< 6ase 2:

"3 printf9=0nput ro@s and 6olumns of ( matrix:=)< s6anf9='d'd=;?m;?n)< printf9=0nput ro@s and 6olumns of H matrix:=)< s6anf9='d'd=;?p;?J)< if9n==p) : printf9=matri6es 6an be multiplied>n=)< printf9=resultant matrix is 'dA'd>n=;m;J)< printf9=0nput ( matrix>n=)< readZmatrix9a;m;n)< printf9=0nput H matrix>n=)< )A.un6tion 6all to read the matrixA) readZmatrix9b;p;J)< )A.un6tion for Multipli6ation of t@o matri6esA) printf9=>n =====Matrix Multipli6ation=====>n=)< for9i=!<i#m<++i) for9P=!<P#J<++P) : 6WiXWPX=!< for9B=!<B#n<++B) 6WiXWPX=6WiXWPX+aWiXWBXAbWBXWPX< C printf9=,esultant of t@o matri6es:>n=)< @riteZmatrix96;m;J)< C )Aend ifA) else : printf9=Matri6es 6annot be multiplied7=)< C )Aend elseA) breaB< 6ase !: printf9=>n Lhoi6e Terminated=)< exit9)< breaB< default: printf9=>n 0nvalid Lhoi6e=)< C get6h9)< C )A.un6tion read matrixA) int readZmatrix9int aW1!XW1!X;int m;int n) : int i;P< for9i=!<i#m<i++)

"" for9P=!<P#n<P++) s6anf9='d=;?aWiXWPX)< return !< C )A.un6tion to @rite the matrixA) int @riteZmatrix9int aW1!XW1!X;int m;int n) : int i;P< for9i=!<i#m<i++) : for9P=!<P#n<P++) printf9='%d=;aWiXWPX)< printf9=>n=)< C return !< C Output: 17 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ME1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA W1X(220T041 4. TF4 M(T,0LES W2XM-/T03/0L(T041 4. TF4 M(T,0LES W!XEY0T AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Enter Iour 6hoi6e: 1 Oalid Lhoi6e 0nput ro@s and 6olumns of ( ? H Matrix:2 2 Enter elements of matrix (: 2 2 2 2 Enter elements of matrix H: 2 2 2 2 =====Matrix (ddition===== " " " " AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ME1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA W1X(220T041 4. TF4 M(T,0LES W2XM-/T03/0L(T041 4. TF4 M(T,0LES W!XEY0T

"% AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Enter Iour 6hoi6e:2 Oalid Lhoi6e 0nput ro@s and 6olumns of ( matrix:2 3 0nput ro@s and 6olumns of H matrix:2 2 Matri6es 6annot be multiplied7 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA ME1AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA W1X(220T041 4. TF4 M(T,0LES W2XM-/T03/0L(T041 4. TF4 M(T,0LES W!XEY0T AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA Enter Iour 6hoi6e:2 Oalid Lhoi6e 0nput ro@s and 6olumns of ( matrix:2 2 0nput ro@s and 6olumns of H matrix:2 2 matri6es 6an be multiplied resultant matrix is 2A2 0nput ( matrix 2 2 2 2 0nput H matrix 2 2 2 2 =====Matrix Multipli6ation===== ,esultant of t@o matri6es: + + + + Conclusion : The program is error free VIVA QU !A"IO#!: 1) Fhat is 6ondition for performing an matri6 addition G (ns: program taBes the t@o matrixes of same si e and performs the addition 2) Fhat is 6ondition for performing an matri6 addition G (ns: The t@o matrixes of different si es and 6he6Bs for possibilitI of multipli6ation and perform multipli6ation if possible

"6 Week , a) i) 3rograms that use re6ursive fun6tion to find the fa6torial of a given integer7 Description: .a6torial of a number is nothing but the multipli6ation of numbers from a given number to 1 Algorithm: main program Step 1: start Step 2: read n Step 3: 6all sub program as f=fa6t9n) Step ": print f value Step %: stop !u% program: Step 1: initiali e the f Step 2: if n= = ! or n == 1 return 1 to main program if not goto step 3 Step 3: return nAfa6t9nE1) to main program

"$

Flowchart:

Start

,ead n

Lall subprogram . = fa6t9n)

4utput .

Stop

!u% program
.a6t 9)

0f n=! VV n=1

false

true

,eturn nAfa6t9nE1)

,eturn to main program

"+ Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 int fa6t9int n) : int f< if99n==!)VV9n==1)) )) 6he6B the 6ondition for the n value return9n)< else f=nAfa6t9nE1)< ))6al6ulate the fa6torial of n return9f)< C void main9) : int n< 6lrs6r9)< printf9=enter the number :=)< s6anf9='d=;?n)< printf9=fa6toria of number'd=;fa6t9n))< get6h9)< C Output: 17 Enter the number : % .a6torial of number: 12! 27 Enter the number : 3 .a6torial of number: 6 37 Enter the number : D .a6torial of number: E3!336 Conclusion: the program is error free VIVA QU !A"IO#!: 1) Fhat is the meaning of fa6torial numberG Ans : .a6torial of a number is nothing but the multipli6ation of numbers from a given number to 1 2) Fhat is the meaning of re6usive fun6tion G (ns: ( fun6tion 6all it self is 6alled re6ursive fun6tion 3) define librarI fun6tions G (ns: The fun6tions have alreadI been @ritten; 6ompiled and pla6ed in libraries and are 6alled librarI fun6tions7 ") 2efine formal parameters G (ns: .ormal parameters are the parameters given in the fun6tion de6laration ans fun6tion definition7

"D a$ ii$ 3rogram that use non re6ursive fun6tion to find the fa6torial of a given integer7 Description: .a6torial of a number is nothing but the multipli6ation of numbers from a given number to 1 Ex: %& =%A"A3A2A1= 12! Algorithm: main program Step 1: start Step 2: read n Step 3: 6all the sub program fa6t9n) Step ": print the f value Step %: stop !u% program: Step 1: initiali e the f=1 Step 2: if n==! or n=1 return 1 to main program7 0f not goto step 3 Step 3: perform the looping operation as follo@s .or i=1 i#=n< i++ Step ": f=fAi Step %: return f value to the main program

%! Flowchart: Factorial nonrecursi-e

start

,ead i

Lall subprogram .a6t9n)

3rint output Oalue of fa6t

Stop

!u% program
.a6t 9 )

. = 1; i

0f n == ! VV n == 1

0=1

i++

0#=n

,eturn to main program

.=fAi

%1 Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 int fa6t9int n) ))starting of the sub program : int f=1;i< if99n==!)VV9n==1)) )) 6he6B the 6ondition for n value return91)< else for9i=1<i#=n<i++) )) perform the looping operation for 6al6ulating the fa6torial f=fAi< return9f)< C void main9) : int n< 6lrs6r9)< printf9=enter the number :=)< s6anf9='d=;?n)< printf9=fa6toria of number'd=;fa6t9n))< get6h9)< C Output: 17Enter the number: $ .a6torial of number: %!"! 27 Enter the number: 6 .a6torial of number: $2! 37 Enter the number: + .a6torial of number: E2%216 Conclusion: The program is error free VIVA QU !A"IO#!: 1) Fhat is meant bI 6all bI value G (ns: passing values to the fun6tion as arguments 2) Fhat is meant bI 6all bI referen6e G (ns: passing address to the fun6tion as arguments 3)define a6tual parameters G (ns: The a6tual parameters often Bno@n as arguments are spe6ified in the fun6tion 6all7

%2 Week , b) i) To find the *L2 of t@o given integers bI using the re6ursive fun6tion Description: *L2 means *reatest Lommon 2ivisor7 i7e the highest number @hi6h divides the given number Ex: *L2912;2") is 12 .ormula: *L2= produ6t of numbers) /LM of numbers Algorithm: main program Step 1: start Step 2: read a;b Step 3: 6all the sub program *L29a;b) for print the value Step ": stop !u% program: Step 1: if n8m return *L29n;m) Step 2: if n==! return m else goto step 3 Step 3: return *L2 9n;m'n) Step ": return to main program

%3

Flowchart:
Start

,ead a;b

Lall sub program *=g6d9a;b) 3rint g6dvalue

Stop

*6d9 )

false
0f n8m true 0f n==! ,eturn m Lall the same fun6tion ,eturn g6d 9 n;m'n)

true

,eturn *6d 9n;m)

,eturn to main program

%" Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 int g6dre6ursive9int m;int n) )) starting of the sub program : if9n8m) return g6dre6ursive9n;m)< if9n==!) return m< else return g6dre6ursive9n;m'n)< )) return to the main program C void main9) : int a;b;ig6d< 6lrs6r9)< printf9=enter the t@o numbers @hose g6d is to be found:=)< s6anf9='d'd=;?a;?b)< printf9=*L2 of a;b is 'd=;g6dre6ursive9a;b))< )) return to the sub program get6h9)< C Output: 17 enter the t@o numbers @hose g6d is to be found:%;2% *L2 of a;b is : % 27 enter the t@o numbers @hose g6d is to be found:36;%" *L2 of a;b is : 1+ 37 enter the t@o numbers @hose g6d is to be found:11;13 *L2 of a;b is : 1 Conclusion: The program is error free VIVA QU !A"IO#!: 1) Fhat is meaning of *L2 G (ns: *L2 means *reatest Lommon 2ivisor7 i7e the highest number @hi6h divides the given number 2) 2efine s6ope of a variable G (ns: The s6ope of a variable 6an be define as the region over @hi6h the variable is a66essible 3) Sho@ an s6ope resolution operator G (ns: double 6olon9::) ") 2efine extent of a variable G (ns: The period of time during @hi6h memorI is asso6iated @ith a variable is 6alled extent of the variable7

%% %$ ii$ To find the *L2 of t@o given integers bI using the non re6ursive fun6tion Description: *L2 means *reatest Lommon 2ivisor7 i7e the highest number @hi6h divides the given number Ex: *L2912;2") is 12 .ormula: *L2= produ6t of numbers) /LM of numbers Algorithm: Step 1: start Step 2: read a;b Step 3: 6all sub program g=*L29a;b) Step ": print the g value Step %: stop Sub program: Step 1: initiali e the p=1; J; remainder Step 2: remainder=pE9p)JAJ) Step 3: remainder=! return J else goto step " Step ": *L29J;remainder) return to main program

%6 Flowchart:
start

,ead a; b

Lall subprogram g=g6d9a;b)

4utput g

stop

*6d 9 )

,emainder=pE9p)JAJ)

false 0f remainder==!

True

*6d9J;remainder)

,eturn J

,eturn to main program

%$ Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 5in6lude#math7h8 int g6dnonre6ursive9int m;int n) : int remainder< remainder=mE9m)nAn)< if9remainder==!) return n< else g6dnonre6ursive9n;remainder)< C void main9) : int a;b;ig6d< 6lrs6r9)< printf9=enter the t@o numbers @hose g6d is to be found:=)< s6anf9='d'd=;?a;?b)< printf9=*L2 of 'd=;g6dnonre6ursive9a;b))< get6h9)< C Output: 17 enter the t@o numbers @hose g6d is to be found:%;2% *L2 of a;b is : % 27 enter the t@o numbers @hose g6d is to be found:36;%" *L2 of a;b is : 1+ 37 enter the t@o numbers @hose g6d is to be found:11;13 *L2 of a;b is : 1 Conclusion: The program is error free VIVA QU !A"IO#!: 1$Fhat is meaning of *L2 G (ns: *L2 means *reatest Lommon 2ivisor7 i7e the highest number @hi6h divides the given number

%+ c$ i$ To solve the to@ers of Nanoi problem bI using the re6ursive fun6tion Description: To@ers of Nanoi problem means @e have three to@ers

Sour6e

intermediate

destination

Nere sour6e ;intermediate and destination are the three to@ers7 Fe have to transfer all the disBs from sour6e to destination to@ers7 Nere the restri6tion is not to pla6e a big disB on smaller one 7 for this @e use intermediate to@er7 .inallI the arrangements in the destination to@er must be as same as the disBs in the sour6e to@er at first7 Algorithm: main program Step 1: start Step 2: initiali e the sour6e=a; intermediate=6; destination = d Step 3: read n Step ": 6all the sub program Nanoi re6ursion 9n value;a ;b; 6) Step %: stop Sub program: Step 1: if n== 1 6all the sub program Nanoi re6ursion 9numE1; a; 6; b) Step 2: print the output from a to b Step 3: 6all the sub program Nanoi re6ursion9numE1; b; 6; a) Step ": return to main program

%D Flowchart:
ST(,T

S4-,LE = ( 01TE,ME20(TE = L 2EST01(T041 = H

,E(2

Lall subprogram Nanoi9num;sour6e;intermediate;destination) (;L; H

Stop

hanoire6ursive9 )

false 0f num==1

true

Lall sbgroram 1umE1;sour6e ](^

3rint (;L

3rint (;L

Lall ubprogram Nanoi9numE1;H;L;())

,eturn to main program

Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 void Nanoire6ursion9int num;6har ndl1;6har ndl2;6har ndl3) :

6! if9num==1) : printf9=Move top disB from needle '6 to needle '6=;ndl1;ndl2)< return< C Nanoire6ursion9numE1;ndl1;ndl3;ndl2)< printf9=Move top dis from needle '6 to needlle '6=;ndl1;ndl2)< Nanoire6ursion9numE1;ndl3;ndl2;ndl1)< C void main9) : int no< 6lrs6r9)< printf9=Enter the no7 of disB to be transferred:=)< s6anf9='d=;?no)< if9no#1) printf9=>n ThereSs nothing to move=)< else printf9=>n re6ursive=)< Nanoire6ursion9no;S(S;SHS;SLS)< get6h9)< C Outputs: 17 Enter the no7 of disB to be transferred :3 Move top disB from needle a to needle b Move top disB from needle a to needle 6 Move top disB from needle b to needle 6 Move top disB from needle a to needle b Move top disB from needle 6 to needle a Move top disB from needle 6 to needle b Move top disB from needle a to needle b Conclusion: The program is error free VIVA QU !A"IO#!: 1$ What is purpose o. towers o. /anoi & Ans: Fe have to transfer all the disBs from sour6e to destination to@ers7 Nere the restri6tion is not to pla6e a big disB on smaller one 7 for this @e use intermediate to@er7 .inallI the arrangements in the destination to@er must be as same as the disBs in the sour6e to@er at first7

61 c$ ii$ To solve the to@ers of Nanoi problem bI using the non re6ursive fun6tion Description: To@ers of Nanoi problem means @e have three to@ers

Sour6e

intermediate

destination

Nere sour6e ;intermediate and destination are the three to@ers7 Fe have to transfer all the disBs from sour6e to destination to@ers7 Nere the restri6tion is not to pla6e a big disB on smaller one 7 for this @e use intermediate to@er7 .inallI the arrangements in the destination to@er must be as same as the disBs in the sour6e to@er at first7 Algorithm: Step 1: start Step 2: de6lare the no Step 3: read the no value Step ": if 9no#1) 3rint nothing to move Else 3rint nonre6ursion Step %:Nanoi non re6ursion9no;7(U;UHU;ULU) Step 6:stop Sub program: Step 1: 2e6lare num;sndl;indl;dndl; stBnW X;stBsndlW X;stBdndl W X;stBaddW X; temp;top;add Step 2: de6lare the top=1-// Step 3: one: 0f9num==1)then 3rint the out put value *oto four Step ": t@o: Top=top+1 StBnWtopX=num StBsndlWtopX=sndl StBindlWtopX=indl StBdndlWtopX=dndl StBaddWtopX=3 1um=numE1 Sndl=sndl Temp=indl 0ndl=dndl 2ndl=temp *oto one7 *oto step 3

62 Step %: Three: 3rint the output Top=top+1 StBnWtopX=num StBsndlWtopX=sndl StBindlWtopX=indl StBdndlWtopX=dndl StBaddWtopX=% 1um=numE1 temp=sndl sndl=indl 0ndl=temp 2ndl=dndl *oto one7 *oto step 3 Step 6: .our: 0f9top==1-//) ,eturn to main program 1um= stBnWtopX Sndl= stBsndlWtopX 0ndl= stBindlWtopX 2ndl=stBdndlWtopX (dd=stBaddWtopX Top=topE1 0f9add==3) *oto three7 *oto step % Else 0f9add==%) *oto four7 *oto step 67 Step $: return to main program

63 Flow chart:
Start

,ead no

false
0f no# 1

true
3rint nothing to move

3rint nonre6ursion

Nanoinonre6ursion 9no;7(U;UHU;ULU)

Stop

6"

Nanoi nonre6ursion 9 )

2e6lare num;sndl;indl;dndl; stBnW X;stBsndlW X;stBdndl W X;stBaddW X; temp;top;add

Top = 1-// one


0f num==1

true
3rint the value

t@o
Top=top+1 StBnWtopX=num StBsndlWtopX=sndl StBindlWtopX=indl StBdndlWtopX=dndl StBaddWtopX=3 1um=numE1 Sndl=sndl Temp=indl 0ndl=dndl 2ndl=temp 0f top=1-/ /

four

1um= stBnWtopX Sndl= stBsndlWtopX 0ndl= stBindlWtopX 2ndl=stBdndlWtopX (dd=stBaddWtopX Top=topE1

3rint value

Top=top+1 StBnWtopX=num StBsndlWtopX=sndl StBindlWtopX=indl StBdndlWtopX=dndl StBaddWtopX=% 1um=numE1 temp=sndl sndl=indl 0ndl=temp 2ndl=dndl Top=top+1

0f add==3

false

0f add== %

6% Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 void Nanoinonre6ursion9int num;6har sndl;6har indl;6har dndl) : 6har stBnW1!!X;stBsndlW1!!X;stBindlW1!!X;stBdndlW1!!X;stBaddW1!!X;temp< int top;add< top=1-//< one: if9num==1) : printf9=>n Move top disB from needle '6 to needle '6=;sndl;dndl)< goto four< C t@o: top=top+1< stBnWtopX=num< stBsndlWtopX=sndl< stBindlWtopX=indl< stBdndlWtopX=dndl< stBaddWtopX=3< num=numE1< sndl=sndl< temp=indl< indl=dndl< dndl=temp< goto one< three: printf9=>n Move top disB from needle '6 to needle '6=;sndl;dndl)< top=top+1< stBnWtopX=num< stBsndlWtopX=sndl< stBindlWtopX=indl< stBdndlWtopX=dndl< stBaddWtopX=%< num=numE1< temp=sndl< sndl=indl< indl=temp< dndl=dndl< goto one< four: if9top==1-//) return< num=stBnWtopX< sndl=stBsndlWtopX< indl=stBindlWtopX< dndl=stBdndlWtopX<

66 add=stBaddWtopX< top=topE1< if9add==3) goto three< else if9add==%) goto four< C void main9) : int no< 6lrs6r9)< printf9=Enter the no7 of diss to be transferred:=)< s6anf9='d=;?no)< if9no#1) printf9=>n ThereSs nothing to move=)< else printf9=>n nonre6ursive=)< Nanoinonre6ursion9no;S(S;SHS;SLS)< get6h9)< C Output: 17Enter the no7 of diss to be transferred:3 nonre6ursive Move top disB from needle ( to needle L Move top disB from needle ( to needle H Move top disB from needle L to needle H Move top disB from needle ( to needle L Move top disB from needle H to needle ( Move top disB from needle H to needle L Move top disB from needle ( to needle L Conclusion: The program is error freed VIVA QU !A"IO#!: 1$ What is purpose o. towers o. /anoi & Ans: Fe have to transfer all the disBs from sour6e to destination to@ers7 Nere the restri6tion is not to pla6e a big disB on smaller one 7 for this @e use intermediate to@er7 .inallI the arrangements in the destination to@er must be as same as the disBs in the sour6e to@er at first7 '$ What is an arra0 & (ns: (n arraI is a seJuen6e of memorI lo6ation of same data tIpe7

6$ Week + a) To find both the largest and smallest number in a list of integers Description: This program 6ontains n number of elements; in these elements @e 6an find the largest and smallest numbers and displaI these t@o numbers Algorithm: Step 1: start Step 2: read n Step 3: initiali e i=! Step ": if i#n do as follo@s7 0f not goto step % ,ead aWiX 0n6rement i *oto step " Step %: min=aW!X; max=aW!X Step 6: initiali e i=! Step $: if i#n do as follo@s7 0f not goto step + 0f aWiX#min (ssign min=aWiX 0n6rement i goto Step $ Step +: print min;max Step D: stop

6+

Flowchart:

Start

,ead n; aWiX;min;max;

Min = aW!X Max = aW!X

0= !

0#n

i++

,ead aWiX

false

0=! 0# n

i++ true false


max#min

true

false

min=aWiX (WiX8ma x true ax=aWiX

3rint min;max

stop

6D Program: 5in6lude#stdio7h8 void main9) : int aW1!X;i;n;min;max< 6lrs6r9)< printf9=enter the arraI si e:=)< s6anf9='d=;?n)< printf9=Enter the elements of arraI=)< for9i=!<i#n<i++) )) read the elements of an arraI s6anf9='d=;?aWiX)< min=aW!X< max=aW!X< for9i=!<i#n<i++))) read the elements of an arraI : if9aWiX#min))) 6he6B the 6ondition for minimum value min=aWiX< if9aWiX8max)))6he6B the 6ondition for maximum value max=aWiX< C printf9=maximum value is:'d>n=;max)< printf9=minimum value is:'d>n=;min)< get6h9)< C Output: 17enter the arraI si e:" Enter the elements of arraI 36 13 2 "% maximum value is:"% minimum value is:2 27enter the arraI si e:% Enter the elements of arraI 6 2 1 3 + maximum value is:+ minimum value is:1 37enter the arraI si e:% Enter the elements of arraIE6 D ED 2 % maximum value is:D minimum value is:ED conclusion: the program is error free VIVA QU !A"IO#!: 1$ Fhat is an arraI & (ns: The 6olle6tion of similar elements is 6alled arraI 2) No@ manI tIpes of arraIs are there G (ns: Three tIpes7 TheI are one dimensional ;t@o dimensional and multi dimensional arrIs

$! Week 1 a) 3rogram that displaIs the position or index in the string S @here the string T begins ; or E1 if S doesnUt 6ontain T Algorithm: Step 1: start Step 2: read the string and then displaIed Step 3: read the string to be sear6hed and then displaIed Step ": sear6hing the string T in string S and then perform the follo@ing steps i7 found=strstr9S;T) ii7 if found print the se6ond string is found in the first string at the position7 0f not goto step % Step %: print the E1 Step 6: stop

$1

Flow chart:

Start

0nitiali e sW X;tW X; found variables

,ead first string

2isplaI the string ,ead string to be sear6hed 2isplaI the string .ound=strstr9s;t) no 0f found 3rint E1 3rint the string .oundEs Ies

Stop

Program: 5in6lude#stdio7h8 5in6lude#string7h8 5in6lude#6onio7h8 void main9) : 6har sW3!X; tW2!X< 6har Afound< 6lrs6r9)< puts9=Enter the first string: =)< gets9s)< puts9=Enter the string to be sear6hed: =)<

$2 gets9t)< found=strstr9s;t)< if9found) printf9=Se6ond String is found in the .irst String at 'd position7>n=;foundEs)< else printf9=E1=)< get6h9)< C Output: 17enter the first string: Bali Enter the string to be seare6hed: li se6ond string is found in the first string at2position 27enter the first string: nagaraPu Enter the string to be seare6hed: raPu se6ond string is found in the first string at"position 37enter the first string: nagarPuna Enter the string to be seare6hed: ma E1 Conclusion: The program is error free VIVA QU !A"IO#!: 1) Fhat is the differen6e bet@een printf9) and puts9) G (ns: puts9) is used to displaI the string at a time and it doesnUt taBe anI integers values but printf9) taBes anI values as defined bI the user 2) define pointer variable G (ns: pointer variables are defined as variable that 6ontain the memorI addresses of data or exe6utable 6ode7 3) Fhat is use of the str6mp9) fun6tion G (ns: This fun6tion 6ompares t@o strings 6hara6ter bI 6hara6ter and returns a value ! if both strings are eJual and non ero value if the strings are different7

Week 1
b) To 6ount the lines;@ords ? 6har6ters in a given text

Description: 0n this program @e have to 6ount the no of lines; no of @ords and no of 6hara6ters in a given program or given text bI using the string fun6tion Algorithm: Step 1: Start Step 2: ,ead the text until an emptI line Step 3: Lompare ea6h 6hara6ter @ith ne@line 6har T>nU to 6ount no of lines

$3 Step ": Lompare ea6h 6hara6ter @ith tab 6har T>t>U or spa6e 6har T T to 6ount no of @ords Step %: Lompare first 6hara6ter @ith 1-// 6har T>!U to find the end of text Step 6: 1o of 6hara6ters = length of ea6h line of text Step $: 3rint no of lines; no of @ords; no of 6hars Step +: Stop

$"

Flow chart:

Start

0nitiali e end=!;6hars=!;@ords=!;lines=!

Fhile End== !

true

L=! false 0f 96tr=get6har9))& =U>nU true /ineW6++X=6tr true 0f lineW!X=U>! U 3rint lines; Fords;6hars 0=! 0 ++ stop 0f lineWiX==U TVV /ineWiX==U>tU Fords ++ /ines++ Lhars+=strlen9line) lineWiX&=U>!> Fords ++ /ineW6X=U>!U

false

$% Program: 5in6lude #stdio7h8 main9) : 6har lineW+1X; 6tr< int i;6; end = !; 6hara6ters = !; @ords = !; lines = !< printf9=RE[ 01 TNE TEYT7>n=)< printf9=*0OE 41E S3(LE (.TE, E(LN F4,27>n=)< printf9=FNE1 L4M3/ETE2; 3,ESS S,ET-,1S7>n>n=)< @hile9 end == !) : )A ,eading a line of text A) 6 = !< @hile996tr=get6har9)) &= S>nS) lineW6++X = 6tr< lineW6X = S>!S< )A 6ounting the @ords in a line A) if9lineW!X == S>!S) breaB < else : @ords++< for9i=!< lineWiX &= S>!S<i++) if9lineWiX == S S VV lineWiX == S>tS) @ords++< C )A 6ounting lines and 6hara6ters A) lines = lines +1< 6hara6ters = 6hara6ters + strlen9line)< C printf 9=>n=)< printf9=1umber of lines = 'd>n=; lines)< printf9=1umber of @ords = 'd>n=; @ords)< printf9=1umber of 6hara6ters = 'd>n=; 6hara6ters)< C Output 17RE[ 01 TNE TEYT7 *0OE 41E S3(LE (.TE, E(LN F4,27 FNE1 L4M3/ETE2; 3,ESS S,ET-,1S7 (dmiration is a verI shortElived passion7 (dmiration involves a glorious obliJuitI of vision7 (l@aIs @e liBe those @ho admire us but @e do not liBe those @hom @e admire7 .ools admire; but men of sense approve7 1umber of lines = % 1umber of @ords = 36

$6 1umber of 6hara6ters = 2!% Conclusion: The program is error free VIVA QU !A"IO#!: 1) Fhat is use of strlen9) G (ns: to read a string length 2) @hat is the use of get69) fun6tion G (ns: To read the 6hara6ter one bI one7 3) Fhat is the use of strstr 9) G (ns: The fun6tion strstr9) sear6hes one string for the o66urren6e of another7 0t a66epts t@o strings as parameters and sear6hes the first string for an o66urren6e of the se6ond

$$ Week 2 a) To generate 3as6alUs triangle Description: 3as6alUs triangle @hi6h is used for a 6oeffi6ient in the eJuation in polInominals7 Alogrithm: Step 1: Start Step 2: 0nitiali e m=! Step 3: ,ead n Step ": 0f m#n goto step %7if not goto step 12 Step %: initiali e i="!Em Step 6: 0f i8! is true do as follo@s7 0f not goto step $ i7 print @hite spa6e ii7 de6rement i iii7 goto Step 6 Step $: 0nitiali e P=! Step +: 0f P=m do as follo@s7 0f not goto Step 1! i) if9P==!VVm==!) ii) 0nitiali e b=1 if not b=bA9mEP+1))P iii) 3rint @hite spa6e; b 7 iv) *oto Step D Step D: in6rement P; goto Step + Step 1!: print ne@ line 6ontrol Step 11: in6rement m; goto step " Step 12: Stop

$+ Flow chart: Start ,ead p true

0=! 0++

0#p

,="!E0 r8!

rEE

false

false 3rint ne@lin e Y=! x#=i true true . 3rint @hite spa6e

Stop

Y++ true false 0f x==! VV 0==! H=bA9iEx+1))x

H=1

3tint b

$D Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 void main9) : int i;p;r;x;binom=1< 6lrs6r9)< printf9=enter the ho@ manI lines to print=)< s6anf9='d=;?p)< i=!< @hile9i#p) )) 6he6B the 6ondition : for9r="!Ei<r8!<rEE) )) perform the looping operation until ! printf9= =)< for9x=!<x#=i<x++) : if99x==!)VV9i==!)) )) 6he6B the 6ondition binom=1< else binom=binomA9iEx+1))x< printf9='d=;binom)< printf9= =)< C printf9=>n=)< i++< C get6h9)< C Output: 17enter the ho@ manI lines to print% 1 11 121 1331 1"6"1 27enter the ho@ manI lines to print3 1 11 121 Conclusion: the program is error free VIVA QU !A"IO#!: 1$ Fhat is meant bI 3as6alUs triangle G Ans: 3as6alUs triangle @hi6h is used for a 6oeffi6ient in the eJuation in polInominals 2)define stru6ture G (ns: ( stru6ture in 6 is a heterogenous user efined data tIpe7 ( stru6ture maI 6ontain different data tIpes70t groups variables into a single entitI7

+!

b) To 6onstru6t a pIramid of numbers Description: 0n this program the @e have to 6onstru6t output in the pIramid shape manner Algorithm: Step 1: Start Step2: initiali e the num;0;I; x=3% Step3: read the num Step":perform the loop operation .or9I=!<I#=num<I++) Step%:*otoxI9x;I+1) Step6: perform the loop operation for displaIing digits to@ards the left and right .or9i=!EI<i#=I<i++) Step$: print abs9i)< Step+: x=xE2< StepD: Stop Flow chart:
Start 0nitiali e num;0;I;x=3% ,ead num

[=! I ++

I#=num

true *otoxI9x;I+1)

0=! 0#=I

i++

Y=xE2

3rint abs9i)

Stop

+1

Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 void main9) : int num;i;I;x=3%< 6lrs6r9)< printf9=>nEnter the number to generate the pIramid:>n=)< s6anf9='d=;?num)< for9I=!<I#=num<I++) : )A9xE6oordinate;IE6oordinate)A) gotoxI9x;I+1)< )Afor displaIing digits to@ards the left and right of eroA) for9i=!EI<i#=I<i++) printf9='3d=;abs9i))< x=xE3< C get6h9)< C Output: 17enter the number: " ! 1!1 21!12 321!123 "321!123"

27enter the number: 3

! 1!1 21!12 321!123 Conclusion: The program is error free VIVA QU !A"IO#!: 1) Fhat is the use of dot operator in stru6tures G (ns: The use of dot93) operator to a66ess the members of a stru6ture independentlI7 The dot operator 6onne6ts a member @ith the stru6ture variable7 2) 2efine unions G (ns: ( union is a data tIpe in 6 @hi6h allo@s the overlaI of more than one variable in the same memorI area7

+2 Week 4 a) To read in t@o numbers x and n and then 6ompute the sum of this geometri6 progression 1+x+x2+x3+KKK7+xn Description: 0n this program @e have to read the t@o numbers and the 6al6ulate the sum of this geometri6 progression in above mention 7 Algorithm: Step 1: Start Step 2: read values of x and n; sumE1; i=1 Step 3: 6he6B for n ? Y i) if n#=! VV x#=! ii) print values are not valid iii) read values of x and n Step ": perform the loop operation i) for9i=1<i#=n<i++) then follo@s ii) sum=sum+po@9x;i) Step %: print sum Step 6: Stop

+3

Flow chart:

Start 0nitiali e Sum;0;x;n ,ead x;n

false 0f n#=!VV x#=! Sum = 1 false 0=1 0++ true Sum=sum+po@9x;i) 3rint sum i#=n

true

3rint not valid

Stop

+" Program: 5in6lude#stdio7h8 5in6lude#6onio7h8 5in6lude#math7h8 void main9) : int sZsum;i;x;n< 6lrs6r9)< printf9=Enter the values for x and n:=)< s6anf9='d 'd=;?x;?n)< if9n#=! VV x#=!) : printf9=Oalue is not valid>n=)< C else : printf9=Oalue is valid>n=)< sZsum=1< for9i=1<i#=n<i++) : sZsum=sZsum+po@9x;i)< C printf9=Sum of series='d>n=;sZsum)< C get6h9)< C Output: 17Enter the values for x and n:2 3 Oalue is valid Sum of series=1% 27Enter the values for x and n:" D Oalue is valid Sum of series=21+"% 37Enter the values for x and n:! 1 Oalue is not valid Conclusion: the program is error free VIVA QU !A"IO#!: 1) @hat are the differen6e bet@een stru6tures and unions G (ns: Nere the maPor differen6e is @ith in the stru6ture all elements must be allo6ated memorI7 Hut in union highest memorI allo6ation must be allo6ated the all these elements7

+%

Week 1' a) 3rogram @hi6h 6opies one file to another Description: 0n this program @e have to use the file fun6tions to perform the 6opI operation from one file to another file7 Algorithm: Step 1: Start Step 2: read 6ommand line arguments Step 3: 6he6B if no of arguments =3 or not7 0f not print invalid no of arguments Step ": open sour6e file in read mode Step %: if 1-// pointer; then print sour6e file 6an not be open Step 6: open destination file in @rite mode Step $: if 1-// pointer; then print destination file 6an not be open Step +: read a 6hara6ter from sour6e file and @rite to destination file until E4. Step D: Llose sour6e file and destination file Step 1!: Stop

+6

Flow chart:

Start ,ead arguments from 6ommand line true 0f arg& =3 false fs=fopen9argW1X;^r^ true 0f fs=1-/ /

3rint invalid no of arguments

3rint sour6e file 6an not be opened

false

.t=fopen9argW2X;^@^

3rint target file 6an not be opened

0f ft==1-/ / false Lh=fget69fs) true

f6lose9fs)

Stop

f6lose9fs) f6lose9ft)

0f 6h==E4 . false fput696h;ft)

+$ Program: 5in6lude #stdio7h8 5in6lude #6onio7h8 5in6lude #pro6ess7h8 void main9int arg6; 6har AargvWX) : .0/E Afs;Aft< 6har 6h< 6lrs6r9)< if9arg6&=3) : puts9=0nvalid number of arguments7=)< exit9!)< C fs = fopen9argvW1X;=r=)< if9fs==1-//) : puts9=Sour6e file 6annot be opened7=)< exit9!)< C ft = fopen9argvW2X;=@=)< if 9ft==1-//) )) 6he6B the 6ondition if the file pointer is 1-// or not : puts9=Target file 6annot be opened7=)< f6lose9fs)< exit9!)< C @hile91) : 6h=fget69fs)< if 96h==E4.) )) 6he6B the 6ondition if the file is end or not breaB< else fput696h;ft)< C f6lose9fs)< f6lose9ft)< get6h9)< C

++ Output: sour6e76 this is sour6e text ouput76 Lommand line arguments sour6e76 ouput76 sour6e76 this is sour6e text ouput76 this is sour6e text Lommand line arguments sour6e76 0nvalid number of arguments7 Conclusion: the program is error free VIVA QU !A"IO#!: 1) Fhat is file G (ns: The 6olle6tion of alphabets is 6alled file 2) Fhat are the various operations performed on the file G (ns: fopen9); fread9); f@rite9); f6lose9) et677; 3) Fhat is the use of file pointer G (ns: The file pointer must be used in subseJuent operations on the file

+D Week 1' b) To reverse the first n 6hara6ters in afile Description: This program perform the reverse operation of n 6hara6ters in the file Algorithm: Step 1: Star Step 2: read the 6ommand line arguments Step 3: 6he6B if arguments=3 or not 0f not print invalid no of arguments Step ": open sour6e file in read mode Step %: if 1-// pointer; then print file 6an not be open Step 6: Store no of 6hars to reverse in B R= AargvW2XE"+ Step $: read the item from file stream using fread Step +: Store 6hars from last position to initial position in another string9temp) Step D: print the temp string Step 1!: Stop

D!

Flow chart:

Start ,ead 6ommand line args false

3rint invalid no of args

0f arg6& =3 true 3rint file 6an not be opened

.p=fopen9argvW1X;^r ^

0f fp==1-/ / false B=AargvW2XE"+ n = fread9a;1;B;fp) aWnX=S>!S len=strlen9a)

false SWP+1X=U>!U

0 = lenE1 0 8=! true SWPX=aWiX

i_

3rint sWPX Stop Q++

D1 Program: 5in6lude #stdio7h8 5in6lude #6onio7h8 5in6lude #string7h8 5in6lude #pro6ess7h8 void main9int arg6; 6har AargvWX) : 6har aW1%X< 6har sW2!X< 6har n< int B< int P=!< int i< int len< .0/E Afp< if9arg6&=3) : puts9=0mproper number of arguments7=)< exit9!)< C fp = fopen9argvW1X;=r=)< if9fp == 1-//) : puts9=.ile 6annot be opened7=)< exit9!)< C B=AargvW2XE"+< n = fread9a;1;B;fp)< aWnX=S>!S< len=strlen9a)< for9i=lenE1<i8=!<iEE) : sWPX=aWiX< printf9='6=;sWPX)< P=P+1< C sWP+1X=S>!S< get6h9)< C

D2 Output: sour6e76 this is sour6e ouput76 Lommand line arguments sour6e76 ouput76 sour6e76 this is sour6e e6ruos si siht Lommand line arguments sour6e76 0nvalid number of arguments7 Conclusion: the program is error free VIVA QU !A"IO#!: 1) /ist out the file handling fun6tions G (ns: fopen9); fprintf9);f6lose9);fs6anf9);fget69);fput69); et677; 2) Fhat is the use of fseeB9) fun6tion G (ns: The fun6tion fseeB sets the file pointer asso6iated @ith a stream to a ne@ position 3) Fhat is use of the fflush9) fun6tion G (ns: 0f the given stream has a buffered output; fflush @rites the output of the stream to the asso6iate file7

D3 Week 15 To 6onvert the given binarI number to 2Us 6omplement7 Description: 0n this program the given binarI number is first 6overt the numbers ! to1 and 1 to !7 (nd finallI add the 1 to the 6onverted number7 Then @e @ill get the 2Us 6omplement number7 Algorithm: main program Step 1: Start Step 2: de6lare the subprogram ]6omplement96har Aa)^ Step 3: initiali e the variable i Step ": read the binarI number Step %: perform the loop operation7 if it is true then follo@s7 if not goto step $ i) for9i=!<aWiX&=U>!U<i++) ii) if9aWiX&=U!U??aWiX&=U1U) then displaIed the number is not valid7 enter the 6orre6t number7 iii) Exit the loop Step 6: 6all sub program T6omplemt9a)U Step $: stop !u% program: Step 1: initiali e the variable 0;6=!;bW16! Step 2: 1=strlen9a) Step 3: perform the loop operation7 if it is true then follo@s7 if not goto i)for9i=lE1<i8=!<iEE) ii)if9aWiX==U!U) then bWiX=U1U else iii)bWiX=U!U Step ": for9i=lE1<i8=!<iEE) is true i) if9i==lE1) then ii) if9bWiX==U!U) then bWiX=U1U else iii) bWiX=U!U;6=1 if not goto step % Step %: if96==1??bWiX==U!U) is true then i) bWiX=U1U; 6=! if not goto Step 6 Step 6: if96==1??bWiX==U1U) then bWiX=U!U;6=1 Step $: displaIed bWlX=U>!U Step +: print b and return to main program

D" Flow chart: Start

0nitiali e 0; aW X

,ead a

false

0=! (WiX&=U>!U

i++

true false

0f aWiX& =U!U??aWiX&=U1U Lall sub program Lomplement9a) true 1umber is not valid

Stop

D%

Lomplement9 ) 0nitiali e ;0;6=!;bW X 1=strlen9a)

0=iE1 false i8=!

0EE

true 0f aWiX==U !U HWiX=X!X

true HWiX=U1U

0=lE1 i8=! L false 0f i==lE 1


0f 6==1?? bWiX=U!U L=1

iEE

true true

false

true
0f bWiX==U!U HWiX=U1U

HWiX==U!U

true

HWiX=U1U L=!

D6

( true 0f 6==1 ?? bWiX==1 HWiX=U!X L=1 H

HWiX=U>!U

3rint TbU

,eturn to main program Program: 5in6lude #stdio7h8 5in6lude#6onio7h8 void 6omplement 96har Aa)< void main9) : 6har aW16X< int i< 6lrs6r9)< printf9=Enter the binarI number=)< gets9a)< for9i=!<aWiX&=S>!S< i++) : if 9aWiX&=S!S ?? aWiX&=S1S) : printf9=The number entered is not a binarI number7 Enter the 6orre6t number=)< exit9!)< C C 6omplement9a)< get6h9)< C void 6omplement 96har Aa)

D$ : int l; i; 6=!< 6har bW16X< l=strlen9a)< for 9i=lE1< i8=!< iEE) : if 9aWiX==S!S) bWiX=S1S< else bWiX=S!S< C for9i=lE1< i8=!< iEE) : if9i==lE1) : if 9bWiX==S!S) bWiX=S1S< else : bWiX=S!S< 6=1< C C else : if96==1 ?? bWiX==S!S) : bWiX=S1S< 6=!< C else if 96==1 ?? bWiX==S1S) : bWiX=S!S< 6=1< C C C bWlX=S>!S< printf9=The 2Ss 6omplement is 's=; b)< C Output: 17Enter the binarI number1!1!1! The 2Ss 6omplement is !1!11! Enter the binarI number11111 The 2Ss 6omplement is !!!!1

D+ Enter the binarI number2222 The number entered is not a binarI number7 Enter the 6orre6t number Conclusion: the program is error free VIVA QU !A"IO#!: 1) Expand (SL00 G (ns: (meri6an standarad 6ode for information inter6hange 2)Fhat is binarI number G (ns: The number @hi6h 6ontains onlI ! and 1 is 6alled binarI number7 3) 2efine 2^s 6omplement G (ns: The given binarI number is first 6overt the numbers ! to1 and 1 to !7 (nd finallI add the 1 to the 6onverted number7 Then @e @ill get the 2Us 6omplement number7

Potrebbero piacerti anche