标签:int input isp actor 计算 nbsp n+1 class continue
//计算1/1!-1/3!+1/5!-1/7!+…+(-1)^(n+1)/(2n-1)! float mathTest(int n){ int sign = 1; float sum = 1, t = 1; for (int i = 1; i <= n - 1; i++) { sign = sign*(-1); t = t*(2 * i)*(2 * i + 1); sum = sum + sign / t; } return sum; } //判断一个是否为完数(如:28=1+2+4+7+14) //寻找(0,n]以内的所有完数 void IsPnum(int n){ int i, a[100]; for (i = 1; i <= n;i++) { int s = 1, k = 0; for (int j = 2; j < i;j++) { if ((i%j)==0) { s = s + j; a[k] = j; k++; } } if ((i==s)&&(s!=1)) { cout << s << ",it‘s factors are:" << "1"; for (int i = 0; i < k;i++) { cout << "," << a[i]; } cout << endl; } } } //求矩阵的鞍点,即行上最小而列上最大的点 void FindAnDian(){ //输入一个n*n的矩阵 cout << "input n*n matric: " << endl; int a[3][3], n = 3, col, row ,AD=0; //cin >> n; for (int i = 0; i < n;i++) { for (int j = 0; j < n;j++) { cin >> a[i][j]; } } //打印矩阵 for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout<< a[i][j]; } cout << endl; } //寻找鞍点 for (int i = 0; i < n;i++) { int t = a[i][0]; for (int j = 0; j < n;j++) { if (t>a[i][j]) { t = a[i][j]; col = j; } } for (row = 0; row < n;row++) { if (t<a[row][col]) { break;//如果第col列中有元素大于t;则直接终止判断是否为列最大元素 } } if (row<n) { continue;//如果row<n即证明第i行的最小元素不是第col列的最大元素直接结束本次循环。寻找下一行元素的最小值。 } else { cout << "the result is a[" << i << "]" << "[" << col << "]" << endl; AD = 1; break; } } if (AD==0) { cout << "Non result" << endl; } }
标签:int input isp actor 计算 nbsp n+1 class continue
原文地址:http://www.cnblogs.com/variance/p/6994958.html