第十五周项目3: 两数和与差(用参数带回结果)

来源:互联网 发布:网络神话txt下载 编辑:程序博客网 时间:2024/05/22 00:53
下面的程序,输入两个整数,调用函数ast后,输出了两数之和及两数之差。阅读程序,补全程序中空白处。
[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #include <iostream>  
  2. using namespace std;  
  3. void ast(int x,int y,int *cp,int *dp)  
  4. {  
  5.    //补全函数的定义  
  6.    ___(1)____=x+y;  
  7.    ___(2)____=x-y;  
  8. }  
  9. int main()  
  10. {  
  11.    int a,b,c,d;  
  12.    cin>>a>>b;  
  13.    //下面调用函数ast  
  14.    ______(3)______  
  15.    cout<<c<<" "<<d<<endl;  
  16.    return 0;  
  17. }  
参考解答:
[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码片
  1. #include <iostream>  
  2. using namespace std;  
  3. void ast(int x,int y,int *cp,int *dp)  
  4. {  
  5.     //补全函数的定义  
  6.     *cp=x+y;  
  7.     *dp=x-y;  
  8. }  
  9. int main()  
  10. {  
  11.     int a,b,c,d;  
  12.     cin>>a>>b;  
  13.     //下面调用函数ast  
  14.     ast(a,b,&c,&d);  
  15.     cout<<c<<" "<<d<<endl;  
  16.     return 0;  
  17. }  
运行结果:

0 0
原创粉丝点击