-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsecutiveOddSummation.c
54 lines (45 loc) · 1.08 KB
/
consecutiveOddSummation.c
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @file consecutiveOddSummation.c
* 34. Write a C program to compute the sum of consecutive odd numbers from a given pair of integers. Go to the editor
Test Data :
Input a pair of numbers (for example 10,2):
Input first number of the pair: 10
Input second number of the pair: 2
Expected Output:
List of odd numbers: 3
5
7
9
Sum=24
* @author Md. Alamin ([email protected])
* I would love be a software engineer at Google. That is why anybody can uses this code without any condition, if you face any difficulty, then try to email me.
* @version 0.1
* @date 2022-03-28
*
* @copyright Copyright (c) 2022
*
*/
#include <stdio.h>
int main()
{
int first, last, temp, sum =0;
printf("Enter 1st and last number of pair: \n");
scanf("%d%d", &first, &last);
if (last < first )
{
temp = first;
first = last;
last = temp;
}
if (first%2==0)
{
first++;
}
for (int i = first; i <= last; i+=2)
{
sum = sum + i;
printf("%d\n", i);
}
printf("Sum of Odd: %d\n", sum);
return 0;
}