各个细节就不加说明了,因为你题目已经说了;本人是正在学C语言,为了帮你编这个程序用了1个小时左右,希望多多支持一下,如果发现有什么错误的地方,请留言;谢谢
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<stdio.h>
void input(float *p,int n)
{
float a[n];
int i;
for(i=0;i<n;i++)
{
*(p+i)=&(a+i);
}
}
void output(float *p,int n)
{
int i;
float a[n+1];
*p=a[0];
for(i=0;i<n+1;i++)
return(*(p+i));
}
void sort(float *p,int n,char style)
{
int i;
float t,a[n];
*p=a[0];
for(i=0;i<n;i++)
{
if(style=='a')
{
if(*(p+i-1)>*(p+i))
{
t=*(p+i-1);
*(p+i-1)=*(p+i);
*(p+i)=t;
}
}
else if(style=='d')
{
if(*(p+i-1)<*(p+i))
{
t=*(p+i-1);
*(p+i-1)=*(p+i);
*(p+i)=t;
}
}
}
void insert(float *p,int n,float x)
{
int i;
float a[n],t;
*p=a[0];
for(i=0;i<n+1;i++)
{
if(*(p+i-1)>*(p+i))
{
if(*(p+n+1)>*(p+i))
{
t=*(p+n+1);
*(p+n+1)=*(p+i);
*(p+i)=t;
}
}
else if(*(p+n+1)<*(p+i))
{
t=*(p+n+1);
*(p+n+1)=*(p+i);
*(p+i)=t;
}
}
int seek(float *p,int n,float x)
{
int i;
float a[n],t;
*p=a[0];
for(i=0;i<n;i++)
{
if(*(p+i)==x)
{
printf("the char in the this:%d",i);
}
else
{
*(p+n+1)=x;
}
}
void insert(*p,n,x);
}
void main()
{float stu[11],x; /* 定义保存成绩的数组 */
char sortch;int n;
puts("Please input 10 score:");
input(stu,10); /* 调用函数实现成绩键盘输入 */
getchar(); /* 消化数据输入最后的回车符 */
printf("Please input sort style:");
sortch=getchar(); /* 接收排序字符 */
sort(stu,10,sortch); /* 调用函数对成绩排序 */
puts("=============after sort output==============");
output(stu,10); /* 输出排序后的10个成绩 */
puts("Please input another score:");
scanf("%f",&x); /* 输入一个要插入的新成绩 */
n=seek(stu,10,x);
if(n==-1)
printf("No find &f\n",x);
else insert(stu,10,x); /* 调用函数将x插入到数组stu中,使数组依然有序 */
puts("============ after insert====================");
output(stu,11);
}
温馨提示:答案为网友推荐,仅供参考