Sunday, October 30, 2011

Sum Of Series

// A Program to find Sum of Series:2^2+(2^2+4^2)+(2^2+4^2+6^2)+(2^2+4^2+6^2+......n^2)

#include<stdio.h>
#include<conio.h>
void main()
{
    int i,j,k,n,d,sum=0;
    clrscr();
    printf("\nEnter Nth Even Term:");
    scanf("%d",&n);
    i=0;
    while(1)
    {
        k=2;
        for(j=0;j<=i;j++)
        {
            d=k*k;
            sum=sum+d;
            if(k==n)
            {
                printf("\nSum Of Terms:%d",sum);
                getch();
                exit(0);
            }
            k=k+2;
        }
        i++;
    }
}

No comments:

Post a Comment