前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()

//GcmLcm.h
extern "C"
{
__declspec(dllexport) int gcm(int v1, int v2);
__declspec(dllexport) int lcm(int v1, int v2);
}
|
//GcmLcm.cpp
#include "GcmLcm.h"
int gcm(int v1, int v2)
{
int w1,w2;
w1 = v1;
w2 = v2;
while(w1 != w2)
{ if (w1 > w2) w1-= w2;
else w2-= w1;
}
return w1;
}
int lcm(int v1, int v2)
{
return v1*v2/gcm(v1,v2);
}
|

![]()

#include <stdio.h>
#include <conio.h>
#include "GcmLcm.h"
#pragma once
#pragma comment(lib,"GcmLcm.lib")
int main(void)
{
printf("GCM(24,32)=%d LCM(24,32)=%d\n", gcm(24,32),lcm(24,32));
_getch();
return(0);
}
|
![]()