zoukankan      html  css  js  c++  java
  • 2-1aabb

    输出所有形如aabb的完全平方数。

    #include<stdio.h>
    #include<math.h>
    int main()
    {
        int a,b,n;
        for(a=1;a<=9;a++)
            for(b=0;b<=9;b++)
            {
                n=1100*a+11*b;
            if(sqrt(n)==floor(sqrt(n)))
    //if(sqrt(n)==floor(sqrt(n)))判断sqrt(n)是不是整数
    //理论上没问题,但不保险;浮点数运算有误差
    printf(
    "%d ",n); } printf(" "); return 0; }
     1 #include<stdio.h>
     2 #include<math.h>
     3 int main()
     4 {
     5     int a,b;
     6     for(a=1;a<=9;a++)
     7         for(b=0;b<=9;b++)
     8         {
     9             int n=1100*a+11*b;
    10             int m=floor(sqrt(n)+0.5);
    /*floor(x+0.5)四舍五入
    floor(x) 其功能是“向下取整”,或者说“向下舍入”,即取不大于x的最大整数(与“四舍五入”不同,下取整是直接去掉小数部分)
    floor(n)对n向负方向舍入
    ​floor(3.14) = 3.0
    floor(9.999999) = 9.0
    floor(-3.14) = -4.0
    floor(-9.999999) = -10
    floor(3.5)=3;
    floor(-3.2)=-4
    */
    11 if(m*m==n) 12 printf("%d ",n); 13 } 14 printf(" "); 15 return 0; 16 }

    1
    #include<stdio.h> 2 int main() 3 { 4 int n; 5 for(int i=1;;i++) 6 { 7 n=i*i; 8 if(n<1100) 9 continue; 10 if(n>9999) 11 break; 12 int a=n/100; 13 int b=n%100; 14 if(a/10==a%10&&b/10==b%10) 15 printf("%d ",n); 16 } 17 printf(" "); 18 return 0; 19 }
    好奇一切知识的咸鱼<@_@>
  • 相关阅读:
    python网络编程,requests模块
    python操作excel
    python加密模块hashlib
    python操作redis
    python操作mysql
    python常用模块3(os和sys模块)
    python打开网站
    python常用模块2
    python模块简介
    mac下开发——环境心得(杂项,持续性更新)
  • 原文地址:https://www.cnblogs.com/xybz/p/9978884.html
Copyright © 2011-2022 走看看