11th C Prg-11 Write an algorithm and program to check whether a given number is palindrome or not (using function and without using function)
Algorithm
Input
1. n
Output
1. Palindrome or not
Method:
1. Start
2. Read n
3. Write n
4. n1=n;
5. rev=0;
6. // logic
while (n != 0)
beng
r= n % 10;
rev = rev * 10 + r;
n = n / 10;
end
7. if (n1 == rev)
write " the given number is palidrome ";
else
write " The given number is not palindrome";
8.stop
Example:
1. 121 is a plindrome
2. 256 is not a palindrome
#program 11
#function
def sum(n): #called function
s=0
n1=n
rev=0
while(n>0):
r=n%10
rev=rev*10+r
n=n//10
s=s+r
if rev==n1:
print("The given number is palindrome")
else:
print("The given number is not palindrome")
#main program
n=int(input("Enter the number"))
print("The number is=",n)
sum(n) #calling functin
Output
Enter the number125 The number is= 125 The given number is not palindrome
Enter the number121 The number is= 121 The given number is palindrome
No comments:
Post a Comment