#include<stdio.h>
int main()
{
int sum = 0, n;
{
int sum = 0, n;
printf("Enter the number : ");
scanf("%d", &n);
scanf("%d", &n);
// Using Math formula
// (n/2)((n / 2) + 1)
sum = ((n / 2) * ((n / 2) + 1));
// (n/2)((n / 2) + 1)
sum = ((n / 2) * ((n / 2) + 1));
printf("Sum of even numbers between 1 to %d : %d", n, sum);
return 0;
}
}
Output :
Enter the number : 100 Sum of even numbers between 1 to 100 : 2550
0 Comments