zoukankan      html  css  js  c++  java
  • 计蒜客 X的平方根

    X的平方根

    设计函数int sqrt(int x),计算x的平方根。

    格式:

       输入一个数x,输出它的平方根。直到碰到结束符号为止。

       千万注意:是int类型哦~

       输入可以如下操作:

    while(cin>>x)

    或者

    while(scanf("%d", &x) != EOF)

    样例输入

    1
    2
    3
    4
    5
    6
    7
    8
    9

    样例输出

    1
    1
    1
    2
    2
    2
    2
    2
    3

     1 #include "iostream"
     2 #include "math.h"
     3 using namespace std;
     4 
     5 int main()
     6 {
     7     int x;
     8     while (cin >> x)
     9     {
    10         if (x == 1)
    11             cout << 1 << endl;
    12         //for (int i = x; i <= 1; i++)
    13         //{
    14         //    if ((x >= (i*i)) && (x < (i + 1)*(i + 1)))
    15         //        cout << i << endl;
    16         //}
    17 
    18         else cout << (int)sqrt(x)<<endl;
    19     }
    20 }    
  • 相关阅读:
    *Triangle
    Pascal's Triangle II
    Pascal's Triangle
    Merge Sorted Array
    House Robber
    Find Peak Element
    Container With Most Water
    *Next Permutation
    top命令VIRT,RES,SHR,DATA
    Octave简单使用
  • 原文地址:https://www.cnblogs.com/SeekHit/p/5552614.html
Copyright © 2011-2022 走看看