Here is the problem:
Write a program to solve to following expression:
S=(1!/2)+(2!/4)+(3!/6)+....+(N!/2N)
- N read from keyboard.
This is my solution:
Code:
#include <stdio.h>
#include <conio.h>
long inputNumber, x;
double fact=1, sum=0;
void main()
{
clrscr();
printf("Enter number: ");
scanf("%ld", &inputNumber);
if(inputNumber==0)
printf("\nPlease enter number from 1 up.");
else
{
for(x=1; x<=inputNumber; ++x)
{
fact=(fact*x)/(2*inputNumber);
sum+=fact;
}
printf("\nThe sum is %lf", sum);
}
getch();
}
Any suggestion to make this program better.