⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 6-5.cpp

📁 为初学者提供的最佳的C++程序设计源程序库
💻 CPP
字号:
#include<iostream.h>
#include<stdlib.h>
# define N 12
void process(float *p,int n,float (*fun)(float *p,int n));
float arr_add(float arr[],int n)
{
	int i;
	float sum=0;
	for(i=0;i<n;i++)
	    sum=sum+arr[i];
	return(sum);
}
float odd_add(float *p,int n)
{
	int i;
	float sum=0;
	for(i=0;i<n;i=i+2,p=p+2)
	    sum=sum+*p;
	return(sum);
}
float arr_ave(float *p,int n)
{
	int i;
	float sum=0,ave;
	for(i=0;i<n;i++)
	   ave=sum/n;
	return(ave);
}
float arr_max(float arr[],int n)
{
	int i;
	float max;
	max=arr[0];
	for(i=0;i<n;i++)
		if(arr[i]>max)
	    max=arr[i];
	return(max);
}
void process(float *p,int n,float (*fun)(float *p,int n))
{
	float result;
	result=(*fun)(p,n);
	cout<<result;
}
void main()
{
void process(float *p,int n,float (*fun)(float *p,int n));
	float arr_add(float arr[],int n);
	float odd_add(float *p,int n);
	float arr_ave(float *p,int n);
	float arr_max(float arr[],int n);
	static float a[]={1.5,3.8,5.6,7.8,91.6,1.61,13.3,15.0,17.5,19.9,21.7,13.0};
	int n=N;
	cout<<"\nthe sum of "<<n<<"element is :"<<"\n";
	process(a,n,arr_add);
	cout<<"\nthe sum of old element is :"<<"\n";
    process(a,n,odd_add);
	cout<<"\nthe sum of average of"<<n<<" element is :"<<"\n";
	process(a,n,arr_ave);
	cout<<"\nthe sum of maximun of"<<n<<" element is :"<<"\n";
	process(a,n,arr_max);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -