手机扫描二维码答题
00:00:00
第7课 自定义函数
录音中...
*
1.
#include<bits/stdc++.h>
using namespace std;
int f(int x,int y){
return x-y;
}
int main(){
int s;
s=f(5,2)+f(7,6);
cout<<s;
return 0;
}
输出:
*
2.
#include<bits/stdc++.h>
using namespace std;
int f( int x,int &y ){
x++;
y++;
}
int main(){
int a=5,b=2 ;
f(a,b);
cout<<a<<" "<<b;
return 0;
}
输出:
*
3.
看程序写结果:
#include<bits/stdc++.h>
using namespace std;
int f(int x,int y){
return x>y?x:y;
}
int main(){
int i,s,a[5]={4,2,7,6,1};
s=a[0];
for(i=1;i<=4;i++)
s=f(s,a[i]);
cout<<s;
return 0;
}
输出:
*
4.
#include<bits/stdc++.h>
using namespace std;
int f( int &x,int &y ){
int k=x;
x=y;
y=k;
}
int main(){
int a=2,b=7 ;
f(a,b);
cout<<a<<" "<<b;
return 0;
}
输出:
*
5.
#include<bits/stdc++.h>
using namespace std;
int f(int x,int y){
return x*y;
}
int main(){
int i,s,a[5]={3,2,2,5,1};
s=1;
for(i=0;i<=4;i++)
s=f(s,a[i]);
cout<<s;
return 0;
}
输出:
您的姓名:
评价对象得分
字体大小