當前位置:編程學習大全網 - 源碼下載 - 批量源修改

批量源修改

根據題目要求,兩個過程如下(改動見註釋)

第壹個程序

# include & ltstdio.h & gt

void main()

{

浮點n,f;

float x1=1,x2,temp//這裏x1初始化為1,因為需要先給x1賦值。

printf("輸入壹個正數:");

scanf("%f ",& ampn);

while(1)

{

x2 =(x 1+n/x 1)/2;//這句話移到這裏,因為妳要先給x2賦值。

temp = x 1-x2;

if(temp & lt;0)

temp =-temp;

if(temp & lt;1e-5)

打破;

x 1 = x2;

}

printf(" 5.2f的平方根是%8.5f\n ",n,x2);

}

第二個節目

# include & ltstdio.h & gt

void main()

{

浮點n,f;

float sqroot(float n);

printf("輸入壹個正數:");

scanf("%f ",& ampn);

f = sqroot(n);//這裏接收函數返回值,因為函數有返回值。

printf(" 5.2f的平方根是%8.5f\n ",n,f);//這裏把x2改成F,因為x2是未定義的。

}

浮點數sqroot(浮點數n)

{

float x1=1,x2,temp//這裏x1初始化為1,因為x1需要先賦值。

for(;;)//刪除temp & gt1e-5,因為for循環中有判斷。

{

x2 =(x 1+n/x 1)/2;//這句話移到這裏,因為x2必須先賦值。

temp = x 1-x2;

if(temp & lt;0)

temp =-temp;

if(temp & lt;1e-5)

打破;

x 1 = x2;

}

返回x2;

}

  • 上一篇:如何讓壹個View從屏幕左邊慢慢移入
  • 下一篇:unity3D培訓學費貴不貴大概需要多少錢
  • copyright 2024編程學習大全網