// s = 1- 2x + 3xpow2 - 4xpow3 + .........
#include <stdio.h>
#include <math.h>
void main( )
{
float x,s,r ;
int a,b,n ;
int i ;
printf ("enter number of term after ") ;
scanf ("%d",&n) ;
printf ("enter value x = ") ;
scanf ("%f",&x) ;
s = 0 ;
for ( i=1 ; i<=n ; i++ )
{
a = 1 + i ;
b = i ;
r = a * pow(x,b) ;
if ( i % 2 == 0)
s = s + r ;
else
s = s - r ;
//first tirm -2x (s = 0 - 2x)
}
s = 1 + s ;
printf ("sum = %10.2f \n",s) ;
}
The most beautiful thing we can experience is the mysterious, it is the source of all true art and science.
Imagination is more important than knowledge.
Thursday, September 25, 2008
C Solve Problem
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment