Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Mathematics ProgramRSS Feeds

PROGRAM TO PRINT THE SUM OF SERIES 1 + 1/4 + 1/9 + 1/16 + ... + 1/N.

Posted By: Luiz Silva     Category: C Programming     Views: 6510

WRITE A PROGRAM TO PRINT THE SUM OF SERIES
1 + 1/4 + 1/9 + 1/16 + ... + 1/N.
INPUT STEPS FROM KEYBOARD.

Code for PROGRAM TO PRINT THE SUM OF SERIES 1 + 1/4 + 1/9 + 1/16 + ... + 1/N. in C Programming


#include<stdio.h>
    #include<conio.h>
    void main()
    {
        double sum=0;
        longint sqr=0,i,n;
        clrscr();

        printf("\n Please Give The Value of N:  ");
        scanf("%ld",&n);
        for(i=1;i<=n;i++)
        {
            sqr=i*i;
            sum=sum+(1/(double)sqr);
            if(i==1)
                printf("\n 1 +");
            elseif(i==n)
                printf(" (1/%ld)  ",sqr);
            else
                printf(" (1/%ld) + ",sqr);
        }
        printf("\n\n THE SUM OF THIS SERIES IS %7.2lf",sum);
        getch();
    }




********************** OUTPUT *********************************

     Please Give The Value of N:  5


     1 + (1/4) +  (1/9) +  (1/16) +  (1/25)



     THE SUM OF THIS SERIES IS    1.46


*****************************************************************
  
Share: 



Luiz   Silva
Luiz Silva author of PROGRAM TO PRINT THE SUM OF SERIES 1 + 1/4 + 1/9 + 1/16 + ... + 1/N. is from Salvador, Brazil.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!