Write A program to check if a positive integer is palindrome or not
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
int main() | |
{ | |
int n;scanf("%d",&n); | |
int digits=0;int reverse=0; | |
int temp1=0; | |
int temp2=0; | |
if(n<=0){printf("enter positive enteger\n");} | |
else | |
{ | |
temp1=n; | |
temp2=n; | |
while(temp1!=0) | |
{ | |
temp1/=10; | |
digits++; | |
} | |
for(int i=digits-1;i>=0;i--) | |
{ | |
reverse+=(temp2%10)*(pow(10,i)); | |
temp2/=10; | |
} | |
if(reverse==n){printf("palindrome\n");} | |
else{printf("not palindrom\n");} | |
} | |
return 0; | |
} |
No comments:
Post a Comment