#include<stdio.h>
int main()
{
int n=1,num;
float x=0,m;
printf("Enter no. of digits:\n");
scanf("%d",&num);
for(n=1;n<=num;n++)
{
m=(float)(2*n-1)/2*n;
if(n%2==0)
{
m=m*(-1);
}
x+=m;
}
printf("Summation is:\n%.4f\n\n",x);
}
I wanted to print the series 1/2 -3/4 5/6 -7/8......num where num is accepted by user. Its going pretty well when num is 1. But doesn't work correctly for any other value of num. Please help!