The program must accept an integer N as the input. The task is to check whether the number is a palindrome. If the number is a palindrome, the program should print YES. Otherwise, it should print NO.
Boundary Condition(s):
1 <= N <= 10^9
Input Format:
The first line contains the number N.
Output Format:
The first line contains either YES or NO.
Example Input/Output 1:
Input:
121
Output:
YES
Explanation:
The number 121 reads the same forwards and backwards, so it’s a palindrome.
Example Input/Output 2:
Input:
12321
Output:
YES
Explanation:
The number 12321 reads the same forwards and backwards, so it’s a palindrome.
Example Input/Output 3:
Input:
12345
Output:
NO
Explanation:
The number 12345 doesn’t read the same forwards and backwards, so it’s not a palindrome.
n = input().strip()
if n == n[::-1]:
print("YES")
else:
print("NO")
#include<stdio.h>
#include<string.h>
int main() {
char num[12];
scanf("%s", num);
int len = strlen(num);
int flag = 1;
for(int i = 0; i < len / 2; i++) {
if(num[i] != num[len - i - 1]) {
flag = 0;
break;
}
}
if(flag) {
printf("YES");
} else {
printf("NO");
}
return 0;
}
#include <iostream>
#include <string>
using namespace std;
int main() {
string num;
cin >> num;
bool isPalindrome = true;
int len = num.length();
for(int i = 0; i < len / 2; i++) {
if(num[i] != num[len - i - 1]) {
isPalindrome = false;
break;
}
}
cout << (isPalindrome ? "YES" : "NO");
return 0;
}
import java.util.Scanner;
public class PalindromeCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String num = sc.next();
boolean isPalindrome = true;
int len = num.length();
for(int i = 0; i < len / 2; i++) {
if(num.charAt(i) != num.charAt(len - i - 1)) {
isPalindrome = false;
break;
}
}
System.out.println(isPalindrome ? "YES" : "NO");
}
}