#include<stdio.h>
#include<stdlib.h>
#define LEN sizeof(struct student)
struct student
{
int num;
char name[100];
struct student *next;
};
int n;
struct student *scan(void)
{
struct student *p1,*p2,*head;
p1=p2=(struct student *)malloc(LEN);
scanf("%d%s",&p1->num,p1->name);
while(p1->num!=0)
{
n++;
if(n1)
head=p1;
else
p2=p1->next;
p1=p2;
p1=(struct student *)malloc(LEN);
scanf("%d%s",&p1->num,p1->name);
}
p2->nextNULL;
return(head);
}
void print( struct student *head)
{
struct student *p;
printf("\n Now, these %d records are :\n", n);
p=head;
if((head)!=NULL)
do
{
printf("%d,%s\n", p->num, p->name);
p=p->next;
}
while(p !=NULL);
}
main()
{
print(scan());
}
2.不会
3.
#include<stdio.h>
main()
{
int i,j,k,n=0;
for(i=0;i<5;i++)
for(j=i+1;j<5;j++)
{
for(k=j+1;k<5;k++)
{
n++;
printf("%d,%d,%d “,i,j,k);
}
}
printf(”%d",n);
}
4.
#include<stdio.h>
swap(int *a,int *b)
{
int n;
n=*a;*a=*b;*b=n;
}
main()
{
int a,b,c,*p1,*p2,*p3;
scanf("%d%d%d",&a,&b,&c);
p1=&a;p2=&b;p3=&c;
if(*p1<*p2)
swap(p1,p2);
if(*p1<*p3)
swap(p1,p3);
if(*p2<*p3)
swap(p2,p3);
printf("%d%d%d",*p1,*p2,*p3);
}
5.不明白
6.
#include <stdio.h>
int max,min;
fun1(int a[10])
{
max=a[0];
int i;
for(i=0;i<10;i++)
if(max<a[i])
max=a[i];
}
fun2(int *a)
{
min=a[0];
int i;
for(i=0;i<10;i++)
if(min>a[i])
min=a[i];
}
main()
{
int i,a[10];
for(i=0;i<10;i++)
scanf("%d",&a[i]);
fun1(a);
fun2(a);
printf(“max=%d min=%d”,max,min);
}
7.
#include<stdio.h>
struct student
{
char name[100];
int change[4];
}a[3];
float fun(struct student a[3])
{
int i,j;float sum=0;
for(i=0;i<3;i++)
for(j=0;j<4;j++)
sum+=a[i].change[j];
return(sum/12);
}
main()
{
int i,j;
for(i=0;i<3;i++)
{
scanf("%s",a[i].name);
for(j=0;j<4;j++)
{
scanf("%d",&a[i].change[j]);
}
}
printf("%f",fun(a));
}
8.
#include<stdio.h>
struct student
{
char name[100];
int change[4];
}a[13];
float fun(struct student a[13])
{
int i,j,n;
for(i=0;i<13;i++)
{
n=0;
for(j=0;j<4;j++)
{
if(a[i].change[j]<60)
n++;
}
if(n>=2)
{
printf("%s ",a[i].name);
for(j=0;j<4;j++)
printf("%d ",a[i].change[j]);
printf("\n");
}
}
}
main()
{
int i,j;
for(i=0;i<13;i++)
{
scanf("%s",a[i].name);
for(j=0;j<4;j++)
{
scanf("%d",&a[i].change[j]);
}
}
fun(a);
}
9.不明白
10.
#include <stdio.h>
float *search(float (*p1)[4],int n)
{
float pt;
pt=(p1+n);
return pt;
}
int main(void)
{
float score[][4]={{60,70,80,90},{56,89,67,88},{34,78,90,66}};
float p;
int i,k;
printf(“输入要找的学生号:\n”);
scanf("%d",&k);
printf(“第%d个学生的全部成绩为:\n”,k);
p=search(score,k);
for(i=0;i<4;i++)
{
printf("%f\t",(p+i));
}
printf("\n");
return 0;
}