请帮忙将以下C语言代码转换为VB.NET代码,谢谢!
#include"stdio.h"#include"string.h"#include"windows.h"intpr(inty,intm,intt){intye,me,...
#include "stdio.h"
#include "string.h"
#include "windows.h"
int pr(int y, int m, int t) {
int ye, me, i;
ye = (m+t-2)/12+y;
me = (m+t-2)%12+1;
printf(" %d-%0d ~ %d-%0d\n", y, m, ye, me);
ye = y; me = m;
for(i = 0; i < t; ++i){
//printf("%d %d\n",ye, me);
prmonth(ye, me);
me+=1;
if (me>12) {ye+=1; me=1;}
}
return 0;
}
int yam(int y, int m) {
char* st[] = {"未定义", " 一月", " 二月", " 三月",
" 四月", " 五月", " 六月", " 七月",
" 八月", " 九月", " 十月", "十一月",
"十二月"};
printf(" %d %s\n", y, st[m]);
printf(" ----------------------------\n");
return 0;
}
int ryear(int y) {
if ((y%400 == 0) || ((y%100!=0) && (y%4==0)))
return 1;
else return 0;
}
int mday(int y, int m){
int day[] = {0, 31, 28, 31, 30, 31, 30, 31,
31, 30, 31, 30, 31};
int ad = 0;
if(m == 2)
ad = ryear(y);
return day[m] + ad;
}
int monday(int y, int m) {
int md = 6, i, daynum;
for(i = 1916; i < y; ++i){
daynum = 365+ryear(i);
md = (md+daynum)%7;
}
for(i = 1; i < m; ++i){
md = (md+mday(y, i))%7;
}
return md;
}
int prmonth(int y, int m){
int md = monday(y, m);
int daysnum = mday(y, m);
int days = daysnum+md;
int i;
yam(y, m);
printf(" 日 一 二 三 四 五 六");
for (i = 0; i < days; ++i) {
if(i % 7 == 0) printf("\n\n ");
if((i - md)>=0)
printf(" %2d", i-md+1);
else printf(" ");
}
printf("\n\n");
return 0;
}
int main()
{
//freopen("cal.txt", "w", stdout);
int y, m, t;
begin:;
scanf("%d%d%d", &y, &m, &t);
if (y < 100) y+=2000;
if(y< 1916 || m > 200) {
printf("ERROR");
goto begin;
}
pr(y, m, t);
//close(stdout);
return 0;
} 展开
#include "string.h"
#include "windows.h"
int pr(int y, int m, int t) {
int ye, me, i;
ye = (m+t-2)/12+y;
me = (m+t-2)%12+1;
printf(" %d-%0d ~ %d-%0d\n", y, m, ye, me);
ye = y; me = m;
for(i = 0; i < t; ++i){
//printf("%d %d\n",ye, me);
prmonth(ye, me);
me+=1;
if (me>12) {ye+=1; me=1;}
}
return 0;
}
int yam(int y, int m) {
char* st[] = {"未定义", " 一月", " 二月", " 三月",
" 四月", " 五月", " 六月", " 七月",
" 八月", " 九月", " 十月", "十一月",
"十二月"};
printf(" %d %s\n", y, st[m]);
printf(" ----------------------------\n");
return 0;
}
int ryear(int y) {
if ((y%400 == 0) || ((y%100!=0) && (y%4==0)))
return 1;
else return 0;
}
int mday(int y, int m){
int day[] = {0, 31, 28, 31, 30, 31, 30, 31,
31, 30, 31, 30, 31};
int ad = 0;
if(m == 2)
ad = ryear(y);
return day[m] + ad;
}
int monday(int y, int m) {
int md = 6, i, daynum;
for(i = 1916; i < y; ++i){
daynum = 365+ryear(i);
md = (md+daynum)%7;
}
for(i = 1; i < m; ++i){
md = (md+mday(y, i))%7;
}
return md;
}
int prmonth(int y, int m){
int md = monday(y, m);
int daysnum = mday(y, m);
int days = daysnum+md;
int i;
yam(y, m);
printf(" 日 一 二 三 四 五 六");
for (i = 0; i < days; ++i) {
if(i % 7 == 0) printf("\n\n ");
if((i - md)>=0)
printf(" %2d", i-md+1);
else printf(" ");
}
printf("\n\n");
return 0;
}
int main()
{
//freopen("cal.txt", "w", stdout);
int y, m, t;
begin:;
scanf("%d%d%d", &y, &m, &t);
if (y < 100) y+=2000;
if(y< 1916 || m > 200) {
printf("ERROR");
goto begin;
}
pr(y, m, t);
//close(stdout);
return 0;
} 展开
1个回答
展开全部
Option Explicit On
Option Strict On
Imports System
Module Program
Sub Main()
Dim y,m,t As Integer
begin:
' 输入数据时一行一个
y=CInt(Console.ReadLine())
m=CInt(Console.ReadLine())
t=CInt(Console.ReadLine())
If y<100 Then
y=y+2000
End If
If y<1916 OrElse m>200 Then
Console.WriteLine("ERROR")
goto begin
End If
pr(y,m,t)
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
End Sub
Function pr(y As Integer,m As Integer,t As Integer) As Integer
Dim ye,[Me],i As Integer
ye=CInt((m+t-2)/12+y)
[Me]=(m+t-2) Mod 12+1
Console.WriteLine(" {0}-{1} ~ {2}-{3}",y,m,ye,[Me])
ye=y
[Me]=m
For i=0 To t-1
prmonth(ye,[me])
[Me]=[Me]+1
If [Me]>12 Then
ye=ye+1
[me]=1
End If
Next
Return 0
End Function
Function yam(y As Integer,m As Integer) As Integer
Dim st As String()={"未定义","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}
Console.WriteLine(" {0} {1}",y,st(m))
Console.WriteLine("----------------------------")
Return 0
End Function
Function ryear(y As Integer) As Integer
If 0=y Mod 400 OrElse (0<>y Mod 100 AndAlso 0=y Mod 4) Then
Return 1
Else
Return 0
End If
End Function
Function mday(y As Integer,m As Integer) As Integer
Dim day As Integer()={0,31,28,31,30,31,30,31,31,30,31,30,31}
Dim ad As Integer=0
If 2=m Then
ad=ryear(y)
End If
Return day(m)+ad
End Function
Function monday(y As Integer,m As Integer) As Integer
Dim md As Integer=6
Dim i,daynum As Integer
For i=1916 To y-1
daynum=365+ryear(i)
md=(md+daynum) Mod 7
Next
For i=1 To m-1
md=(md+mday(y,i)) Mod 7
Next
Return md
End Function
Function prmonth(y As Integer,m As Integer) As Integer
Dim md As Integer=monday(y,m)
Dim daysnum As Integer=mday(y,m)
Dim days As Integer=daysnum+md
Dim i As Integer
yam(y,m)
Console.Write(" 日 一 二 三 四 五 六")
For i=0 To days-1
If 0=i Mod 7 Then
Console.WriteLine()
Console.WriteLine()
Console.Write(" ")
End If
If i-md>=0 Then
Console.Write(" {0,2}",i-md+1)
Else
Console.Write(" ")
End If
Next
Console.WriteLine()
Console.WriteLine()
Return 0
End Function
End Module
Option Strict On
Imports System
Module Program
Sub Main()
Dim y,m,t As Integer
begin:
' 输入数据时一行一个
y=CInt(Console.ReadLine())
m=CInt(Console.ReadLine())
t=CInt(Console.ReadLine())
If y<100 Then
y=y+2000
End If
If y<1916 OrElse m>200 Then
Console.WriteLine("ERROR")
goto begin
End If
pr(y,m,t)
Console.Write("Press any key to continue . . . ")
Console.ReadKey(True)
End Sub
Function pr(y As Integer,m As Integer,t As Integer) As Integer
Dim ye,[Me],i As Integer
ye=CInt((m+t-2)/12+y)
[Me]=(m+t-2) Mod 12+1
Console.WriteLine(" {0}-{1} ~ {2}-{3}",y,m,ye,[Me])
ye=y
[Me]=m
For i=0 To t-1
prmonth(ye,[me])
[Me]=[Me]+1
If [Me]>12 Then
ye=ye+1
[me]=1
End If
Next
Return 0
End Function
Function yam(y As Integer,m As Integer) As Integer
Dim st As String()={"未定义","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"}
Console.WriteLine(" {0} {1}",y,st(m))
Console.WriteLine("----------------------------")
Return 0
End Function
Function ryear(y As Integer) As Integer
If 0=y Mod 400 OrElse (0<>y Mod 100 AndAlso 0=y Mod 4) Then
Return 1
Else
Return 0
End If
End Function
Function mday(y As Integer,m As Integer) As Integer
Dim day As Integer()={0,31,28,31,30,31,30,31,31,30,31,30,31}
Dim ad As Integer=0
If 2=m Then
ad=ryear(y)
End If
Return day(m)+ad
End Function
Function monday(y As Integer,m As Integer) As Integer
Dim md As Integer=6
Dim i,daynum As Integer
For i=1916 To y-1
daynum=365+ryear(i)
md=(md+daynum) Mod 7
Next
For i=1 To m-1
md=(md+mday(y,i)) Mod 7
Next
Return md
End Function
Function prmonth(y As Integer,m As Integer) As Integer
Dim md As Integer=monday(y,m)
Dim daysnum As Integer=mday(y,m)
Dim days As Integer=daysnum+md
Dim i As Integer
yam(y,m)
Console.Write(" 日 一 二 三 四 五 六")
For i=0 To days-1
If 0=i Mod 7 Then
Console.WriteLine()
Console.WriteLine()
Console.Write(" ")
End If
If i-md>=0 Then
Console.Write(" {0,2}",i-md+1)
Else
Console.Write(" ")
End If
Next
Console.WriteLine()
Console.WriteLine()
Return 0
End Function
End Module
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询