1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
int n, s=0, sip=0, sii=0,sipri=0, siirp=0,x,y;
/*1. Calculate the Sum of all the Results.
2. Calc sum of results for even and odd iterations.
3. Calc sum of even results, for odd iterations.
4. Calc sum of odd results, for even iterations.*/
cout<<" Enter n=";
cin>>n;
for(int i=0,a,b,c, R; i < n ; i++ )
{
a=rand()%10;
b=rand()%10;
c=rand()%10;
R=a+b-c;
s+=R;
if( i%2==0 ) sip+=R;
else sii+=R;
if( i%2==0 && R%2!=0 ) sipri+=R;
else if( i%2!=0 && R%2==0 ) siirp+=R;
cout<<" i="<<i<<" - a="<<a<<" b="<<b<<" c="<<c<<" a+b-c="<<a+b-c<<endl;
}
cout<<endl;
cout<<" s="<<s<<endl;
cout<<" sip="<<sip<<endl;
cout<<" sii="<<sii<<endl;
cout<<" sipri="<<sipri<<endl;
cout<<" siirp="<<siirp<<endl;
//Solve the equation a+b-c, for all pair of answers
for(int i=0,a,b,c, R; i < n ; i+=2 )
R=a+b-c;
cout<<"R= "<<endl;
/// From iteration 2 to iteration 5, solve a+b-c, where a,b,c are values included in x...y interval.
cout<<"Enter x, y, where y>x "<<endl;
cin>>x;
cin>>y;
cout<<"x= "<<x<<" y= "<<y<<endl;
for (int a,b,c,t, i= rand()%3+2; i<5; i++) {
t=y-x;
a= rand()%t+x;
b= rand()%t+x;
c= rand()%t+x;
a+b-c;
cout<<" i="<<i<<"a= "<<a<<" b= "<<b<<" c= "<<c<<" a+b-c= "<<a+b-c<<endl;
}
//For all the even results find out the maximum and minimum answer, if the iteration is smaller then the result ( i<R )
for ( int R, max=INT_MIN, i=0 ; i<R ; max<R ) {
if (max<R && R%2==0)
max=R;
cout<<" max = "<<max<<endl;
}
for (int R, min=INT_MAX, i=0 ; i<R ; min>R ){
if (min>R && R%2==0)
min=R;
cout<<" min = "<<min<<endl;
}
return 0;
|