水仙花数-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
相关推荐
曲幽3 分钟前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
用户60648767188961 小时前
国内开发者如何接入 Claude API?中转站方案实战指南(Python/Node.js 完整示例)
人工智能·python·api
只与明月听1 小时前
RAG深入学习之Chunk
前端·人工智能·python
用户8356290780513 小时前
自动化文档处理:Python 批量提取 PDF 图片
后端·python
norlan_jame19 小时前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone20 小时前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ40220549620 小时前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
百锦再20 小时前
Django实现接口token检测的实现方案
数据库·python·django·sqlite·flask·fastapi·pip
czy878747520 小时前
除了结构体之外,C语言中还有哪些其他方式可以模拟C++的面向对象编程特性
c语言
QQ51100828520 小时前
python+springboot+django/flask的校园资料分享系统
spring boot·python·django·flask·node.js·php