C43-数组传参
原题链接:28705.NoteSC++2025-02-08 12:12:54
发布于:江苏
#include<iostream>
using namespace std;
//1. 函数的声明
void f();
//2. 函数的定义(实现) 
void f(string name){	//形参, 接收的 
	cout << name << " xmw666"; 
} 
int sum(int a, int b){
	return a+b; 
}
//function 函数 
bool prime(int n){
	//除了1和它本身之外没有其他的约数 
	//优化, 可以枚举到平方根 sqrt(n) 
	if (n < 2) return false; 
	
	for (int i=2; i<=sqrt(n); i++){
		if (n%i==0) return false; 
	} 
	return true;
} 
int main(){
	//3. 函数的调用 
	string name;
	cin >> name; 
//	f(name);	//实参 
	cout << sum (114514, 114515);
	 
	return 0;
}
#include<iostream>
using namespace std;
int function(int x){
	if (x <= 0){
		return -2*x;
	}else {
		return x;
	}
} 
int main(){
	int x;cin>>x;
	cout << function(x) ; 
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
int f(string s, double n){
	if (s == "ceil") {
		return ceil(n);
	}
	else if (s == "floor"){
		return floor(n);
	}
	else if (s == "round"){
		return round(n);
	}
}
int main(){
	double n; 
	string s;
	cin >> s >> n;
	cout <<  f(s, n);
	return 0;
}
#include<iostream>
using namespace std;
int main(){
//	char a[100] = {'1','2','3','4'};
//	int a[100] = {1,2,3,4,5,6,};
	long long  a[100] = {1,2,3,4,5,6,};
	cout << a << endl; 	
	cout << a+1 << endl;
	cout << a+2 << endl;
	/*
	地址(指针): 内存中的编号 
	数组名表示数组的首地址 
	*/ 
	
	return 0;
}
#include<iostream>
using namespace std;
//数组作为形参的时候 定义方式为 数据类型 a[] 
void f(int a[], int n){
	int mx = a[1], mn = a[1];
	double sum = 0;
	for (int i=1; i<=n; i++){
		sum += a[i];
		if (a[i] > mx) mx = a[i];	//更新最大值 
		if (a[i] < mn) mn = a[i];	//更新最小值 
	} 
	cout<<mx<<' '<<mn<<' ';
	printf("%.1lf", sum/n); 
} 
int main(){
	int a[105] = {}, n;
	cin >> n;
	for (int i=1; i<=n; i++){
		cin >> a[i];
	}
	f(a, n);	//数组的传参 直接写数组名即可 
	return 0;
}
这里空空如也








有帮助,赞一个