C语言里所谓主程序的算法都有什么,具体一点。求大佬解释!

C语言里所谓主程序的算法都有什么,具体一点。求大佬解释!,第1张

主程序一般都指Main函数,程序都是从Main开始执行的,里面可以实现你想要的功能,也就是你说的算法,算法很广泛,所有的功能都是属于算法,枝纳悄丛什么条件语句啊,循环语句啊猛运没,这些都是一种算法,不只是生活中的加减乘除那些才是算法

#include<stdio.h>

#include<time.h>

#include<stdlib.h>

int

input(int

t)

int

copu(int

s)

int

main()

{

int

tol=0

printf("\n*

*

*

*

*

*

*

*catch

thirty*

*

*

*

*

*

*

\n")

printf("Game

Begin\n")

//randomize()

/*初始化随机数发生器

这个函数和下面是random是bc/tc里的函数

不是标准函数,所以编译通不过!*/

srand(0)//初始化随机发生器,srand()中的整数就是种子,一般以时间为种子!

//

即,使用这个:srand(time(NULL))

//rand()%2

是取1或2的随机数

if

(/*random(2)*/

rand()%2

==1)

/*取随机数决定机器和人谁先走第一薯睁瞎步*/

tol=input(tol)

/*若为1,则余元走第一步*/

while

(tol!=30)

/*游戏结束条件*/

if

((tol=copu(tol))==30)

/*计算机取一个数,若为30则机器胜利*/

printf("I

lose!

\n")

else

if

((tol=input(tol))==30)

/*人取一个数,若为30则人胜利*/

printf("I

lose!

\n")

printf("

*

*

*

*

*

*

*

*Game

Over

*

*

*

*

*

*

*

*\n")

}

int

input(int

t)

{

int

a

do

{

printf("Please

count:")

scanf("%d",&a)

if

(a>2||a<1||t+a>30)

printf("Error

input,again!")

else

printf("You

count:%d\n",t+a)

}

while

(a>2||a<1||t+a>30)

return

t+a

/*返回当前的已经取走的数累加数空和*/

}

int

copu(int

s)

{

int

c

printf("Computer

count:")

if

((s+1)%3==0)

/*若剩余的数的模为1,则取1*/早绝

printf("

%d\n",++s)

else

if

((s+2)%3==0)

{

s+=2

/*若剩余的数的模为2,则取2*/

printf("

%d\n",s)

}

else

{

c=/*random(2)*/rand()%

2

+1

/*否则随机取1或2*/

s+=c

printf("

%d\n",s)

}

return

s

}


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/12282093.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存