302班

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

          求你一個數的平方根

          Posted on 2007-06-30 21:27 停留的風 閱讀(477) 評論(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;
          }
          主站蜘蛛池模板: 朝阳区| 平度市| 来宾市| 政和县| 宁安市| 福建省| 凤庆县| 日喀则市| 阿图什市| 石渠县| 乌兰县| 贵阳市| 醴陵市| 台州市| 辉南县| 吉木乃县| 天气| 南川市| 建湖县| 长子县| 墨竹工卡县| 东莞市| 乐亭县| 唐河县| 邢台县| 繁昌县| 平江县| 马关县| 乐亭县| 龙海市| 松滋市| 宜宾市| 温宿县| 尚义县| 天气| 巴林左旗| 襄垣县| 镇雄县| 南丹县| 阜新市| 化隆|