/*Write a c program to find the sum of the Series s=2+4+6+.....+n by indirect method using for loop */ #include <stdio.h> #include <stdlib.h> int main() { int n,i,sum=0; printf("Enter the even value for n :\n"); scanf("%d",&n); if(n%2==0) { for(i=2;i<=n;i+=2) sum=sum+i; printf("Sum of the series is = %d\n",sum); } else printf("Invalid input!\n"); return 0; }
Enter the even value for n : 6 Sum of the series is = 12
No comments:
Post a Comment