Skip to main content

C-Programming Program 3(c)

3 (c) Write a C program to calculate the following  

   Sum=1-x2/2! +x4/4!-x6/6!+x8/8!-x10/10! 

Algorithm


Step-1 : Start

Step-2 : Declare variables x,i,j,f,sum
Step-3 : Initialise sum=1,f=1
Step-4 : Read value of x
Step-5 : Initialize i=2
 5.1 : if(i<=10)
 5.1.1 : initialize f=1
 5.1.2 : initialize j=1
 5.1.2.1 : if(j<=i)
 5.1.2.1.1 : f=f*j
 5.1.2.1.2 : Increment value of j
 5.1.2.1.3 : Go to Step-5.1.2.1
 5.1.2.1.4 : if(i%4= =0)
 5.1.2.1.4.1: sum=sum+pow(x,i)/f
 5.1.2.1.5 : if(i%4!=0)
 5.1.2.1.5.1: sum=sum-pow(x,i)/f
 5.1.3 : increment value of i
 5.1.4 : Go to Step-5.1
Step-6 : Stop

Flowchart 








Program 

#include <stdio.h>
#include <math.h>
void main()
{
    int counter,factorial_counter;
    float sum=0,x,power=0,fact;
    printf(" PROGRAM To Find The SUM OF EQ. SERIES \n");
    printf("\nEQUATION SERIES : 1- X^2/2! + X^4/4! - X^6/6! + X^8/8! - X^10/10!  ..........");
    printf("\nENTER VALUE OF X : ");
    scanf("%f",&x);
    for(counter=0; power<=10; counter++)
    {
        fact=1;
        for(factorial_counter=power; factorial_counter>=1; factorial_counter--)
        fact *= factorial_counter;
        sum=sum+(pow(-1,counter)*(pow(x,power)/fact));
power=power+2
    }
    printf("SUM : %f \n",sum);
}




Comments

Popular posts from this blog

C-Programming with Record

C-Programming Programs Syllabus Click for full record  1.a) Write a C program to ask the user to enter one char ( Upper-Case letter) check  whether user  entered a Upper-case letter or not(by using relational and logical operators) and then if user has  entered a Upper-case letter  convert into a Lower-case letter? ( hint: Upper-case means capital letters,  use ASCII information to check for Upper-case and convert) b) Write a  C program to ask the user to enter two integers and apply all arithmetic operations on those  print the corresponding values?(hint : +,-,*,/,%)     c) Write a C program to Determine the ranges of char, short, int and long int variables both signed and  Unsigned   By using sizeof operator(ii) By printing appropriate values from standard header (limits.h )   2.a) Write a Program to Find the Roots of a Quadratic Equation using if else and Switch statements. b) Write a Program which Gener...

OOPS CPP Program-14

14. Write a program to find transpose of a given matrix of mxn size using unary operator overloading #include<iostream> using namespace std; class matrix {         int x[5][5],m,n; public:         matrix(){ }         matrix(int a,int b)         {                m=a;n=b;         }         void get();         void put();         matrix operator !(); }; void matrix::get() {         int i,j;         cout<<"\n Enter a matrix of order"<<m<<"x"<<n<<"\n";                for(i=0;i<m;i++)                    for(j=0;j<n;j++)                        ...

OOPS CPP Program-15

15. Write a program to concatenate one string to another using binary operator overloading. #include<iostream> #include<string.h> using namespace std; class str  {         char *st; public:         str(int len, char *s)         {                  int l=strlen(s);                st= new char[l];                st=s;          }         str()         {         }         void put();         str operator +(str); }; str str :: operator +(str s)  {  /*str abc; abc.st=strcat(st, s.st); return abc;*/         st=strcat(st, s.st);         return *this; } void str :: put() {   cout<<...