← Back to Codes
C
Equation Series Sum
Calculates the sum of the series: 1 - X^2/2! + X^4/4! ...
equation_series.c
#include <stdio.h>
#include <math.h>
int main()
{
printf("INSTRUCTIONS: Enter the value of X to calculate the series sum.\n");
int counter,f_coun;
float sum=0,x,power,fact;
printf("\tEQUATION SERIES : 1- X^2/2! + X^4/4! - X^6/6! + X^8/8! - X^10/10!");
printf("\n\tENTER VALUE OF X : ");
scanf("%f",&x);
for(counter=0, power=0; power<=10; counter++,power=power+2)
{
fact=1;
for(f_coun=power; f_coun>=1; f_coun--)
fact *= f_coun;
sum=sum+(pow(-1,counter)*(pow(x,power)/fact));
}
printf("SUM : %f",sum);
}Equation Series Sum — Free C, Java Code Example
Calculates the sum of the series: 1 - X^2/2! + X^4/4! ... This free code example is available in C, Java and can be copied and run immediately — no account or signup required. Use the language tabs above to switch between implementations.
How to Use This Code
- Select your language — click the language tab (C, Java, C++, or Python) above the code viewer.
- Copy the code — use the copy button in the top-right corner of the code block.
- Run it — paste into a file with the correct extension (.c, .java, .cpp, .py), compile, and run using your terminal or IDE.
- Follow the on-screen instructions in the terminal to provide any required inputs.
Frequently Asked Questions
What does this program do?
Calculates the sum of the series: 1 - X^2/2! + X^4/4! ...
Which languages is it available in?
Available in C, Java. Switch between implementations using the tabs at the top of the code viewer.
How do I run this code?
Copy the code, save it with the right file extension (.c, .java, .cpp, or .py), then compile or run it with your installed compiler or interpreter (GCC, JDK, G++, Python 3).
Is this code free?
Yes — free to view, copy, and use. No account required.