任务二报告v1.2前言:本次任务我使用的是c语言(其他语言不熟悉...汗颜)。源码:#includeintmain(){inta,b,c,d,e,f,g,h,i,j,k,l;printf("10000以内的水仙花数:");printf("四位数有:");for(a=1000;a<=9999;a++)for(b=0;b<=9999;b++)for(c=0;c<=9999;c++)if(a*100000000+b*10000+c==a*a*a+b*b*b+c*c*c)printf("%d%d%04d",a,b,c);printf("三位数有:");for(f=100;f<=999;f++)for(d=0;d<=999;d++)for(e=0;e<=999;e++)if(f*1000000+d*1000+e==f*f*f+d*d*d+e*e*e)printf("%d%d%03d",f,d,e);printf("二位数有:");for(g=10;g<=99;g++)for(h=0;h<=99;h++)for(i=0;i<=99;i++)if(g*10000+h*100+i==g*g*g+h*h*h+i*i*i)printf("%d%d%02d",g,h,i);printf("一位数有:");for(j=1;j<=9;j++)for(k=0;k<=9;k++)for(l=0;l<=9;l++)if(j*100+k*10+l==j*j*j+k*k*k+l*l*l)printf("%d%d%d",j,k,l);}运行结果:设计思路:刚拿到这个题目的时候,我想到先定义三个变量i,j,k,我将i设定为从1到99的任意整数,j和k为0到9的任意整数,根据条件来判断,便得出了结果,用时为0.55秒,之后我考虑能不能将结果优化,因为结果中最大的为四位数,如果i为两位数,则其立方不能超过10000,否则就不会成立,于是我将10000开三次方,得出最大的立方不超过10000的两位数是21,于是我把21带入i的循环语句中,成功缩短了时间,最后结果的时间降为0.016秒。第一版本出现了严重错误,即忽略了121和112的两种情况,现已重新增加两组循环语句,得出了相对更准确的结果。#includeintmain(){inta,b,c,d,e,f,g,h,i,j,k,l;printf("10000以内的水仙花数:\n");printf("三位数有:");for(f=100;f<=999;f++)for(d=0;d<=999;d++)for(e=0;e<=999;e++)if(f*1000000+d*1000+e==f*f*f+d*d*d+e*e*e)printf("%03d%03d%03d",f,d,e);printf("\n二位数有:");for(g=10;g<=99;g++)for(h=0;h<=99;h++)for(i=0;i<=99;i++)if(g*10000+h*100+i==g*g*g+h*h*h+i*i*i)printf("%02d%02d%02d",g,h,i);printf("\n一位数有:");for(j=1;j<=9;j++)for(k=0;k<=9;k++)for(l=0;l<=9;l++)if(j*100+k*10+l==j*j*j+k*k*k+l*l*l)printf("%d%d%d",j,k,l);}#includeintmain(){inta,b,c,d,e,f,g,h,i,j,k,l;printf("10000以内的水仙花数:");printf("\n四位数有:");for(a=1000;a<=9999;a++)for(b=0;b<=9999;b++)for(c=0;c<=9999;c++)if(a*100000000+b*10000+c==a*a*a+b*b*b+c*c*c)printf("%04d%04d%04d",a,b,c);printf("\n三位数有:");for(f=100;f<=999;f++)for(d=0;d<=999;d++)for(e=0;e<=999;e++)if(f*1000000+d*1000+e==f*f*f+d*d*d+e*e*e)printf("%03d%03d%03d",f,d,e);printf("\n二位数有:");for(g=10;g<=99;g++)for(h=0;h<=99;h++)for(i=0;i<=99;i++)if(g*10000+h*100+i==g*g*g+h*h*h+i*i*i)printf("%02d%02d%02d",g,h,i);printf("\n一位数有:");for(j=1;j<=9;j++)for(k=0;k<=9;k++)for(l=0;l<=9;l++)if(j*100+k*10+l==j*j*j+k*k*k+l*l*l)printf("%d%d%d",j,k,l);#includeintmain(){inta,b,c,d,e,f,g,h,i,j,k,l;longlongz,x;printf("10000以内的水仙花数:");printf("\n四位数有:");for(a=1000;a<=9999;a++)for(b=0;b<=9999;b++)for(c=0;c<=9999;c++){z=a*100000000+b*10000+c;x=a*a*a+b*b*b+c*c*c;}if(z==x)printf("%04d%04d%04d",a,b,c);printf("\n三位数有:");for(f=100;f<=999;f++)for(d=0;d<=999;d++)for(e=0;e<=999;e++){if(f*1000000+d*1000+e==f*f*f+d*d*d+e*e*e)printf("%03d%03d%03d",f,d,e);}printf("\n二位数有:");for(g=10;g<=99;g++)for(h=0;h<=99;h++)for(i=0;i<=99;i++){if(g*10000+h*100+i==g*g*g+h*h*h+i*i*i)printf("%02d%02d%02d",g,h,i);}printf("\n一位数有:");for(j=1;j<=9;j++)for(k=0;k<=9;k++)for(l=0;l<=9;l++){if(j*100+k*10+l==j*j*j+k*k*k+l*l*l)printf("%d%d%d",j,k,l);}}