失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > c语言阅读源代码 C语言-源代码详细资料.doc

c语言阅读源代码 C语言-源代码详细资料.doc

时间:2023-04-06 21:54:17

相关推荐

c语言阅读源代码 C语言-源代码详细资料.doc

\\

剪刀石头布源代码

#include

#include

main()

{

int d,x;

{

printf("请输入:1是剪刀,2是石头,3是布");

scanf("%d",&d);

x=rand()%3;

if(d==x)

printf("双方平局");

else if((d==1&&x==2)||(d==2&&x==3)||(d==3&&x==1))

printf("你赢了");

else

printf("电脑赢了");

}

}

简单计算器

#include

main()

{

int a,b,d=0;

char c;

while(d==0)

{

printf("请开始计算,请输入需要运算的数字和运算法则,数字 符号 数字:");

scanf("%d%c%d",&a,&c,&b);

switch(c)

{

case'+':

printf("%d+%d=%d\n",a,b,a+b);

break;

case'-':

printf("%d-%d=%d\n",a,b,a-b);

break;

case'*':

printf("%d*%d=%d\n",a,b,a*b);

break;

case'/':

if(0==b)

printf("除法被除数不能为零!\n") ;

else

printf("%d/%d=%d\n",a,b,a/b);

break;

}

}

}

加油站加油问题

#include

int main()

{

double a = 3.25, b = 3.00, c= 2.75;

double d = 0.05, e = 0.10, m;

int x,y,z;

printf("请输入您要的加油量:");

scanf("%d",&x);

printf("请输入您要的汽油种类,1-a型汽油售价3.25元/千克, 2-b型汽油售价3.00元/千克, 3-c型汽油售价2.75元/千克:");

scanf("%d",&y);

printf("请输入您要的服务类型,1-自己加 服务优惠0.05,2-协助加 服务优惠0.10:");

scanf("%d",&z);

switch(y)

{

case 1:

y = a;break;

case 2:

y = b;break;

case 3:

y = c;break;

}

if(z == 1)

m = (1 - d) * y * x;

else if(z == 2)

m = (1 - e) * y * x;

printf("您需要支付:%f 元,谢谢惠顾,欢迎下次再来",m);

return 0;

}

猜数字游戏

#include

#include

int main()

{

int d=1,e=0;

int a,b,t;

printf ("请输入1-10以内的整数,\n ");

while(d==1)

{

printf("玩家的选择: ");

scanf("%d",&a);

do

{

if((a>=0)&&(a<11))break;

else

{printf("错误");

scanf("%d",&a);}

}

while(e==0);

b=rand()%10+1;

printf("npc:%d",b);

t=a-b;

if(t==0)

printf("\nRight!\n");

else if(t<0)

printf("\n Wrong !太小了\ n");

else if(t>0)

printf("\n Wrong !太大了\ n");

}

return 0;

}

万年历

#include

#include

void setmonth(int r);

void main(void)

{

int year,month,day,a,b,i,j,d,x,mon,k;

do

{

printf("-------------------------

如果觉得《c语言阅读源代码 C语言-源代码详细资料.doc》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。