Sum of even number between the two range number are given below….
Let’s understand some concept.
Even Number..
Number which divided by 2 with 0 remainder is known as Even number.
Sum of even Number. if you enter number then the sum done by this formula…If a=last term 100. Then n=a/2. So, x=n*(n+1).
Some important symbols used in code.
- () small bracket
- && use for ‘and’ use for address
- {} curly bracket
- “” double code
Sum of even number by using formula…
If you Enter an Even number or odd number. This code for both case..
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a,b,c,d,e;
- clrscr();
- printf(“Enter the to find sum of even number upto range”);
- scanf(“%d”, &a);
- if(a%2==0)
- {
- b=a/2;
- c=b*(b+1);
- printf(“%d”,c);
- }
- else if(a%2!=0)
- {
- b=(a-1)/2;
- c=b*(b+1);
- printf(“%d”, c);
- }
- getch();
- }
Inputs..
If a=100 then
Results..
Sum= 2550
Sum of even number by using ‘for’ loop…
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a,b,c=0,d,e;
- clrscr();
- printf(“Enter the to find sum of even number upto range”);
- scanf(“%d”, &a);
- for(b=2;b<=a;b++)
- if(b%2==0)
- {
- c+=b;
- }
- printf(“%d”, c);
- getch();
- }
Inputs..
If a = 100 then
Results..
Sum= 2550.

Sum of even number by using ‘while’ loop…
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a,b=2,c=0;
- clrscr();
- printf(“Enter the to find sum of even number upto range”);
- scanf(“%d”, &a);
- while(b<=a)
- {
- if(b%2==0)
- c+=b;
- b++;
- }
- printf(“%d”, c);
- getch();
- }
Inputs..
If a=100 then
Results..
Sum= 2550
Sum of even number by using ‘do while’ loop…
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a,b=2,c=0;
- clrscr();
- printf(“Enter the to find sum of even number upto range”);
- scanf(“%d”, &a);
- do
- {
- if(b%2==0)
- c+=b;
- b++;
- }
- while(b<=a);
- printf(“%d”, c);
- getch();
- }
Inputs..
If a=100 then
Results..
Sum= 2550..

Sum of even number between the two range number by using ‘for’ loop…
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a,b,c=0,d,e;
- clrscr();
- printf(“Enter the to find sum of even number between two range number”);
- scanf(“%d%d”, &a, &b);
- for(c=a;c<=b;c++)
- if(c%2==0)
- {
- d+=c;
- }
- printf(“%d”, d);
- getch();
- }
Inputs..
If a=1 and b=100 then
Results..
Sum= 2550..
Sum of even number between the two range number by using ‘while’ loop…
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a,b,c=0,d,e;
- clrscr();
- printf(“Enter the to find sum of even number between two range number”);
- scanf(“%d%d”, &a, &b);
- c=a;
- while(c<=b)
- if(c%2==0)
- {
- d+=c;
- c++;
- }
- printf(“%d”, d);
- getch();
- }
Inputs..
If a=1 and b=100 then
Results..
Sum= 2550..
Sum of even number between the two range number by using ‘do while’ loop…
- #include<stdio.h>
- #include<conio.h>
- void main()
- {
- int a,b,c=0,d,e;
- clrscr();
- printf(“Enter the to find sum of even number between two range number”);
- scanf(“%d%d”, &a, &b);
- c=a;
- do
- {
- if(c%2==0)
- {
- d+=c;
- c++;
- }
- }
- while(c<=b);
- printf(“%d”, d);
- getch();
- }
Inputs..
If a=1 and b=100 then
Results..


