c语言

 

< script >

 
var  now = new  Date();
 
var  t = now.getDate();
 
var  m = now.getMonth();
 
var  y = now.getFullYear();
 
var  w = now.getDay();

  
switch  (w)
    
{
        
case 1:
        w
="星期一";
        
break;
        
case 2:
        w
="星期二";
        
break;
        
case 3:
        w
="星期三";
        
break;
        
case 4:
        w
="星期四";
        
break;
        
case 5:
        w
="星期五";
        
break;
        
case 6:
        w
="星期六";
        
break;
        
case 0:
        w
="星期日";
        
break;
     }


    document.write(
" 今天是  " + y + " " + (m + 1 ) + " " + t + " " + " <font color=red> " + w + " </font> " );
</ script >
#include <stdio.h>
struct student
{
 int no;        //学号
 char name[15]; //姓名
 int score[3];  //三门课程的成绩
 double avr;    //平均成绩
};

struct student stu[50]; //声明一个结构数组变量

struct student input();
void display(struct student stud[],int count);
void sort(struct student stud[],int count);
void insert(struct student stud[],int count);
void del(struct student stud[],int count);

void main()
{
 int count;
    char ch;
 ch='y';
   
 printf("请输入学员信息。");
 printf("/n");
 count=0;
 while ((ch=='y') || (ch=='Y'))
 {

  stu[count]=input();       //调用录入信息函数
  count++;
  printf("/n 是否继续?(y or n)");
  scanf(" %c",&ch);
 }
 printf("/n排序前的学员信息如下:");
 display(stu,count);           //调用显示信息函数
 sort(stu,count);              //调用排序函数
 printf("/n排序后的学员信息如下:");
 display(stu,count); 
 
 printf("/n/n是否要插入新学员?(y or n)");
 scanf(" %c",&ch);
 if(ch=='y' || ch=='Y')
 {
  insert(stu,count);       //调用插入信息函数
  count++;
  printf("/n插入新学员后的学员信息如下:");
  display(stu,count);
 }

 printf("/n/n是否要删除某个学员?(y or n)");
 scanf(" %c",&ch);
 if(ch=='y' || ch=='Y')
 {
  del(stu,count);    //调用删除信息函数
  count--;
  printf("/n删除后学员的信息如下:");
  display(stu,count);
 }
}

struct student input()   //录入信息函数
{
  struct student studn;
     int sum,j;
     printf("/n学号:");
  scanf("%d",&studn.no);
  
  printf("/n姓名:");
  scanf("%s",studn.name);
  
  printf("/n三门成绩:");
  sum=0;
  printf("/n");
  for(j=0;j<3;j++)
  {
   printf("成绩%d: ",j+1);
   scanf("%d",&studn.score[j]);
   sum+=studn.score[j];
  }
  studn.avr=sum/3.0;
  return studn;
}

void display(struct student stud[],int count) //显示信息函数
{
 int i;
 printf("/n学号/t姓名/t/t平均成绩");
 printf("/n");
 for(i=0;i<count;i++)
 {
  printf("%-03d",stud[i].no);
  printf("/t%-15s",stud[i].name);
  printf("/t%-10.1f",stud[i].avr);
  printf("/n");
 }
}

void sort(struct student stud[],int count)  //排序函数
{
 /*  冒泡排序法*/
 struct student temp;
    int a,b;
 for(a=0;a<count;a++)
 {
   for(b=0;b<count-1-a;b++)
   {
    if (stu[b].avr<stu[b+1].avr)
       {temp=stu[b+1];
    stu[b+1]=stu[b];
          stu[b]=temp;
   } 

 }
 
 }
 
}

void insert(struct student stud[],int count)  //插入函数
{
 /*插入一个学员的信息,要求插入后的学员信息依然有序*/
  int x,y;
  struct student in;
   in=input();

  for(x=0;x<count;x++)
  {
    if(stu[x].avr<in.avr)
  break;
  }
   for(y=count;y>x;y--)  //为要插入的结构空出位置
   {
     stu[y]=stu[y-1];
   } 
   stu[x]=in;            //将要插入的结构保存到该位置
 

 
}

void del(struct student stud[],int count) //删除函数
{
 /*删除一个指定学号的学员信息,要求删除后的学员信息依然有序*/
  int o,p,num;
  printf("请输入您要删除的学号:");
  scanf("%d",&num);
  for(o=0;o<count;o++)
 {
    if(num==stu[o].no)
    break;
  }
  for(p=o+1;p<count;p++)
  {
   stu[o]=stu[p];
  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值