实验:样本函数实验(统计学实验)
一、实验要求
输入2-100的样本,要求输入格式为小数,样本数为n并确定具体数值,输出不超过每个数的最大素数,并由此计算一阶矩、二阶矩及三阶矩,输入两组数据并验证。
二、实验代码
#include<iostream>
#include<string> //字符串类型
#include<sstream> //输入、输出和输入输出操作
#include<conio.h>
#include<cmath>
#define n 5 //定义个常量n来确定数据个数
using namespace std;
bool check(double a) //定义一个bool方法,检查数据是不是小数,是则返回true,否则返回flase
{
string s;
stringstream ss;
ss << a;
ss >> s;
int m = s.find(".", 0); //从字符串的第一个位置开始寻找有没有带小数点的数
if (m == string::npos)
{
return false;
}
else
return true;
}
int judge(double a) //定义一个方法来计算每一个数据的最大素数
{
int max = 0;
int j = 0;
int m = int(a);
for (int i = m; i > 0; i--)
{
max = i; //记录最大素数
for (j &