标签:
#include<iostream> #include<ctime> using namespace std; int main() { srand((unsigned)time(NULL)); int * arr1=new int[5]; int * arr2=new int[5]; int sum=0,k=0,result=0; int randoms=0,count1=0,count2=0,c1=0,c2=0; cout<<"随机产生10个数值:\n"<<endl; for ( int i1=0; i1<5; i1++ ) { randoms = ( -rand()%100 + ( rand()%100 ) ); arr1[i1] = randoms; } for ( int i2=0; i2<5; i2++ ) { randoms = ( rand()%100 ) ; arr2[i2] = randoms; } for ( int i3=0; i3<5; i3++ ) { if((arr2[i3]/10<0)){ cout<<"数组元素"<<i3+1<<"分别为:"<<arr1[i3]<<"0"<<arr2[i3]<<endl; } else cout<<"数组元素"<<i3+1<<"分别为:"<<arr1[i3]<<arr2[i3]<<endl; } result=arr1[0]; for ( int j=0; j<5; j++ ) { if ( sum>=0 ){ c2=j; sum+=arr1[j]; } else { c1=j; sum=arr1[j]; } if( result< sum ) { count1=c1; count2=c2; result=sum; } } result=result*100; for(int i=c1;i<=c2;i++) { result+=arr2[i]; } cout<<endl<<"从第"<<count1+1<<"个元素到第"; cout<<count2+1<<"个元素为最大数组"<<endl<<endl; cout<<"最大数组之和:"<<result<<endl<<endl; return 0; }
运行截图;
结对编程总结:
程序基本实现,有瑕疵,不过为了赶时间,以后补充更好的吧。通过这次编程实践,我觉得交流可以
扩充思路,互相指点,很有帮助。^_^
标签:
原文地址:http://www.cnblogs.com/huazongzong/p/4378886.html