# Python program to check prime number # Function to check prime number def isPrime(n): return all([(n % j) for j in range(2, int(n/2)+1)]) and n>1 # Main code num = 59 if isPrime(num): print(num, "is a prime number") else: print(num, "is not a prime number") ...
Python program to check prime number using object oriented approach# Define a class for Checking prime number class Check : # Constructor def __init__(self,number) : self.num = number # define a method for checking number is prime or not def isPrime(self) : for i in range(2, int(...
Sunny Number Program in Java Java Program to reverse the Array java program to check palindrome string using recursion System.out.println(“Enter a number for check in main method:”); int n = scan.nextInt(); int count = 0; } }
Example 1: Check Armstrong Number for 3 digit number fun main(args: Array<String>) { val number = 371 var originalNumber: Int var remainder: Int var result = 0 originalNumber = number while (originalNumber != 0) { remainder = originalNumber % 10 result += Math.pow(remainder.toDouble(...
# Program to check if a string is palindrome or not my_str = 'aIbohPhoBiA' # make it suitable for caseless comparison my_str = my_str.casefold() # reverse the string rev_str = reversed(my_str) # check if the string is equal to its reverse if list(my_str) == list(rev_str):...
util.Scanner; public class StrongNumber { // Function to calculate the factorial of a number public static int factorial(int num) { int fact = 1; for (int i = 1; i <= num; i++) { fact *= i; } return fact; } // Function to check if the number is a Strong Number public ...
Check give number is Even or Odd #include<iostream.h>#include<conio.h>voidmain(){intno;clrscr();cout<<"Enter any num: ";cin>>no;if(no%2==0){cout<<"Even num";}else{cout<<"Odd num";}getch();} Output Enter any num : 5 Odd num ...
Non-Palindrome Strings:“hello”, “world” Logic to Check Palindrome String To check if a string is a palindrome: Read the string as input. Reverse the string. Compare the original string with the reversed string. If both strings are identical, it is a palindrome; otherwise, it is not. ...
Here is source code of the Python Program to check whether a string is a palindrome or not using recursion. The program output is also shown below. def is_palindrome(s): if len(s) < 1: return True else: if s[0] == s[-1]: return is_palindrome(s[1:-1]) else: return False ...
15. Palindrome Check Variants Write a C program to check if a singly linked list is a palindrome or not. Sample Solution: C Code: #include<stdio.h>#include<stdlib.h>#include<stdbool.h>// Node structure for the linked liststructNode{intdata;structNode*next;};// Function to create a ne...