前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
/*★ GCM, LCM の DLL Object Class 前田 稔 ★*/
// File: GcmLcm.cs
namespace GcmLcm
{
public class GCMLCM
{ int d1,d2;
public GCMLCM(int n, int m)
{ d1= n;
d2= m;
}
public int Gcm()
{ int n,m;
n= d1;
m= d2;
while(n!=m)
{ if (n>m) n-= m;
else m-= n;
}
return n;
}
public int Lcm()
{ int wk;
wk= Gcm();
return d1*d2/wk;
}
}
}
|
C:\DATA\C#>vsvars32.bat C:\DATA\C#>csc /target:library /out:GcmLcm.dll GcmLcm.cs |
/*★ DLL を使って GCM LCM を計算 前田 稔 ★*/
// TestGcm.cs
using System;
using GcmLcm;
class console
{
public static int Main()
{ GCMLCM glcm = new GCMLCM(24,32);
Console.WriteLine("GCM={0} LCM={1}",glcm.Gcm(),glcm.Lcm());
System.Console.ReadLine();
return 0;
}
}
|
C:\DATA\C#>csc /out:TestGcm.exe /reference:GcmLcm.dll TestGcm.cs |
![]()
/*★ こよみの DLL Object Class 前田 稔 ★*/
// File: Koyomi.cs
using System;
namespace Koyomi
{
public class KOYOMI
{ int[] MTBL= { 0,31,59,90,120,151,181,212,243,273,304,334 };
string[] WTBL= { "日","月","火","水","木","金","土" };
int yy,mm,dd;
int Today,cnt,wek;
//Constructor
public KOYOMI()
{ //西暦1年1月1日から今日までの日数を調べる
yy= DateTime.Today.Year;
mm= DateTime.Today.Month;
dd= DateTime.Today.Day;
Today= Days();
}
// 生年月日を入力して曜日と通算日数を計算
public bool GetDate()
{ string str;
string[] ymd;
Console.WriteLine("生年月日= YYYY/MM/DD を入力(Enter のみで終了)");
str = Console.ReadLine();
if (str==string.Empty) return false;
ymd= str.Split(new char[] {'/'});
yy= int.Parse(ymd[0]);
mm= int.Parse(ymd[1]);
dd= int.Parse(ymd[2]);
cnt= Days();
wek= cnt%7;
cnt= Today-cnt+1;
return true;
}
// 生年月日と曜日と通算日数を印字
public void Print()
{ Console.WriteLine("{0}年 {1}月 {2}日 ({3}曜日) 通算日数={4}",
yy, mm, dd, WTBL[wek], cnt);
}
// 西暦1年1月1日からの通算日数を調べる関数
public int Days()
{ int w;
w= (yy-1)*365; //年*365
w+= (yy/4 - yy/100 + yy/400 + MTBL[mm-1] + dd);
if (mm<3 && Uruu(yy)) w--;
return(w);
}
// 閏年を調べる関数
public bool Uruu(int year)
{ if (year%400L==0L) return(true);
if (year%100L==0L) return(false);
if (year%4L==0L) return(true);
return(false);
}
}
}
|
C:\DATA\C#>vsvars32.bat C:\DATA\C#>csc /target:library /out:Koyomi.dll Koyomi.cs |
/*★ 曜日と経過日数を表示 前田 稔 ★*/
using System;
using Koyomi;
class console
{
public static int Main()
{
KOYOMI koyomi = new KOYOMI();
if (koyomi.GetDate()!=false)
{ koyomi.Print(); }
return 0;
}
}
|
C:\DATA\C#>csc /out:TestKoyomi.exe /reference:Koyomi.dll TestKoyomi.cs |
![]()