[C_MM27-易] 計算兩整數間所有整數的總和
- #include <iostream>
- using namespace std;
- int main() {
- int start, end;
- int sum = 0;
- while(cin >> start >> end)
- {
- if(start > end)
- {
- for(int i = end; i <= start;i++)
- {
- sum = sum + i;
- }
- cout << sum << endl;
- }
- else if(start < end)
- {
- for(int i = start; i <= end;i++)
- {
- sum = sum + i;
- }
- cout << sum << endl;
- }
- sum = 0;
- }
- return 0;
- }
沒有留言:
張貼留言