1234567891011121314151617181920212223242526272829303132
#include <iostream> #include <algorithm> using namespace std; int main() { int t; cin>>t; while(t--) { int a,b,sum=0; cin>>a>>b; int ma=max(a,b); int mi=min(a,b); for(int i=mi; i<ma; i++) { if(mi%2!=0) sum+=mi; } cout<<sum<<endl; } return 0; }
123456789101112
// sum is set to 0 every iteration of the loop while(t--) { int a,b,sum=0; ...} ... // What determines the value of mi? for(int i=mi; i<ma; i++) { if(mi%2!=0) sum+=mi; }
#include <iostream> #include <algorithm> using namespace std; int main() { int t; cout << "How many tests? "; cin>>t; while(t--) { int a,b,sum=0; cout << "Enter start: " << endl; cin >> a; cout << "Enter end: " << endl; cin >> b; int ma=max(a,b); int mi=min(a,b); for(int i=mi; i<ma; i+=2) { sum+=mi; } cout<<sum<<endl; } return 0; }