#include<stdio.h>
#define N 200
struct child
{
char name[10];
char sex[3];
int age;
int height;
float weight;
struct {
int year;
int month;
int day;
}bdate;
}ch[N];
void input()
{
int i;
for(i=0;i<N;i++)
{
printf("\n请输入第%d名小朋友信息:\n",i+1);
printf("姓名:");
scanf("%s",ch[i].name);
printf("性别:");
scanf("%s",ch[i].sex);
printf("年龄:");
scanf("%d",&ch[i].age);
printf("身高:");
scanf("%d",&ch[i].height);
printf("体重:");
scanf("%f",&ch[i].weight);
printf("出生日期[YYYY-MM-DD]:");
scanf("%d-%d-%d",&ch[i].bdate.year,&ch[i].bdate.month,&ch[i].bdate.day);
}
}
void sort()
{
struct child ct;
int i,j;
for(i=0;i<N-1;i++)
for(j=0;j<N-i-1;j++)
if(ch[j].height<ch[j+1].height)
{
ct=ch[j];
ch[j]=ch[j+1];
ch[j+1]=ct;
}
}
void output()
{
int i;
printf("\n\t幼儿园小朋友一览(依身高排序)\n");
printf("===================================================\n");
printf(" 姓名 性别 年龄 身高 体重 出生日期 \n");
printf("===================================================\n");
for(i=0;i<N;i++)
printf(" %-8s %-2s %2d %d %3.1f %d.%d.%d\n",ch[i].name,ch[i].sex,ch[i].age,ch[i].height,ch[i].weight,ch[i].bdate.year,ch[i].bdate.month,ch[i].bdate.day);
}
void main()
{
input();
sort();
output();
}
//分给的忒少,呵呵
⑵ C语言时钟源代码
#include<graphics.h> /* 引入.h */
#include<math.h> /* 引入math.h */
#include<dos.h> /* 引入dos.h */
#define pi 3.1415926 /*定义pi=3.14159*/
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y) /*定义……*/
void init() /*初始化程序*/
{int i,l,x1,x2,y1,y2; /*定义……*/
setbkcolor(1); /*设置颜色*/
circle(300,240,200); /*作园*/
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++) /*循环(算时间)*/
{if(i%5==0) l=15;
else l=5;
x1=200*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s; /*定义*/
struct time t[1];
initgraph(&gd,&gm,"d:\\tc");
init();
setwritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_sec; /*定义时分秒*/
setcolor(7); /*设置颜色*/
d(150,h,30);
setcolor(14);
d(170,m,6);
setcolor(4);
d(190,s,6);
while(!kbhit()) /*获取键盘相应*/
{while(t[0].ti_sec==s)
gettime(t); /*C语言中得到时间的函数*/
sound(400); /*计算时间……*/
delay(70);
sound(200);
delay(30);
nosound();
setcolor(4);
d(190,s,6);
s=t[0].ti_sec;
d(190,s,6);
if (t[0].ti_min!=m)
{
setcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if (t[0].ti_hour!=h)
{ setcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch(); /*设置空格后退出*/
closegraph();
}
http://..com/question/121241211.html
⑶ 求C语言单链表 源代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct people
{
char name[10];
int age;
struct people * next;
};
int main()
{
struct people * head=NULL;
struct people * prev , * current;
int flag=1;
while(flag!=0)
{
printf("请输入学生姓名,年龄:(年龄输入0结束所有输入工作)
");
current=(struct people *)malloc(sizeof(struct people));
if(head==NULL)
head=current;
else
prev->next=current;
current->next=NULL;
scanf("%s",¤t->name);
scanf("%d",¤t->age);
prev=current;
flag=current->age;
}
printf("Output:
");
if(head==NULL)
printf("无资料。
");
else
{
current=head;
while(current->next!=NULL)
{
printf("姓名:%s
年龄:%d
",current->name,current->age);
current=current->next;
}
}
}
至于排序,断开旧链表,将前后指针链接到新的节点就好
如果还有问题欢迎再问哈