Header Ads

C program for sum of all even number below given range

__________________________________________________________________________________________________________________________________________________________________

Program:

#include<stdio.h>
#include<conio.h>
main()
{
    int i,s=0,n;
    printf("Enter the range: ");
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        if(i%2==0)
            s=s+i;
    }
    printf("Sum of all even numbers below %d is \'%d\'",n,s);
    getch();
}


Output:

Output screenshot for sum of all even number below given range
__________________________________________________________________________________________________________________________________________________________________

No comments