C++ 常用数学运算(加减乘除)代码实现 Utils.h, Utils.cpp(有疑问欢迎留言)

Utils.h

#pragma once
class Utils {
public:
    static double* array_diff(double*A,double B[],int n);
    static double* array_multiplication(double*A, double B[], int n);
    static double array_sum(double*A, int n);    
    static double* array_pow(double*A, int m, int n);
};

Utils.cpp

#include "Utils.h"
#include "math.h"

double* Utils::array_diff(double*A, double B[], int n)
{
    double *diff = new double[n];
    for (int i = 0; i < n; i++)
    {
        diff[i] = A[i]-B[i];
    }
    return diff;
}

double* Utils::array_multiplication(double*A, double B[], int n)
{
    double *mul = new double[n];
    for (int i = 0; i < n; i++)
    {
        mul[i] = A[i] * B[i];
    }
    return mul;
}

double Utils::array_sum(double*A, int n)
{
    double sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum = sum + A[i];
    }
    return sum;
}

double* Utils::array_pow(double*A, int m, int n)
{
    double* sqt = new double[m];
    for (int i = 0; i < m; i++)
    {
        sqt[i] = pow(A[i], n);
    }
    return sqt;
}

 

posted @ 2019-11-03 16:49  我们都是大好青年  阅读(1042)  评论(0编辑  收藏  举报