C语言——使用for循环找出100~200之间的完全平方数

方法一

cpp 复制代码
#include <stdio.h>
#include <math.h>

int main() {
    int i;
    for (i = 100; i <= 200; i++) 
    {
        int squareRoot = sqrt(i);
        if (squareRoot * squareRoot == i) 
        {
            printf("%d ", i);
        }
    }
    return 0;
}

方法二

cpp 复制代码
#include <stdio.h>

int main() {
    int i;
    for (i = 10; i <= 14; i++)   //因为14的平方是196,小于200
    {
        printf("%d ", i * i);
    }
    return 0;
}

方法三

cpp 复制代码
#include <stdio.h>

int main() {
    int i, square;

    for (i = 1; i <= 14; ++i)  //因为14的平方是196,小于200
    {
        square = i * i;
        
        if (square >= 100 && square <= 200) 
        {
            printf("%d\n", square);
        }
    }

    return 0;
}
相关推荐
8Qi83 小时前
回文子串(Palindromic Substrings)—— 题解
算法·leetcode·职场和发展·动态规划
xskukuku3 小时前
使用VSCode配置C语言运行环境
c语言·ide·vscode
想吃火锅10055 小时前
【leetcode】405.数字转换为十六进制数js
开发语言·javascript·ecmascript
专注VB编程开发20年6 小时前
AI 生成C# WinForm 窗体 = 目前就是垃圾
开发语言·人工智能·c#
cfm_29146 小时前
JVM GC垃圾回收初步了解
java·开发语言·jvm
~小先生~6 小时前
Python从入门到放弃(一)
开发语言·python
许彰午7 小时前
17_synchronized关键字深度解析
java·开发语言
z落落7 小时前
C# 泛型接口和泛型类+泛型约束
开发语言·c#
阿正的梦工坊7 小时前
【Rust】02-变量、不可变性与基础类型
开发语言·后端·rust