-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path1071.c
More file actions
33 lines (29 loc) · 745 Bytes
/
1071.c
File metadata and controls
33 lines (29 loc) · 745 Bytes
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
//Questão 1071 - Soma de Ímpares Consecutivos I - URI Online Judge
#include <stdio.h>
int main(void){
int x, y, i, soma = 0;
scanf("%d %d", &x, &y);
if(y == x){
printf("0\n");
return 0;
}
if(y % 2 == 0 && x % 2 != 0){
for(i = y+1; i <= (x-2); i+=2)
soma += i;
}else{
if(y % 2 != 0 && x % 2 != 0){
for(i = y+2; i <= (x-2); i+=2)
soma += i;
}else{
if(y % 2 != 0 && x % 2 == 0){
for(i = y+2; i <= (x-1); i+=2)
soma += i;
}else{
for(i = y+1; i <= (x-1); i+=2)
soma += i;
}
}
}
printf("%d\n", soma);
return 0;
}