Page 110 - Computer science 868 Class 12
P. 110
Problem 8: Write an algorithm to input any number and check it is a Tech number or not. Tech number is an even
digit number which is divided into two equal parts. If square of sum of the two parts is equal to the number then it
is a tech number.
Step 1: Start.
Step 2: Accept an even digit number n
Step 3: Assign length l=(int)Math.log10(n)+1
Step 4: If l%2 !=0 then print “not even digit”, go to Step 2
Step 5: Assign left part lp=n/(int)Math.pow(10, l/2)
Step 6: Assign right part rp = n%(int) Math.pow(10, l/2)
Step 7: Assign sum=lp+rp
Step 8: If n=Sum×Sum then print “Tech number” else print “not”
Step 9: Stop.
Problem 9: Write an algorithm to check if a number is a Happy number or not. Happy number is a number in which
the ultimate sum of the square of the digits is equal to 1. Let us demonstrate it with an example.
Say Input = 28
2
2
2 + 8 = 68
Since 68 is not a 1-digit number, calculate the sum of the square of digits of 68 as
2
2
6 + 8 = 100.
Since 100 is not a 1-digit number, further digit extraction is possible as
2
2
1 + 0 + 0 = 1
2
As we have reached a one-digit number, no more extraction of digits is required. Thus, since the ultimate sum is 1,
so 28 is a Happy number.
Step 1: Start.
Step 2: Read number num.
Step 3: Initialise variable copy to num.
Step 4: Repeat Step 5 to Step 10 while copy > 9.
Step 5: Initialise the sum to 0.
Step 6: Repeat Step 7 to Step 9 while copy > 0.
Step 7: Divide copy by 10 and store the remainder to dig.
Step 8: Calculate dig*dig and accumulate the result in sum.
Step 9: Divide copy by 10 and store its quotient in copy.
Step 10: Initialise copy = sum.
Step 11: If copy = 1 then go to Step 12, else go to Step 13.
Step 12: Display num “is a Happy number”, go to Step 14.
Step 13: Display num “is not a Happy number”.
Step 14: Stop.
108108 Touchpad Computer Science-XII

