else break;
}
sum=sum+m-1; c=sum%7; return(c);
}
运行结果:
提高题: 1.兑奖程序:
体育彩票由七位数字组成,第七位数字是特别号码,只有在前面六位数都正确的时候才对第七位数。现在体彩中心给出了一个特等奖号码是1234567,程序要求在屏幕上任输入一个号码判断出中了几等奖。(如果七位数字都相同就是特等奖;前六位相同为一等奖,任连续五位相同为二等奖,任连续四位相同为三等,任连续三位相同为四等,任连续两位相同位五等。(注意:除特等奖外都不考虑第七位)
按照以下对奖方式,写出程序:
不按位对奖:也就是说不管是多少位,只要有连续几位相同都可以。比如说给出的号码是:2312345就中了三等奖(因为1234和前面相同,注意,这里的第七位是5,虽然也相同但是不能算) 设计思路: 调试结果:
#include \void main() {
char a[7],b[7];
int i,j,num,max=0;
printf(\请输入中奖号码:\gets(a);
printf(\请输入兑奖号码:\gets(b);
for(j=0;j<6;j++) { }
for(i=0,num=0;i<6;i++) {
if(a[i]==b[j]) { }
j++; num++;
}
if(num>max) max=num;
}
if(max==6) { }
if(a[6]==b[6]) printf(\你中了特等奖\\n\else printf(\你中了一等奖\\n\
else if(max==5) printf(\你中了二等奖\\n\else if(max==4) printf(\你中了三等奖\\n\else if(max==3) printf(\你中了四等奖\\n\else if(max==2) printf(\你中了五等奖\\n\else printf(\谢谢惠顾\\n\
运行结果:
2.学生成绩管理系统:
编写一个简单的学生信息管理程序,能实现对学生信息的简单管理。具体要求为:
建立一个4个学生的信息登记表,每个学生的信息包括:学号,姓名,和3门课程的成绩(FOX,C,ENGLISH)。
程序运行时显示一个简单的菜单,例如:
(1):信息输入(INPUT) (2):总分统计(COUNT) (3):总分排序(SORT) (4):查询(QUERY)
其中:
(1):对4个学生的信息进行输入;
(2):对每个学生的3门课程统计总分;
(3):对4个学生的总分按降序排序并显示出来;
(4):查询输入一个学号后,显示出该学生的有关信息;
请同学们根据实际情况再进行适当扩展。 #include \#include \struct student {
long num; char name[20]; float fox; float c; float english; float sum;
struct student *next; };
int n;
struct student *input(void){ int boolean =0;
}
struct student *sort(struct student *head)
struct student *head,*p1,*p2; n=0;
head=p1=p2=(struct student*)malloc(sizeof(struct student)); printf(\请输入学生学号: \scanf(\
printf(\请输入学生姓名: \
scanf(\
printf(\请输入学生各科成绩(FOR,C,ENGLISH): \scanf(\
p1->sum=p1->fox+p1->c+p1->english;// COUNT;
printf(\是否继续输入? 1/继续,0/结束\scanf(\while(boolean) {
}
p1->next=NULL; return (head);
n++;
p2=p1;
p1=(struct student*)malloc(sizeof(struct student));
printf(\请输入学生学号: \scanf(\
printf(\请输入学生姓名: \
scanf(\
printf(\请输入学生各科成绩(FOR,C,ENGLISH): \scanf(\p1->sum=p1->fox+p1->c+p1->english; p2->next=p1;
printf(\是否继续输入? 1/继续,0/结束\scanf(\
{
struct student *p1,*p2,*p; int i,j,k; k=n;
if(head!=NULL) {
for(j=0;j for(i=0,p=p1=head,p2=head->next; i void print(struct student *head) { if(head!=NULL) { while(head!=NULL) } { } if(p1->sum < p2->sum) { } if(p==head&&i==0) { } else { } p1->next=p2->next; p2->next=p1; p->next=p2; p=p2; p1->next=p2->next; p2->next=p1; head=p2; p=p2; else p=p1; return(head); else { printf(\木有人!\ return(head); } { printf(\
相关推荐: