close

1:09 PM
C编译工具 win-tc
C编译工具
WIN-TC是一个TC2 WINDOWS平台开发工具。该软件使用TC2为内核,提供WINDOWS平台的开发界面,因此也就支持WINDOWS平台下的功能,例如剪切、复制、粘贴和查找替换等。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
下面是完整的c程式
------------------------------------------------------------------------------------------------------
 
三天打鱼两天晒渔网
 
一个完整的c程序
#include<stdio.h>
struct date{
int year;
int month;
int day;
};
int days(struct date day);

void main()
{
struct date today,term;
int yearday,year,day;
puts("***********************************************************************");
puts("* Fishing or idling ? *");
puts("* As the famous Chinese saying goes:fishing 3 days and idling 2 days *");
puts("* someone at age of 20 from 1990 1 1 begin fishing and idling *");
puts("* find one day after 1990 1 1 he is fishing or idling *");
puts("***********************************************************************\n");
while(1)
{
printf("\n\nPlease input year month and day (input 1990 1 1 to exit):");
scanf("%d%d%d",&today.year,&today.month,&today.day); /*输入日期*/
if(today.year<1990)
{
if(today.year<1970)
puts("Sorry,he wasn't born at that time. Strike any key to continue.");
else
puts("Sorry,he didn't begin fishing at that time. Strike any key to continue.");
getch();
continue;
}
if(today.year==1990&&today.month==1&&today.day==1)
break;
term.month=12; /*设置变量的初始值:月*/
term.day=31; /*设置变量的初始值:日*/
for(yearday=0,year=1990;year<today.year;year++)
{
term.year=year;
yearday+=days(term); /*计算从1990年至指定年的前一年共有多少天*/
}
yearday+=days(today); /*加上指定年中到指定日期的天数*/
day=yearday%5; /*求余数*/
if(day>0&&day<4) printf("%d %d %d he was fishing.\n",today.year,today.month,today.day); /*打印结果*/
else printf("%d %d %d he was idling.\n",today.year,today.month,today.day);

}
puts("\nStrike any key to quit.");
getch();
}

int days(struct date day)
{
static int day_tab[2][13]=
{{0,31,28,31,30,31,30,31,31,30,31,30,31,}, /*平均每月的天数*/
{0,31,29,31,30,31,30,31,31,30,31,30,31,},
};
int i,lp;
lp=day.year%4==0&&day.year%100!=0||day.year%400==0;
/*判定year为闰年还是平年,lp=0为平年,非0为闰年*/
for(i=1;i<day.month;i++) /*计算本年中自1月1日起的天数*/
day.day+=day_tab[lp][i];
return day.day;
}
 
该游戏可以由程序随机产生或由用户输入四个0到9之间的数字,且不重复。玩游戏者通过游戏提示输入八次来匹配上面所输入的数字。A表示位置正确且数字正确,B表示数字正确而位置不正确。
二、功能要求:
1、本游戏显示这样的菜单:
(1) 随机产生数据
(2) 用户输入数据
(3) 退出游戏
2、游戏成功与否都能返回主菜单
三、算法提示:
1、 数据结构:数组
2、 用简单的程序设计方法
四、测试数据:
测试数据: 3792
第一次输入: 1234
0A2B
第二次输入: 5678
0A1B
第三次输入: 0867
0A1B
第四次输入: 9786
1A1B
第五次输入: 1794
2A0B
第六次输入: 2793
2A2B
第七次输入: 3792
4A0B
游戏成功!!!
 
 
一个完整的c程序
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main()
{
int stime,a,z,t,i,c,m,g,s,j,k,l[4]; /*j:数字正确的位数 k:位置正确的位数*/
long ltime;
ltime=time(NULL); /*l:数字相同时,人所猜中数字的正确位置*/
stime=(unsigned int)ltime/2;
srand(stime);
z=random(9999); /*计算机想一个随机数*/
printf("I have a number with 4 digits in mind,please guess.\n\n");
for(c=1;;c++) /*c: 猜数次数计数器*/
{
printf("Enter a number with 4 digits:");
scanf("%d",&g); /*请人猜*/
a=z;j=0;k=0;l[0]=l[1]=l[2]=l[3]=0;
for(i=1;i<5;i++) /*i:原数中的第i位数。个位为第一位,千位为第4位*/
{
s=g;m=1;
for(t=1;t<5;t++) /*人所猜想的数*/
{
if(a%10==s%10) /*若第i位与人猜的第t位相同*/
{
if(m&&t!=l[0]&&t!=l[1]&&t!=l[2]&&t!=l[3])
{
j++;m=0;l[j-1]=t; /*若该位置上的数字尚未与其它数字“相同”*/
} /*记录相同数字时,该数字在所猜数字中的位置*/

if(i==t) k++; /*若位置也相同,则计数器k加1*/
}
s/=10;
}
a/=10;
}
printf("Correctly guessed %d digits,",j);
printf("and guessed %d digits in exact position.\n\n",k);
if(k==4) break; /*若位置全部正确,则人猜对了,退出*/
}
printf("Now correctly guessed the whole number after %d times.\n",c);
}
 
 
心算抢答系统
 
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main()
{int i,k,v,score,z,m,n,t=1;
long y,j,a1,a2;
static char c[4]={'+','-','*','/'};
char key;
while (t!=0)
{system("cls");
printf("请选择难度:(0-easy 1-normal 2-hard)");
scanf("%d",&v);
switch(v) /*选择难度*/
{case 0: z=10;break;
case 1: z=100;break;
case 2: z=1000;
}
score=0;
for (i=0;i<=9;i++)
{y=z;
k=random(4);
if((k==0)||(k==1)) y=z*z;
a2=random(y);
j=random(y);
if (c[k]=='/')
{while(a2==0) a2=random(y); /*除数不能为0*/
a1=a2*j;
}
else a1=j;
printf("%ld%c%ld=",a1,c[k],a2);
scanf("%ld",&m);
switch (c[k])
{case '*':n=a1*a2;break;
case '/':n=a1/a2;break;
case '+':n=a1+a2;break;
case '-':n=a1-a2;}
if (m==n)
{printf("答案正确!\n");
score++;
}
else printf("答案错误!\n");}
printf("你的得分是:%d,是否继续(Y/N)?",10*score);
scanf("\n%c",&key);
if ((key!='n')&&(key!='N')) t=1;
else t=0;
}
}
Views: 1414 | Added by: ystyle | Rating: 0.0/0
Total comments: 0
Only registered users can add comments.
[ Sign Up | Log In ]