#include<stdio.h>
int main()
{
int i,n,sum=0;
printf("Enter the n value : ");
scanf("%d",&n);
printf("\nThe even numbers are :");
for(i=1;i<=n;i++)
{
if(i%2==0)
{
printf("%d ",i);
sum+=i;
}
}
printf("\nThe Sum of Even Natural Number upto %d terms : %d \n",n,sum);
return 0;
}
OUTPUT:
Enter the n value : 5
The even numbers are :2 4
The Sum of Even Natural Number upto 5 terms : 6
Enter the n value : 10
The even numbers are :2 4 6 8 10
The Sum of Even Natural Number upto 10 terms : 30
No comments:
Post a Comment