求出0~999之间的所有“水仙花数”并输出。

来源:互联网 发布:linux中dns配置文件 编辑:程序博客网 时间:2024/05/16 11:00
#include<stdio.h>#include<stdlib.h>#include<math.h>int main(){    int i=0,a=0,b=0,c=0,j=0,m=0;    printf("0-999的水仙花数是");    for(i=100;i<=999;i++)    {        a=i/100;        b=(i%100)/10;        c=i%10;        j=pow(a,3)+pow(b,3)+pow(c,3);        if(i==j)        {            m++;            printf("%d ",i);        }    }    printf("\n");    printf("0-999的水仙花数有 %d 个\n",m);    system("pause");    return 0;}

这里写图片描述

阅读全文
0 0
原创粉丝点击