This project is about to find the Highest Common Factor(HCF) or Least Common Multiplication(LCM).You should give the input for finding the hcf or lcm and it gives the output.
#include #include void main() { int n,a[5],i,j,op,c,t; long int x,k; clrscr(); printf("\n\nEnter how many numbers:\t"); scanf("%d",&n); for(i=0;i<5;i++) a[i]=0; printf("\n\nEnter the numbers one by one:\n"); for(i=0;i scanf("%d",&a[i]); do { printf("\n\nChoose:\n\n1.HCF\n\n2.LCM\n\n3.Exit\n\nEnter your option:\t"); scanf("%d",&op); switch(op) { case 1: t=a[0]; for(i=1;i if(t>a[i]) t=a[i]; for(i=t;i>0;i--) { c=0; if(t%i==0) { for(j=0;j { if(a[j]%i==0) c=1; else { c=0; break; } } } if(c==1) { printf("\n\nHCF : %d",i); break; } } break; case 2: x=1; for(i=0;i x=x*a[i]; t=a[0]; for(i=1;i if(t t=a[i]; for(k=t;k<=x;k++) { c=0; if(k%t==0) { for(j=0;j { if(k%a[j]==0) c=1; else { c=0; break; } } } if(c==1) { printf("\n\nLCM : %ld",k); break; } } break; } }while(op!=3); getch(); }
|
No feedbacks found. Be the first to respond...
|