?? 平方根.c
字號:
#define Epsilon 1.0E-6 /*控制解的精度*/
#include <stdio.h>
#include <math.h>
main()
{
float num,pre,this;
do
{
scanf("%f",&num);/*輸入要求平方根的數(shù)*/
}while(num<0);
if (num==0)
printf("the root is 0");
else
{
this=1;
do
{
pre=this;
this=(pre+num/pre)/2;
}while(fabs(pre-this)>Epsilon);/*用解的精度,控制循環(huán)次數(shù),fabs()是求絕對值的函數(shù)*/
}
printf("the root is %f",this);
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -