#include
#include
#define N 30
void Input(int n,int *p1, char *p3[N], char *p2[N]);
void Average(int n,int *p1);
void Task6(int n,int *p1, char *p3[N], char *p2[N]);
int main()
{
int n, sorce[N];
int *p1=sorce;
printf("how many students?\n");
scanf("%d",&n);
char number[n][N];
char name[n][N];
char *p2[N];
char *p3[N];
int i = 0;
for(;i<n;i++)
{
p2[i]=name[i];
p3[i]=number[i];
}
Input(n,p1,p3,p2);
Average(n,p1);
Task6(n,p1,p3,p2);
}

void Input(int n,int *p1, char *p3[N], char *p2[N])
{
int i=0;
for(;i<n;i++)
{
printf("No.%d students name: \n",i+1);
getchar();
gets(*p2+i);
printf("the students number: \n");
gets(*p3+i);
printf("thr students sorce: \n");
scanf("%d",(p1+i));

``````}
``````

}

void Average(int n,int p1)
{
int i=0,sum=0;
for(;i<n;i++)
{
sum+=
(p1+i);
}
printf("the sum is %d\n",sum);
printf("the average is %d\n",sum/n);
}

void Task6(int n,int *p1, char *p3[N], char *p2[N])
{
int temp1;
char *temp2;
char *temp3;
int i =0,j;
for(;i {
for(j=i+1;j {
if(p1[i]>p1[j])
{
temp1 = p1[i];
p1[i] = p1[j];
p1[j] = temp1;
temp2 = p2[i];
p2[i] = p2[j];
p2[j] = temp2;
temp3 = p3[i];
p3[i] = p3[j];
p3[j] = temp3;

``````        }

}
}
for(;i<n;i++)
{
printf("%6d%13s%13s\n",p1[i],p2[i],p3[i]);
}
``````

}

1个回答