Pages

Monday, January 2, 2012

C Programming to find sum of square of first n natural numbers


/*to find sum of square of first n odd natural numbers*/
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main( )
{
    int i,j=1,n,sum=0;
    printf ("enter n: ");
    scanf ("%d",&n);
    for (i=1; i<=n; i++)
    {
        sum+=pow(j,2);
        j+=2;
    }
    printf ("sum=%d",sum);
    system ("pause");
    return 0;
}

No comments:

Post a Comment