| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 427 人关注过本帖
标题:C语言求水仙花数
只看楼主 加入收藏
小白级的小黑
Rank: 2
等 级:论坛游民
帖 子:31
专家分:32
注 册:2022-3-19
结帖率:50%
收藏
 问题点数:0 回复次数:0 
C语言求水仙花数
别的不说了,上码
程序代码:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int x;
    int start = 1;
    int end = 1;
    int count;
    
    printf( "输入位数:" );
    scanf( "%d", &x );
    
    for( count = 1; count < x; count++ )
    {
        start *= 10;
    }
    
    for( count = 1; count <= x; count++ )
    {
        end *= 10;
    }
    
    for( ; start < end; start++ )
    {
        int t = start;
        int sum = 0;
        int digit;
        
        do{
            digit = t % 10;
            t /= 10;
            
            int p = digit;
            int j = 0;
            
            while( j < x - 1 )
            {
                p *= digit;
                j++;
            }
            
            sum += p;
        }while( t > 0 );
        
        if( sum == start)
        {
            printf(">%d\n", start);
        }
    }
    
    system ( "pause" );
    return 0; 
} 


小白入门使用,大佬轻喷!
搜索更多相关主题的帖子: int start count C语言 digit 
2022-11-07 07:16
快速回复:C语言求水仙花数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014787 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved