302班

          java突擊隊
          posts - 151, comments - 74, trackbacks - 0, articles - 14
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          求你一個數的平方根

          Posted on 2007-06-30 21:27 停留的風 閱讀(480) 評論(0)  編輯  收藏 所屬分類: C語言學習歷程
          #include <stdio.h>
           float absoluteValue(float x)
           {
             if(x<0)
             {
              x=-x;
             }
             return x;
           }
           float squareRoot(float x)
           {
             const float epsilon= 0.0001;
             float guess=1.0;
             if(x<0)
             {
              printf("Negative argument to squareRoot.\n");
              return -1.0;
             } 
             while (absoluteValue((guess*guess)-x)>=epsilon)
             {
              guess=(x/guess+guess)/2.0;
             }
             return guess;
           
           }
          int main(void)
          {
            float  number; 
            printf("Enter an float number!\n");
            scanf("%f",&number);
           
            printf("The squareRoot of number %f is %f.\n",number,squareRoot(number));
            return 0;
          }
          主站蜘蛛池模板: 澄迈县| 黄平县| 贡嘎县| 耒阳市| 朝阳市| 尼玛县| 依安县| 即墨市| 南澳县| 新巴尔虎右旗| 安顺市| 吴忠市| 泾阳县| 中卫市| 六枝特区| 陆丰市| 平江县| 长寿区| 保康县| 泰宁县| 万荣县| 汶川县| 颍上县| 旬邑县| 遂平县| 积石山| 黄石市| 张家口市| 桂阳县| 安康市| 永济市| 日照市| 大洼县| 隆安县| 梁河县| 瑞丽市| 拉萨市| 昌宁县| 琼中| 寿光市| 湖北省|