# UVA 10783 Odd Sum ## 題目連結 [UVA 10268](https://vjudge.net/problem/UVA-10783) ### 題目內容 Given a range [a, b], you are to find the summation of all the odd integers in this range. For example, the summation of all the odd integers in the range [3, 9] is 3 + 5 + 7 + 9 = 24. ### 輸入限制 There can be at multiple test cases. The first line of input gives you the number of test cases, T (1 ≤ T ≤ 100). Then T test cases follow. Each test case consists of 2 integers a and b (0 ≤ a ≤ b ≤ 100) in two separate lines. ### 輸出限制 For each test case you are to print one line of output – the serial number of the test case followed by the summation of the odd integers in the range [a, b]. ### 解題思路 1.是奇數就相加 ### 程式碼 ```cpp= #include<bits/stdc++.h> using namespace std; int main(){ int t,kase=1; cin>>t; while(t--){ int a,b,ans=0; cin>>a>>b; for(int i=a;i<=b;i++){ if(i%2==1){ ans+=i; } } cout<<"Case "<<kase++<<": "<<ans<<endl; } } ``` ## 測資 ### Sample input 2 1 5 3 5 ### Sample output Case 1: 9 Case 2: 8 ## 中文題目連結 [zerojudge c022](https://zerojudge.tw/ShowProblem?problemid=c022)