1、题目:有五个学生,每个学生有 3 门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩) ,计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件“stud“中。1.程序分析:2.程序源代码:#include “stdio.h“struct student char num6;char name8;int score3;float avr; stu5;main()int i,j,sum;FILE *fp;/*input*/for(i=0;icj)t=ci;ci=cj;cj=t;printf(“n C file is:n“);fp=fopen(“C“,“w“);for(i=0;i=
2、afputc(stri,fp);i+;fclose(fp);fp=fopen(“test“,“r“);fgets(str,strlen(str)+1,fp);printf(“%sn“,str);fclose(fp);题目:计算字符串中子串出现的次数1.程序分析:2.程序源代码:#include “string.h“#include “stdio.h“main() char str120,str220,*p1,*p2;int sum=0;printf(“please input two stringsn“);scanf(“%s%s“,str1,str2);p1=str1;p2=str2;whil
3、e(*p1!=0)if(*p1=*p2)while(*p1=*p2p2+;elsep1+;if(*p2=0)sum+;p2=str2;printf(“%d“,sum);getch();题目:家庭财务管理小程序1.程序分析:2.程序源代码:/*money management system*/#include “stdio.h“#include “dos.h“main()FILE *fp;struct date d;float sum,chm=0.0;int len,i,j=0;int c;char ch4=“,ch116=“,chtime12=“,chshop16,chmoney8;pp: c
4、lrscr();sum=0.0;gotoxy(1,1);printf(“|-|“);gotoxy(1,2);printf(“| money management system(C1.0) 2000.03 |“);gotoxy(1,3);printf(“|-|“);gotoxy(1,4);printf(“| - money records - | - today cost list - |“);gotoxy(1,5);printf(“| - |-|“);gotoxy(1,6);printf(“| date: - | |“);gotoxy(1,7);printf(“| | | | |“);goto
5、xy(1,8);printf(“| - | |“);gotoxy(1,9);printf(“| thgs: - | |“);gotoxy(1,10);printf(“| | | | |“);gotoxy(1,11);printf(“| - | |“);gotoxy(1,12);printf(“| cost: - | |“);gotoxy(1,13);printf(“| | | | |“);gotoxy(1,14);printf(“| - | |“);gotoxy(1,15);printf(“| | |“);gotoxy(1,16);printf(“| | |“);gotoxy(1,17);pr
6、intf(“| | |“);gotoxy(1,18);printf(“| | |“);gotoxy(1,19);printf(“| | |“);gotoxy(1,20);printf(“| | |“);gotoxy(1,21);printf(“| | |“);gotoxy(1,22);printf(“| | |“);gotoxy(1,23);printf(“|-|“);i=0;getdate(sprintf(chtime,“%4d.%02d.%02d“,d.da_year,d.da_mon,d.da_day);for(;)gotoxy(3,24);printf(“ Tab _browse co
7、st list Esc _quit“);gotoxy(13,10);printf(“ “);gotoxy(13,13);printf(“ “);gotoxy(13,7);printf(“%s“,chtime);j=18;ch0=getch();if(ch0=27)break;strcpy(chshop,“);strcpy(chmoney,“);if(ch0=9)mm:i=0;fp=fopen(“home.dat“,“r+“);gotoxy(3,24);printf(“ “);gotoxy(6,4);printf(“ list records “);gotoxy(1,5);printf(“|-|“);gotoxy(41,4);printf(“ “);gotoxy(41,5);printf(“ |“);while(fscanf(fp,“%10s%14s%fn“,chtime,chshop,i=0;题目:时间函数举例 4,一个猜数游戏,判断一个人反应快慢。 (版主初学时编的)1.程序分析:2.程序源代码:#include “time.h“#include “stdlib.h“#include “stdio.h“main()char c;clock_t start,end;time_t a,b;double var;int i,guess;srand(time(NULL);