Skip to main content

Test weather a given String is palindrome or not

C programming code :

#include <stdio.h> 
#include <string.h> 
void isPalindrome(char str[]) 

    int l = 0; 
    int h = strlen(str) - 1; 
  
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            printf("No"); 
            return; 
        } 
    } 
    printf("Yes"); 

  
int main() 

    char s[1000];
    scanf("%s",s);
    isPalindrome(s);
    return 0; 
}

Python code:
 
s = input()
ans = s == s[::-1] 
  
if ans: 
    print("Yes", end='') 
else: 
    print("No", end='') 

Java code:

import java.util.Scanner;
public class code
{
    public static void main(String args[])
    {
        String a, b = "";
        Scanner s = new Scanner(System.in);
        a = s.nextLine();
        int n = a.length();
        for(int i = n - 1; i >= 0; i--)
        {
            b = b + a.charAt(i);
        }
        if(a.equalsIgnoreCase(b))
        {
            System.out.print("Yes");
        }
        else
        {
            System.out.print("No");
        }
    }
}

Comments

Popular posts from this blog

Count the number of vowels in a string

C programming code : #include <stdio.h> int main() { char s[1000]; scanf("%s", s); int i = 0; int vowels = 0; int consonants = 0; while(s[i++] != '\0') { if(s[i] == 'a' || s[i] == 'e' || s[i] == 'i' || s[i] == 'o' || s[i] == 'u' ) vowels++; else consonants++; } printf("%d",vowels); return 0; } Python code: def vowel_count(str): count = 0 vowel = "aeiouAEIOU" for alphabet in str: if alphabet in vowel: count = count + 1 print(count, end='') str = input() vowel_count(str) Java code: import java.util.Scanner; public class code1 { static int isVowel(char ch) { ch = Character.toUpperCase(ch); if(ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { return 1; } else return 0; } ...

Test weather the year is leap year or not

C programming code : #include<stdio.h> int leapprog(int year) { if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) printf("Yes"); else printf("No"); } int main() { int input_year, val; scanf("%d",&input_year); leapprog(input_year); return 0; } Python code: year = int(input()) if (year % 4) == 0: if (year % 100) == 0: if (year % 400) == 0: print("Yes") else: print("No") else: print("Yes") else: print("No") Java code: import java.util.Scanner; public class code { public static void main(String[] args){ int year; Scanner sc = new Scanner(System.in); year = sc.nextInt(); if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) System.out.println("Yes"); else System.out.println("No"); } }