-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path42.c
More file actions
41 lines (33 loc) · 703 Bytes
/
42.c
File metadata and controls
41 lines (33 loc) · 703 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
34
35
36
37
38
39
40
41
/*4.Write a program which accept range from user and return addition of all even
numbers in between that range. (Range should contains positive numbers only)
Input :23 30
Output : 108 */
#include <stdio.h>
int RangeSumEven(int iNo1,int iNo2)
{
int iCnt=0,iSum=0;
if((iNo1>iNo2)||(iNo1<0)||(iNo2<0))
{
printf("Invalid Range\n");
return 0;
}
for(iCnt=iNo1;iCnt<=iNo2;iCnt++)
{
if(iCnt%2==0)
{
iSum=iSum+iCnt;
}
}
return iSum;
}
int main()
{
int iValue1=0,iValue2=0,iRet=0;
printf("Enter First Number\n");
scanf("%d",&iValue1);
printf("Enter Second Number\n");
scanf("%d",&iValue2);
iRet=RangeSumEven(iValue1,iValue2);
printf("Summenation is :%d \n",iRet);
return 0;
}