Skip to content

Commit

Permalink
1158 C
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasPLopes committed Dec 19, 2019
1 parent 9e9d103 commit 3a00f54
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions C/1158.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <stdio.h>

int toOdd(int N)
{
if (N % 2 == 0)
return N + 1;
return N;
}
int sum(int N, int steps)
{
int sum = 0;
for (size_t i = 0; i < steps; i++)
{
sum += N;
N += 2;
}
return sum;
}

void print(int N)
{
printf("%d\n", N);
}

void toAll(int N, int steps)
{
print(sum(toOdd(N), steps));
}

int main(int argc, char const *argv[])
{
int times, N, steps;
scanf("%d", &times);
for (size_t i = 0; i < times; i++)
{
scanf("%d %d", &N, &steps);
toAll(N, steps);
}

return 0;
}

0 comments on commit 3a00f54

Please sign in to comment.