Docstoc

c

Document Sample
c Powered By Docstoc
					Q4. Write a program that accepts 15 different numbers and find the LCM and HCM.



Answer: Text Box

//Compiled & tested with Dev-C++ Compiler

//For Turbo C++ use void main () instead of main(void)

#include <stdio.h>

#include <conio.h>



int hcmz(int,int);

int lcmz(int,int);



main(void)

{

int num[14],c=15,v,max,min;



printf("Enter 15 numbers:\n");



for(v=0;v<c;v++)

scanf("%d",&num[v]);

min=num[0];

for(v=1;v<c;v++)

min=hcmz(min,num[v]);

printf("\nHCM is %d",min);

max=num[0];

for(v=1;v<c;v++)
max=lcmz(max,num[v]);

printf("\nLCM is %d",max);

printf("\n\n\t\t\tWritten for smu.covertbay.com\n\n");

getch();

}

int lcmz(int e,int f)

{

int lcm;

lcm = e*f/hcmz(e,f);

return lcm;

}

int hcmz(int e,int f)

{

int dump,rem;

if(e<f)

{

dump=e;

e=f;

f=dump;

}

while(1)

{

rem=e%f;

if(rem==0)

return f;
else

e=f;

f=rem;

}

}

				
DOCUMENT INFO
Categories:
Tags:
Stats:
views:8
posted:7/15/2012
language:English
pages:3