š Problem Solving from Codeforces using C language
This is a problem-solving post from Codeforces. Below is the problem with a short explanation and its solution.
This example is solved using C language.
š§© Main Problem: Given two numbersĀ XĀ andĀ Y. Print theĀ sumĀ of allĀ oddĀ numbers between them, excludingĀ XĀ andĀ Y.
š Problem Link: Codeforces Problem
š” Solution:
#include <stdio.h>
int main()
{
int t, x, y;
scanf("%d", &t);
while (scanf("%d %d", &x, &y) != EOF) //EOF means End Of File,, that means the datas will scan under scanf is till the ending of input file.
{ // if we dont use EOF it may hamper on our code.
if (x > y)
{ // here, we sorting/rearranging the numbers if there is ani number greater than nextone
int temp = x; // vale of x is in temp
x = y; // vale of y is in x (that means, y is now x)
y = temp; // stored value of x in temp now is assigned in y (x is now y)
}
int sum = 0;
for (int a = x + 1; a < y; a++) // we are excluding x and y
{
if (a % 2 != 0)
sum = sum + a; // calculation the summation value
}
printf("%d ", sum);
printf("\n");
}
return 0;
}
ā This solution takes input from user about how many test case are there then it takes those test cases. then it sort numbers od testcases from minimum to maximum then find the odd numbers between the test values and then summation them.
š Input:
3
5 6
10 4
4 9
š Output:
0
21
12
š Find Similar Problems from Codeforcesā Click Here
š¤ More Problem Solving ā Click Here
š Learn C Programming ā Click Here