5.1
#include <iostream> #include<array> using namespace std; void main51() { int min,max; cout<<"Enter the min:"; cin>>min; cout<<endl<<"Enter the max:"; cin>>max; int sum=0; for(int i=min;i<=max;i++) sum+=i; cout<<"\nsum="<<sum<<endl; cin.get(); // int ArrSize=max-min+1; //array<int,ArrSize> arr; }
5.2
#include <iostream> #include <array> using namespace std; const int ArrSize=101; void main52() { array<long double,ArrSize> arr; arr[0]=arr[1]=1L; for(int i=2;i<ArrSize;i++) arr[i]=arr[i-1]*i; for(int i=0;i<ArrSize;i++) cout<<i<<"!="<<arr[i]<<endl; cin.get(); }
5.3
#include <iostream> void main53() { using namespace std; cout<<"Plese Enter the number ,if is 0,for end:"; double iput,sum=0; cin>>iput; while(iput) { sum+=iput; cout<<"\nnow sum is "<<sum<<" \nEnter a another number:"; cin>>iput; } cin.get(); }
5.4
#include <iostream> using namespace std; void main54() { double Dsum=10; double Csum=10; int i=0; while (Csum<=Dsum) { Dsum+=10; Csum+=Csum*0.05; i++; } cout<<"After "<<i<<" year, Csum is bigger than Dsum"<<endl; cout<<"Dsum="<<Dsum<<" Csum="<<Csum; cin.get(); }
5.5
#include <iostream> void main55() { using namespace std; char arr[15]={'1','2','3','4','5','6','7','8','9','10','11','12'}; char *c=arr; int num[15]; int sum=0; for(int i=0;i<12;i++,c++) { //void *c1=c; cout<<"The "<<*c<<" month number is "; cin>>num[i]; sum+=num[i]; cout<<"\n now sum is "<<sum<<endl; } cout<<"This year num is "<<sum<<endl; cin.get(); }
——————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:https://www.royalchen.com/
author:royalchen
Email:royalchen@royalchen.com
———————————————————————————————————————————————————