Neeraj Mishra

A crazy computer and programming lover. He spend most of his time in programming, blogging and helping other programming geeks.

Java program to swap two numbers without using temp variable

class Swap { public static void main(String…s) { int a,b; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); System.out.println(“nBefore Swap:n”+”a=”+a+”tb=”+b); a=a+b; b=a-b; a=a-b; System.out.println(“nAfter Swap:n”+”a=”+a+”tb=”+b); } }

Java program to swap two numbers

class Swap { public static void main(String…s) { int a,b,temp; a=Integer.parseInt(s[0]); b=Integer.parseInt(s[1]); System.out.println(“nBefore Swap:n”+”a=”+a+”tb=”+b); temp=a; a=b; b=temp; System.out.println(“nAfter Swap:n”+”a=”+a+”tb=”+b); } }

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 factorial of any number using recursion

#include<stdio.h> #include<conio.h> void main() { int fac,n; int factorial(int); clrscr(); printf(“Enter any number:”); scanf(“%d”,&n); fac=factorial(n); printf(“Factorial=%d”,fac); getch(); } int factorial(int x) { int f; if(x==1||x==0) return 1; else f=x*factorial(x-1); return f; }

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 »