您的位置:

c语言源码400行,c语言400行代码大作业

本文目录一览:

高分求用C语言编的闹钟程序或者定时提醒程序300-400行之间

给,已经编译运行确认了:

#includeconio.h

#include stdio.h

#includestdlib.h

#includetime.h

#includestring.h

int GetHour(char *s)

{

char *p, *q;

p = (char *)malloc(10);

strcpy(p, s);

q = p;

while(*q != ':')

{

q++;

}

*q = '\0';

return atoi(p);

}

int GetMinute(char *s)

{

char *p;

p = (char *)malloc(10);

strcpy(p, s);

while(*p != ':')

{

p++;

}

p++;

return atoi(p);

}

main()

{

char s[10];

int hour,minute;

time_t t;

struct tm *timeinfo;

printf("please input the time like [18:30]:\n");

gets(s);

hour = GetHour(s);

minute = GetMinute(s);

while(1)

{

time(t);

timeinfo = localtime(t);

if(timeinfo-tm_hour hour)continue;

else if(timeinfo-tm_min minute)continue;

else

{

printf("Time is up!Wake up!\n\007");

printf("\a\a\a\a");

exit(0);

}

}

}

C语言 怎么在21点小游戏中加入其他纸牌游戏,求个完整代码,共400行就行

如果你已经有其他牌戏的代码,只要在一开始加一个功能选择就行。

如果你没有其他代码,这个不是牌戏。

#includedos.h

#includegraphics.h

#includestdlib.h

int

sheet[20][2],sheeter;

picture(int

x,int

y,int

aim)

{

setcolor(2);

setlinestyle(0,0,3);

setwritemode(0);

line(x+10+aim,y,x+5+aim,y);

line(x-10-aim,y,x-5-aim,y);

line(x,y+10+aim,x,y+5+aim);

line(x,y-10-aim,x,y-5-aim);

delay(15000);

}

target_sheet(int

x,int

y,int

aim)

{

int

i;

if(0==rand()%2)x+=rand()%aim;

else

x-=rand()%aim;

if(0==rand()%2)y+=rand()%aim-aim/2-aim/3;

else

y-=rand()%aim;

sheeter=(sheeter+1)%20;

sheet[sheeter][0]=x;

sheet[sheeter][1]=y;

}

sounding()

{

sound(1500);

delay(2000);

sound(1000);

delay(2000);

sound(500);

delay(2000);

nosound();

}

main()

{

int

x,y,i,aim;

int

gdriver,

gmode;

union

REGS

regs;

detectgraph(gdriver,

gmode);

initgraph(gdriver,

gmode,

"c:\\turboc2");

while(1)

{

cleardevice();

setcolor(7);

for(i=0;i20;i++)

{

circle(sheet[i][0],sheet[i][1],0);

}

regs.x.ax=3;

int86(0x33,®s,®s);

x=regs.h.cl+regs.h.ch*255;

y=regs.h.dl+regs.h.dh*255;

if(regs.h.bl!=0)

{

sounding();

if(aim4)aim=aim+1+rand()%2;

else

aim=aim+3+rand()%5;

if(aim30)aim=25+rand()%15;

target_sheet(x,y,aim);

picture(x,y,aim-5);

}

else

if(aim5)aim-=aim/3;

else

if(aim0)aim-=1;

picture(x,y,aim);

setlinestyle(0,0,3);

}

closegraph();

}

中分,紧急求个200行左右的C语言源代码!

#include iostream.h

#include fstream.h

int mark[]; //右来保存走法的

int num[2][2];//棋盘

int temp;

int k ;

int q ;

string strAim = "123804765" //目标字符串,空格用0表示

string States[100];//字符窜数组

int iQuick; //有来退出递归的标志,1,表示找到走法,可以退出,0,怎么没有找到走法,继续走

Hrd(int i,int j)//华龙道算法,好像能找到结果,但是不能找到最少步数的结果,我不确定会不会还有漏洞。结果保存在mark[]中

{ string str1;

if (i!=0) //如果可以向上走,则向上走一步

{

temp=num[i-1][j];

num[i-1][j]=num[i][j];

num[i][j]=temp ; //交换空格和它上面的数字

// 保存交换后的状态

str1=Change2Str(num[][]); //转化成字符串,用来比较

if (CompState(str1)) //比较变换后的状态是否在以前的状态中出现过

{

//如果以前出现过,则返回

temp=num[i-1][j];

num[i-1][j]=num[i][j];

num[i][j]=temp ; // 把原来交换过的数字再交换过来

return ;

}

else//比较后,发现目前的状态以前没有出现过

{ mark[k++]=1 ;

if(strcmp(strAim, str1)=1)//跟目标比,看是否相等

{

iquick=1;

return;

}

else //不相等,没有达到最后我们的要求

{

//1 代表向上走了一步

Add2States(str1); //保存现在的状态到状态数组中

Hrd(i-1,j);

if (iquick=1) //可以退出

{

return;

}

} //递归,继续遍历

}

}

if(j!=2)//如果可以向右走,则向右走一步

{

temp=num[i][j+1];

num[i][j+1]=num[i][j] ;

num[i][j]=temp;

// 保存交换后的状态

str1=Change2Str(num[][]); //转化成字符串,用来比较

if (CompState(str1)) //比较变换后的状态是否在以前的状态中出现过

{

//如果以前出现过,返回

temp=num[i][j+1];

num[i][j+1]=num[i][j] ;

num[i][j]=temp; // 把原来交换过的数字再交换过来

return;

}

else//比较后,发现目前的状态以前没有出现过

{ mark[k++]=2 ; //2 代表向右走了一步

if(strcmp(strAim, str1)=1)//跟目标比,看是否相等

{

iquick=1;

return;

}

else //没有达到结果

{

Add2States(str1); //保存现在的状态到状态数组中

Hrd(i,j+1) ; //递归,继续遍历

if (iquick=1)

{

return;

}

}

}

}

if (i!=2)// 如果可以向下走,则向下走一步

{

temp=num[i+1][j];

num[i+1][j]=num[i][j];

num[i][j]=temp;

// 保存交换后的状态

str1=Change2Str(num[][]); //转化成字符串,用来比较

if (CompState(str1)) //比较变换后的状态是否在以前的状态中出现过

{

//如果以前出现过,则返回

temp=num[i+1][j];

num[i+1][j]=num[i][j];

num[i][j]=temp; // 把原来交换过的数字再交换过来

return ;

}

else//比较后,发现目前的状态以前没有出现过

{ mark[k++]=3 ; //3 代表向下走了一步

if(strcmp(strAim, str1)=1)//跟目标比,看是否相等

{

iquick=1;

return;

}

else //没有达到最后我们的要求

{

Add2States(str1); //保存现在的状态到状态数组中

Hrd(i+1,j) ; //递归,继续遍历

if (iquick=1)

{

return;

}

}

}

}

if (j!=0)//如果可以向左走,则向左走一步

{

temp=num[i1][j-1];

num[i][j-1]=num[i][j];

num[i][j]=temp;

// 保存交换后的状态

str1=Change2Str(num[][]); //转化成字符串,用来比较

if (CompState(str1)) //比较变换后的状态是否在以前的状态中出现过

{

//如果以前出现过,则回溯

temp=num[i][j-1];

num[i][j-1]=num[i][j];

num[i][j]=temp; // 把原来交换过的数字再交换过来

return ;

}

else//比较后,发现目前的状态以前没有出现过

{ mark[k++]=4 ; //1 代表向右走了一步

if(strcmp(strAim, str1)=1)//跟目标比,看是否相等

{

iquick=1;

return;

}

else //没有达到最后我们的要求

{

Add2States(str1); //保存现在的状态到状态数组中

Hrd(i,j-1) ; //递归,继续遍历

if (iquick=1)

{

return;

}

}

}

}

//如果都走过了,则返回

k--;

return;

}

void Change2Str(int arr[][])// 把二维数组转换成一个字符串

{int i,j

string strState

for (i=0;i3 ;i++ )

{ for (j=0;j3 ;j++ )

{

strState= strState arr[i][j];

}

}

return strState;

}

void CompState(string str1 )//比较当前的状态是否再以前的状态中出现过

{ int i;

for (i=0;ilen(states[])-1 ; i++)//len(states[]),取得数组的长度,有点忘了

{

if (strcmp(States[i],str1)!=0)//如果两个字符串相等,则函数返回true

{

return true;

}

}

return false;

}

Add2States(string str1)

{

States[q++]=str1 ;

}

main()

{ num[0][0]=1;

num[0][1]=2;

num[0][2]=3;

num[1][0]=8;

num[1][1]=6;

num[1][2]=4;

num[2][0]=1;

num[2][1]=0;

num[2][2]=5;

hrd(2,1);

for(int i=0 ,i100,i++)

{countmark[i]endl;

}

}

Dim moveup As Integer '蛇向上转向的标志

Dim movedown As Integer

Dim moveleft As Integer

Dim moveright As Integer

Public u As Integer 'u,l,r,d为蛇转向时的控制数值

Public d As Integer

Public l As Integer

Public r As Integer

Public score As Integer '游戏分数

Public speed As Integer '游戏速度

Public pause As Boolean '游戏暂停标志

Public gamebegin As Boolean '游戏开始标志

Public s As Integer '蛇的当前长度,开始时设为6

Public eatd As Boolean '蛇是否吃到食物的标志

Public lastx As Integer '若蛇吃到食物,lastx,lasty用来存放当前最后一个shape的运动状态,以供设定新的shape运动状态之用

Public lasty As Integer

Option Base 1

Dim X(100) As Long '数组存放蛇的长度

Dim Y(100) As Long

Public Sub eat() '判断蛇是否吃到食物的函数

If X(1) = -200 Then

If Shape1(1).Left = Shape2.Left And Shape1(1).Top = Shape2.Top Then

eatd = True

End If

End If

If Y(1) = -200 Then

If Shape1(1).Top = Shape2.Top And Shape1(1).Left = Shape2.Left Then

eatd = True

End If

End If

If X(1) = 200 Then

If Shape1(1).Left = Shape2.Left + 200 And Shape1(1).Top = Shape2.Top Then

eatd = True

End If

End If

If Y(1) = 200 Then

If Shape1(1).Top = Shape2.Top + 200 And Shape1(1).Left = Shape2.Left Then

eatd = True

End If

End If

End Sub

Public Sub ensure_position() '此函数确定新的shape1(s)的位置

If X(s - 1) = -200 Then

Shape1(s).Left = Shape1(s - 1).Left + 200: Shape1(s).Top = Shape1(s - 1).Top

End If

If Y(s - 1) = -200 Then

Shape1(s).Left = Shape1(s - 1).Left: Shape1(s).Top = Shape1(s - 1).Top + 200

End If

If X(s - 1) = 200 Then

Shape1(s).Left = Shape1(s - 1).Left - 200: Shape1(s).Top = Shape1(s - 1).Top

End If

If Y(s - 1) = 200 Then

Shape1(s).Left = Shape1(s - 1).Left: Shape1(s).Top = Shape1(s - 1).Top - 200

End If

End Sub

Public Sub ensure_state() '此过程用来确定新的控件的初始运动状态

If X(1) = -200 Then

If moveleft = 1 Then

X(s) = X(s - 1): Y(s) = Y(s - 1)

Else

X(s) = lastx: Y(s) = lasty

End If

End If

If Y(1) = -200 Then

If moveup = 1 Then

X(s) = X(s - 1): Y(s) = Y(s - 1)

Else

X(s) = lastx: Y(s) = lasty

End If

End If

If X(1) = 200 Then

If moveright = 1 Then

X(s) = X(s - 1): Y(s) = Y(s - 1)

Else

X(s) = lastx: Y(s) = lasty

End If

End If

If Y(1) = 200 Then

If movedown = 1 Then

X(s) = X(s - 1): Y(s) = Y(s - 1)

Else

X(s) = lastx: Y(s) = lasty

End If

End If

End Sub

Public Sub strike_oneself() '测试蛇头是否撞到自己

Dim i

Dim j: j = 0

If Y(1) = 200 Then '蛇头向下撞到自己

For i = 7 To s '蛇头只能和第六块或以后的蛇身相撞

If Shape1(1).Top = Shape1(s).Top And Shape1(1).Left = Shape1(s).Left Then

Form1.initialize

Form1.outputmessage

Exit For

End If

Next i

End If

If X(1) = 200 Then '蛇头向右撞到自己

For i = 7 To s

If Shape1(1).Left = Shape1(i).Left - 200 And Shape1(1).Top = Shape1(i).Top Then

Form1.initialize

Form1.outputmessage

Exit For

End If

Next i

End If

If Y(1) = -200 Then '蛇头向上撞到自己

For i = 7 To s

If Shape1(1).Top = Shape1(i).Top + 200 And Shape1(1).Left = Shape1(i).Left Then

Form1.initialize

Form1.outputmessage

Exit For

End If

Next i

End If

If X(1) = -200 Then '蛇头向左撞到自己

For i = 7 To s

If Shape1(1).Left = Shape1(i).Left + 200 And Shape1(1).Top = Shape1(i).Top Then

Form1.initialize

Form1.outputmessage

Exit For

End If

Next i

End If

End Sub

Public Sub strike_wall() '测试蛇头是否撞到墙壁

If Shape1(1).Top 0 Or Shape1(1).Top Line1.Y1 - 200 Or Shape1(1).Left 0 Or Shape1(1).Left Form1.Width - 200 Then

Form1.outputmessage

Form1.initialize

End If

End Sub

Public Sub outputmessage() ' 游戏结束后的输出信息

gameovermessage = "GAME OVER!"

dx = (8000 - TextWidth(gameovermessage)) / 2 '在窗体中间输出"GAME OVER!"和得分

dy = (6000 - TextHeight(gameovermessage)) / 2

CurrentX = dx: CurrentY = dy

Form1.Print gameovermessage

scoremessage = "你的得分:" + Text1.Text

dx = (8000 - TextWidth(scoremessage)) / 2

dy = dy + TextHeight(scoremessage)

CurrentX = dx: CurrentY = dy

Form1.Print scoremessage

End Sub

Public Sub initialize() '游戏结束(失败)后,游戏初始化函数

moveup = 0

movedown = 0

moveleft = 0

moveright = 0

u = 0: d = 0: l = 0: r = 0

Label5.Caption = "停止"

For i = 1 To s ' 初始化蛇的位置和状态

Shape1(i).Left = 1200 + (6 - i) * 200

Shape1(i).Top = 5000

X(i) = 200

Y(i) = 0

Next i

If s 6 Then

For i = 7 To s

Unload Shape1(i) '卸载多余的shape,使初始的shape个数为六个

Next i

End If

'以下的这段是用来查看游戏初始化时的中的参数

'CurrentX = 0: CurrentY = 0

'Form1.FontSize = 10

'Print moveup: Print movedown: Print moveleft: Print moveright

'Print u: Print r: Print l: Print d

'For i = 1 To s

'Print X(i): Print Y(i)

'Next i

s = 6

Timer1.Enabled = False

gamebegin = False '游戏未开始

pause = False

HScroll1.Enabled = True

End Sub

Private Sub Command1_Click()

Timer1.Enabled = False

Dim r

r = MsgBox("你真的要退出吗?", 33, "警告")

If r = 1 Then

Unload Form1

Else

Timer1.Enabled = True

End If

End Sub

Private Sub Form_KeyPress(keyascii As Integer)

If gamebegin = True And pause = False Then '只有游戏处于开始时方向键才有效

'下面四个if语句是蛇的方向控制函数

If keyascii = 119 Then

If Y(1) 200 Then '只有当蛇头不正好向下运动时,按下向上才有效

moveup = 1 '向下上为w

End If

End If

If keyascii = 97 Then '向左为a

If X(1) 200 Then

moveleft = 1

End If

End If

If keyascii = 115 Then '向下为s

If Y(1) -200 Then

movedown = 1

End If

End If

If keyascii = 100 Then '向右为d

If X(1) -200 Then

moveright = 1

End If

End If

End If

If keyascii = 32 Then '判断游戏是否在开始,按下空格键开始,否则按下空格键为暂停

If gamebegin = False Then

Timer1.Enabled = True

Label5.Caption = "开始"

Form1.Cls

score = 0

Text1.Text = Str$(score)

HScroll1.Enabled = False

gamebegin = True

Else

If pause = True Then '判断暂停与否

Timer1.Enabled = True

Label5.Caption = "开始"

Else

Timer1.Enabled = False

Label5.Caption = "暂停"

End If

pause = Not pause

End If

End If

End Sub

Private Sub Form_Load() '对各参数的初始化

moveup = 0

moveleft = 0

moveright = 0

movedown = 0

u = 0: l = 0: d = 0: r = 0

s = 6 '蛇的初始长度

eatd = False

gamebegin = False

pause = False

speed = HScroll1.Value '初始速度

Label5.Caption = "停止"

Dim i

For i = 1 To s '蛇的初始运动方向

X(i) = 200

Y(i) = 0

Next i

Timer1.Enabled = False '没开始游戏

Shape2.Left = 200 * Int(30 * Rnd) '贪吃蛇的食物的位置初始化

Shape2.Top = 200 * Int(30 * Rnd)

End Sub

Private Sub HScroll1_Change()

speed = HScroll1.Value

End Sub

Private Sub Timer1_Timer()

Timer1.Interval = 150 / speed '游戏速度

If movedown = 1 Then '按下下方向键,蛇向下转向

d = d + 1

X(d) = 0: Y(d) = 200

If d = s Then

movedown = 0: d = 0

End If

End If

If moveup = 1 Then '按下向上方向键,蛇向上转向

u = u + 1

X(u) = 0: Y(u) = -200

If u = s Then

moveup = 0: u = 0

End If

End If

If moveleft = 1 Then '向左

l = l + 1

X(l) = -200: Y(l) = 0

If l = s Then

moveleft = 0: l = 0

End If

End If

If moveright = 1 Then '向右

r = r + 1

X(r) = 200: Y(r) = 0

If r = s Then

moveright = 0: r = 0

End If

End If

Dim i '蛇的运动代码

For i = 1 To s

Shape1(i).Left = Shape1(i).Left + X(i)

Shape1(i).Top = Shape1(i).Top + Y(i)

Next i

Form1.eat '调用过程eat(),判断蛇是否吃了食物

If eatd = True Then

score = score + 5 * HScroll1.Value

Text1.Text = Str$(score)

Shape2.Left = 200 * Int(30 * Rnd) '如果食物被吃则随机产生贪吃蛇的食物的位置

Shape2.Top = 200 * Int(30 * Rnd)

Shape2.FillColor = RGB(Int(255 * Rnd), Int(255 * Rnd), Int(255 * Rnd)) '随机产生食物的颜色

If Shape2.FillColor = H0 Then

Shape2.FillColor = RGB(100, 150, 200)

End If

lastx = X(s) '蛇吃到食物,lastx,lasty用来存放当前最后一个shape的运动状态-

lasty = Y(s) '-以供设定新的shape运动状态之用

s = s + 1

Load Shape1(s) '产生新的控件shape1数组,使蛇的长度加长

Form1.ensure_state '调用设定新的shape控件的运动状态过程

Form1.ensure_position '设定新的shape1的位置

Shape1(s).Visible = True

eatd = False

End If

Form1.strike_oneself '测试游戏是否失败的函数

Form1.strike_wall

End Sub

求一篇C语言编写的通讯录程序,原创,调试成功的来,要求400行以上,速度立刻马上,现在就要,好的加分。

呵呵,400行以上,立刻马上,神的速度都没得这么快,自己慢慢等吧

C语言一元多项式计算器程序

我可以帮你做,不过需要一点时间,还有就是你可以把要求说细致一点。