Loops

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 »