c++第七次作业

来源:互联网 发布:数据库没有了 编辑:程序博客网 时间:2024/06/06 04:17
1、
#include<iostream>using namespace std;long fac(int n){long f = 1;for (int i = 1; i <= n; i++)f *= i;return f;}int judge(int a){if (a % 2 == 0)return 0;elsereturn 1;}int main(){long i = 0;long j = 0;int a[10] = { 1,2,3,4,5,6,7,8,9,10 };for (int b = 0; b < 10; b++){if (judge(a[b]) == 0)i += fac(a[b]);elsej += fac(a[b]);}cout << "奇数的阶乘和为:" << j << endl;cout << "偶数的阶乘和为:" << i << endl;return 0;}

0 0
原创粉丝点击