#include <iostream> using namespace std; double powf(double x,int n) { double temp=1; for(int i=1;i<=n;i++) temp*=x; return temp; } int main() { double a,b=1,sum=0; for(a=1;a<=10;a++) { sum=sum+powf(b,a); b=1/(a+1); } cout<<"1+1/2^2+1/3^3...1/10^10 = "<<sum; system("pause"); return 0; }
#include <iostream> using namespace std; int factorial(int n) { if(n == 1) return n; else return n*factorial(n-1); } int main() { int k,total=0; for(k=1;k<=10;k++) total+=factorial(k); cout<<"1!+2!....+10! = "<<total; system("pause"); return 0; }
#include <iostream> using namespace std; int factorial(int n) { if(n == 1) return n; else return n*factorial(n-1); } int main() { int k,total=0; cout<<"请输入一个整数以计算阶层 :"; cin>>k; for(int i=1;i<=k;i++) total+=factorial(i); cout<<"1!+2!....+n! = "<<total; system("pause"); return 0; }
#include <iostream> using namespace std; int swap(int &num1,int &num2) { int temp=num1; num1=num2; num2=temp; return 0; } int main() { int a[10]={45,23,18,10,6,8,67,98,30,50}; int temp; for(int k=0;k<10;k++) for(int i=0;i<k;i++) if(a[i]>a[i+1]) swap(a[i],a[i+1]); cout<<"最大值 :"<<a[9]<<endl; cout<<"最小值 :"<<a[0]<<endl; system("pause"); return 0; }