void DrawSnow()
{int i;
int sx[62];
randomize();
for(i=0;i<62;i++)
sx[i]=(i+2)*10;
cleardevice();
while(!kbhit())
{
Pr();
if(snownum!=100)
{
snow[snownum].speed=2+random(5);
i=random(62);
snow[snownum].x=sx[i];
snow[snownum].y=10-random(100);
}
for(i=0;i<snownum;i++)
putimage(snow[i].x,snow[i].y,save2,COPY_PUT);
Pr();
if(snownum!=100)
snownum++;
/*delay(300);*/
setfillstyle(SOLID_FILL,15);
for(i=0;i<snownum;i++)
{
snow[i].y+=snow[i].speed;
putimage(snow[i].x,snow[i].y,save1,COPY_PUT);
if(snow[i].y>500)
snow[i].y=10-random(200);
}
change++;
if(change==140)
change=10;
}
nosound();
}
2学生成绩管理系统(自己设计界面)
#define N 1
struct student
{char num[10];
char name[10];
int score[4];
float ave;
}stu[N];
main()
{int i,j,max,maxi,sum;
float average;
for(i=0;i<N;i++)
{printf("Please input scores of student %d :\n",i+1);
printf("NO.:");
scanf("%s",stu[i].num);
printf("name:");
scanf("%s",stu[i].name);
for(j=0;j<3;j++)
{printf("score %d :",j+1);
scanf("%d",&stu[i].score[j]);
}
}
average=0;
max=0;
maxi=0;
for(i=0;i<N;i++)
{sum=0;
for(j=0;j<3;j++)
sum+=stu[i].score[j];
stu[i].ave=sum/3.0;
average+=stu[i].ave;
if(sum>max)
{max=sum;
maxi=i;
}
}
average/=N;
printf(" NO. name score1 score2 score3 average\n");
for(i=0;i<N;i++)
{printf("%5s",stu[i].num);
printf("%10s",stu[i].name);
for(j=0;j<3;j++)
printf("%9d",stu[i].score[j]);
printf("%8.2f\n",stu[i].ave);
}
printf("average=%6.2f\n",average);
printf("The highest score is : %s,score total :%d\n",stu[maxi].name,max);
getch();
}
3.异或加密与解密
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
void jiami(char *in,char *pwd,char *out);
void main(int argc,char *argv[])
{
char in[30];
char out[30];
char pwd[8];
if(argc!=4)
{
printf("\Input file name:\n");
gets(in);
printf("Please enter password:\n");
gets(pwd);
printf("Output file name:\n");
gets(out);
jiami(in,pwd,out);
}
else
{
strcpy(in,argv[1]);
strcpy(pwd,argv[2]);
strcpy(out,argv[3]);
jiami(in,pwd,out);
}
}
void jiami(char *in,char *pwd,char *out_file)
{
FILE *fp1,*fp2;
register char ch;
int j=0;
int k=0;
fp1=fopen(in,"rb");
if(fp1==NULL)
{
printf("Cannot open in-file!\n");
exit(1);
}
fp2=fopen(out_file,"wb");
if(fp2==NULL)
{
printf("Cannot open or create output-file!\n");
exit(1);
}
while(pwd[++k]);
ch=fgetc(fp1);
while(!feof(fp1))
{
fputc(ch^pwd[j>=k?j=0:j++],fp2);
ch=fgetc(fp1);
}
fclose(fp1);
fclose(fp2);
}