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;
}
相关推荐
Ada's2 小时前
【计算机基础系列】003:Python数据结构
开发语言·数据结构·python
2601_962885723 小时前
如何用 Python 计算 TRIX 三重指数平滑均线指标?
开发语言·python
还卿一钵无情泪3 小时前
Unsloth 微调 构建自己的大模型 没有GPU也能微调
linux·开发语言·人工智能·python·大模型·nlp·unsloth
Nil2084 小时前
leetcode 118杨辉三角
算法·leetcode·职场和发展
倔强的石头1065 小时前
应用账号最小权限实践:读写账号、报表账号、运维账号分层
java·运维·开发语言
传人once5 小时前
页面中心圆圈放大效果如何写
开发语言·javascript·ecmascript
NeilYuen5 小时前
【C++】STL源码仿写(二):vector
开发语言·c++
蜗牛互联网6 小时前
Python消费Responses SSE事件:增量文本、超时与取消
java·开发语言·人工智能·后端·python
wanderist.6 小时前
线性筛法详解:从筛质数到欧拉函数、Möbius 函数与约数函数
java·数据结构·算法
All for pursuit.6 小时前
【设计-1】208.实现Trie (前缀树)
数据结构·c++·算法·leetcode