Loops

Program to Reverse Number in Java

Here you will learn how to reverse number in java with a program example. For example given number is 1478 then its reverse will be 8741. Program to Reverse Number in Java package com; import java.util.Scanner; class Reverse { public static void main(String…s) { int n,rev=0,i; Scanner sc = new Scanner(System.in); System.out.println(“Enter any number: “); …

Program to Reverse Number in Java Read More »

Program for Factorial in Java

Here you will get program for factorial in java. We can find factorial of any number by multiplying it with all the numbers below it. For example, factorial of 4 is 4*3*2*1 = 24. Program for Factorial in Java package com; import java.util.Scanner; class Factorial { public static void main(String…s) { int n,fac=1,i; Scanner sc …

Program for Factorial in Java Read More »

Number Palindrome in Java

Here you will learn about number palindrome in java. A number is called palindrome if it is equal to its reverse. For example 1221 is a palindrome while 1234 is not palindrome. Below I have shared the java program to check given number is palindrome or not. Also Read: String Palindrome in Java   Program …

Number Palindrome in Java Read More »

Java Program to Find Sum of Digits of a Number

Here you will get java program to find sum of digits of a number. For example if given digit is 125 then its sum will be 8. class sum { public static void main(String…s) { int n,i,sum=0; n=Integer.parseInt(s[0]); while(n!=0) { i=n%10; sum+=i; n/=10; } System.out.println(sum); } }   Output

C Program to Find LCM and HCF of Two Numbers

Here you will get C program to find lcm and hcf of two given numbers. #include<stdio.h> int main() { int a,b,hcf,lcm,max,min,r; printf(“Enter two numbers:”); scanf(“%d%d”,&a,&b); if(a>b) { max=a; min=b; } else if(b>a) { max=b; min=a; } if(a==b) hcf=a; else { do { r=max%min; max=min; min=r; }while(r!=0); hcf=max; } lcm=(a*b)/hcf; printf(“\nLCM=%d\nHCF=%d”,lcm,hcf); return 0; }   Output …

C Program to Find LCM and HCF of Two Numbers Read More »