小白求问数列求和
#include"stdio.h"#include"math.h"
main()
{
int s,i;
s=0;
i=1;
while(i<=1000)
{
s=pow(-1,i+1)/(2i-1);
i++;
}
printf("%d",s);
}
[Error] cannot convert '__complex__ double' to 'int' in assignment
#include <stdio.h> int main( void ) { // 计算 1/1 - 1/3 + 1/5 - 1/7 + …… - 1/1999 = 0.785148 double s = 0; for( int i=0; i!=1000; ++i ) s += (i%2==0 ? +1 : -1) / (2*i+1.0); printf( "%f\n", s ); }