水仙花数-C语言和python实现

C语言代码

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

int main(){
    int i=100,j=0;
    int count=0;
    int num=0;
    for (; i < 1000; i++)
    {

        count = i;
        for(;j<3;j++){
            num = num + (count%10)*(count%10)*(count%10);
            count = (int)(count/10);
        }
        if (num==i)
        {
            /* code */
            printf("%d是一个水仙花数\n",num);
            num=0;
            count=0;
            j=0;
        }else{
            num=0;
            count=0;
            j=0;
        }
        
    }
   return 0; 
}

python实现

python 复制代码
count = 0
for i in range(100,1000):
    for j in range(3):
        num = str(i)
        count = count + eval(num[j])**3
    if count == i:
        print("{}是水仙花数".format(i))
        count = 0
    else:
        count = 0
相关推荐
风流 少年19 小时前
Python Web框架:FastAPI
前端·python·fastapi
Qres82120 小时前
Rabrg/artificial-life test
python·模拟
财经资讯数据_灵砚智能20 小时前
基于全球经济类多源新闻的NLP情感分析与数据可视化(夜间-次晨)2026年5月1日
大数据·人工智能·python·信息可视化·自然语言处理
jinyishu_20 小时前
链表经典OJ题
c语言·数据结构·算法·链表
好奇龙猫20 小时前
[大学院ーpython-base learning3: python and recommendation system ]
开发语言·python
篮子里的玫瑰20 小时前
Python与网络爬虫——字典与集合
开发语言·python
爱编码的小八嘎20 小时前
C语言完美演绎9-14
c语言
skilllite作者20 小时前
Zed 1.0 编辑器深度评测与实战指南
开发语言·人工智能·windows·python·编辑器·agi
2401_8822737220 小时前
pattern属性在旧版Android浏览器无效怎么办_手动验证补充【操作】
jvm·数据库·python
贾红平20 小时前
Python装饰器实战指南
python