only advertisement 2020-11-22 12:09 采纳率: 0%
浏览 11

求助C语言一个对于水仙花数题目的新类型

 Question:The number 153 is a special number. It has the following attributes: 1. 13+53+33 = 153 2. For any positive integer which is multiple of 3, if we cube each digit and then get the sum, repeat this process, finally it will reach 153. For example: 12 13+23=9,   93=729,  73+23+93=1080,   13+03+83+03 = 513, 53+13+33=153
Please write a program to verify all the numbers under 1000 which are the multiple of 3.
/*Try to solve the problem with only the knowledge we have learnt so far. If cannot, you can also use other knowledge in C language.*/

#include<stdio.h>
int main()
{
    int num;
    for(num=1;num<1000;num++){
    while(num%3==0){
    L:int a=num/100;
    int b=num/10%10;
    int c=num%10;
    num=a*a*a+b*b*b+c*c*c;
    if(num!=153)
        goto L;
    if(num==153)
        break;
    }
    printf("%d is a flower number\n",num);
    }
}

希望有大佬能指点一下迷津,谢谢

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-09-09 16:26
    关注
    不知道你这个问题是否已经解决, 如果还没有解决的话:

    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^
    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)