mengxin


私信TA

用户名:1000001

访问量:6622

签 名:

等  级
排  名 490
经  验 4506
参赛次数 0
文章发表 73
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

注意事项:

题目说的“数之间用两个空格分开”,其实是一个空格!!

一个数确定位数,然后根据位数,进行立方求和;遍历一遍就行。

最后的结果用数组存储,输出最后一位时不保留空格。

参考代码:

#include <stdio.h>
#include <stdlib.h>
#include<math.h>
int main()
{
    int a[100];
    int length=0;
    for(int i=2;i<1000;i++)
    {

        int count=0;
        int j=i;
        while(j)
        {
            count++;
            j/=10;
        }
        if(count==2)
        {
            if(i==(pow(i/10,3)+pow(i-i/10*10,3)))
                {
                    a[length]=i;
                    length++;
                }
        }
        if(count==3)
        {
            if(i==(pow(i/100,3)+pow((i-i/100*100)/10,3)+pow(i%10,3)))
                {

                    a[length]=i;
                    length++;

                }
        }

    }
    for(int i=0;i<length;i++)
    {
        if(i!=length-1)
            printf("%d ",a[i]);
        else
            printf("%d",a[i]);
    }
    return 0;
}

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区