这个C语言程序怎么改?
来源:百度知道 编辑:UC知道 时间:2024/07/08 12:01:48
修改下面这个程序,接受一个名为sortOrder 的字符型参数。如果sortOrder是一个a,则只有当第一个数值大于第二个数值时,swap()才交换这两个数值,即这个函数应该按升序返回数值(最小的数第一,最大的数第二)。对于任何其它的数值,函数应该按降序返回数值(最大的数第一,最小的数第二)
)
#include <stdio.h>
void swap(float *,float*);
int main()
{
float firstnum, secnum;
printf(“Enter two numbers:”);
scanf(“%f %f”, &firstnum,&secnum);
printf(“\n before the call to swap():\n”);
printf(“ the value in firstnum is %5.2f\n”,firstnum);
printf(“the value in secnum is %5.2f\n”,secnum);
swap(&firsnum, &secnum);
printf(“\n after the call to swap():\n”);
printf(“the value in firstnum is %5.2f\n”, firstnum);
printf(“the value in secnum is %5.2f\n”, secnum);
return 0;
}
void swap(float *num1Addr, float *num2Addr)
{
float temp;
temp=*num1Addr;
*num1addr=*num2Addr;
*num2addr=temp;
}
不是吧。。。显然没改。。。
)
#include <stdio.h>
void swap(float *,float*);
int main()
{
float firstnum, secnum;
printf(“Enter two numbers:”);
scanf(“%f %f”, &firstnum,&secnum);
printf(“\n before the call to swap():\n”);
printf(“ the value in firstnum is %5.2f\n”,firstnum);
printf(“the value in secnum is %5.2f\n”,secnum);
swap(&firsnum, &secnum);
printf(“\n after the call to swap():\n”);
printf(“the value in firstnum is %5.2f\n”, firstnum);
printf(“the value in secnum is %5.2f\n”, secnum);
return 0;
}
void swap(float *num1Addr, float *num2Addr)
{
float temp;
temp=*num1Addr;
*num1addr=*num2Addr;
*num2addr=temp;
}
不是吧。。。显然没改。。。
#include <stdio.h>
void swap(float *,float*);
int main()
{
float firstnum, secnum;
printf("Enter two numbers:");
scanf("%f %f", &firstnum,&secnum);
printf("\n before the call to swap():\n");
printf("the value in firstnum is %5.2f\n",firstnum);
printf("the value in secnum is %5.2f\n",secnum);
swap(&firstnum, &secnum);
printf("\n after the call to swap():\n");
printf("the value in firstnum is %5.2f\n", firstnum);
printf("the value in secnum is %5.2f\n", secnum);
return 0;
}
void swap(float *num1Addr, float *num2Addr)
{
float temp;
if(*num1Addr > *num2Addr)
{
temp=*num1Addr;
*num1Addr=*num2Addr;
*num2Addr=temp;
}
}
改好了