Posts

Showing posts from January, 2019

LCM of two integer

#include <stdio.h> #include <stdlib.h> void main() {     int a,b,L,n,i,j;     printf("Enter two numbers : ");     scanf("%d %d",&a,&b);     for(L=(a>b?a:b);L<=(a*b);L+=(a>b?a:b))     {         if(L%a==0 && L%b==0)         break;     }     H=(a*b)/L;     printf("The LCM is %d\n",L);     printf("The HCF is %d",H); }

LCM of an array of integers

#include <stdio.h> #include <stdlib.h> int mul(int arr[],int n); int maxArrElement(int arr[],int n); int main() {     int L,n,i,j,arr[100],max,multiplication;     printf("Enter the no. of terms: ");     scanf("%d",&n);     for(i=0;i<n;i++)     {         scanf("%d",&arr[i]);     }   max=maxArrElement(arr,n);    multiplication=mul(arr,n);    printf(" The maximum no is : %d\n",max); printf("Multiplication of Array elements is : %d\n",multiplication);     for(L=max;L<=multiplication;L+=max)     {         for(j=0;j<n;j++) {         //....You have to put general condition for any no of array elements...         if(L%arr[0]==0 && L%arr[1]==0 && L%arr[2]==0 && L%arr[3]==0 && L%arr[4]==0 )         break; } ...

Next prime function

private static int nextPrime(int num) { num++; for (int i = 2; i <num; i++) { if(num%i == 0) { num++; i=2; } else{ continue; } } return num; }