Lecture1
.pdfPalindrome
Palindrome – text that is same if letters are in reverse order
1.S = “madam”
2.For i = length(S) downto 1 do
3. T = T + S[i]
4.
5. if S=T then
6. output “It is palindrome”
7. else
8. output “It is not palindrome”
Palindrome – better solution
1.S = “talgat”
2.H = true
3.n = length( S )
4.For i = 1 to n div 2 do
5. |
if S[ i ] ≠ S[ n – i + 1 ] then |
6. |
H = false |
7. |
break |
8.if H = true then
9. output “It is Palindrome”
10. else
11. output “It is not Palindrome”
Sum of digits
Sum of digits
1. S = “38164913”
2.sum = 0
3.For i = 1 to length(S) do
4. sum = sum + (S[i] – „0‟)
5. output sum
Numeral systems
•How to find that octal number, of length 10000 digits, is divisible by 7.
Home Work
•First question:
•Zero sequence
•S = “1001101001100001010001”
•Find length of longest consecutive „0‟ sequence.
•For this example is 4.
•Second question:
•Katya selects two numbers X and Y less that 106.
•Then tell Vasya sum, and product of X and Y.
•Write program to help Vasya find X and Y.