《C语言程序设计》江宝钏主编-习题8-2-指针参数传递多个返回值

AC代码:

/*《C语言程序设计》江宝钏主编-习题8-2-指针参数传递多个返回值
Description 
编写函数,其功能是对传送过来的两个浮点数求出和值与差值,并通过形参传回调用函数。
注意:此题用C语言完成时,必须使用指针方法处理,只提交头文件和
void compute(float a,float b,float *c,float *d)
函数,系统将自动附加下面的main函数后运行,请复制下面的main函数用于调试函数。
其他语言的答案无此要求。
int main(){ 
   float a,b,c,d; 
   scanf("%f%f",&a,&b); 
   compute(a,b,&c,&d); 
   printf("%g %g",c,d); 
  
} 
Input 
两个浮点数a,b
Output 
a+b a-b 用%g输出

Sample Input Copy 
1.5 2.5
Sample Output Copy 
4 -1
*/

#include <stdio.h>
#include <math.h>
void compute(float a,float b,float *c,float *d);
int main(){
   float a,b,c,d; 
   scanf("%f%f",&a,&b); 
   compute(a,b,&c,&d); 
   printf("%g %g",c,d); 
  return 0;
}
void compute(float a,float b,float *c,float *d){
   *c=a+b;
   *d=a-b;
}


//标程:
#include <stdio.h>
void compute(float a,float b,float *c,float *d);
int main(void)
{
	float a,b,c,d;
	scanf("%f%f",&a,&b);
	compute(a,b,&c,&d);
	printf("%g %g",c,d);
	return 0;
}
void compute(float a,float b,float *c,float *d)
{
	//c=a+b
	//d=a-b
	*c=a+b;
	*d=a-b;
}
发布了39 篇原创文章 · 获赞 7 · 访问量 3669

猜你喜欢

转载自blog.csdn.net/qq_45599068/article/details/104158022