这是一道c语言的英文题,求大神解答 题目是1.write a c program for the

Python041

这是一道c语言的英文题,求大神解答 题目是1.write a c program for the,第1张

把盒图转变为算法

#include "stdio.h"

#include "math.h"

int main()

{

double pi=0.0,i=0.0

int show=0,digit

float accuracy,dif

do{

printf("how many digit do you want to calculate(4 to 7)?")

scanf("%d",&digit)

}while(digit>=4||digit<=7)

accuracy =11*pow(10.0,digit)

do{

i++

show++

pi=pi+(1/(i*i))

if(show==1000){

printf("pi is about",sqrt(pi/6))

}

}while(show<1000)\\下面的条件看不到...大概是这个吧。

}

这是我所能看到的盒图写的程序

show是什么数据类型?看程序的话我暂且设定问int型。

第二个循环我有点不解,完全不需要把程序都放到循环里。既然是题,那就按题走吧

首先说一下你这个程序,其中程序段

for(i = 0i <20i++)

{

fir[i] = tmp

tmp = getchar()

if(tmp == ' ')

for(i = i+1i <20i++)

fir[i] = ' '

}

结束后,i的值是21.因为你内层循环结束后i已经是20,再到外层循环时要先执行i++,之后再判断i<20.

还有就是以下程序段中

for(i = 0i <20i++)

{

last[i] = tmp

tmp = getchar()

if(tmp == ' ')

for(i = i+1i <20i++)

last[i] = ' '

}

你整个输入的字符创不是以空格结束的,而是以回车换行结束的,所以其中不应该是tmp == ‘ ’,而是tep == ‘\n'.

再有就是你写的这个程序好啰嗦。