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;
}
相关推荐
点心的游戏开发世界9 小时前
GDScript 入门笔记(十一):Lambda 与匿名函数
开发语言·笔记·游戏引擎·godot
phltxy9 小时前
C语言操作符详解
java·c语言·算法
RuoZoe10 小时前
从 2026 年 3 月 1 日开源,到 26.10.9:Jalium UI 半年时间到底走了多远?
c语言·c++
aqiu11111110 小时前
【LeetCode 902】最大为 N 的数字组合 - 详细题解与数位组合思路
数据结构·算法·leetcode·蓝桥杯·数位dp
辰烨chenye10 小时前
LeetCode Hot 100 题解 · 哈希篇
算法·leetcode·哈希算法
事圆则缓11 小时前
Kotlin 协程完全指南
开发语言·kotlin
罗西的思考11 小时前
DreamZero 与 DreamDojo:世界模型与策略的分层协同综合分析与对比
人工智能·算法·机器学习
我爱写代码i11 小时前
BeLink - 支持生成多种URL 缩短网址PHP源码
开发语言·php·短网址php源码
Java后端的Ai之路11 小时前
20、Python - 备忘录模式
开发语言·人工智能·python·外观模式·备忘录模式