728x90

20240504 백준 파이썬 공부
9713번 Sum of Odd Sequence

1. 문제
Given an odd integer N, 
calculate the sum of all the odd integers between 1 and N inclusive.

2. 입력
First line of the input contains T, the number of test cases. 
Each test case contains a single integer N. N is between 1 and 100.

3. 출력
For each test case output the value 1+3+….+N.

>>>코드

for _ in range(int(input())):
    result = 0
    n = int(input())
    for i in range(1, n+1):
        if i%2 == 1:
            result += i
    print(result)



>>>문제링크
https://www.acmicpc.net/problem/9713

728x90

+ Recent posts