程序设计:求一个三位数各位数的立方和等于这个数的倒数第二大的数

langlang99 1年前 已收到1个回答 举报

我从金星来的 幼苗

共回答了12个问题采纳率:100% 举报

"#include<stdio.h>intmain(){inta,b,c;intct=0;for(a=9;a>0;a--)for(b=9;b>0;b--)for(c=9;c>0;c--){if(a*100+b*10+c==a*a*a+b*b*b+c*c*c){ct++;if(ct==2)//倒数第二大的数{printf(""%d=%d^3+%d^3+%d^3n"",a*100+b*10+c,a,b,c);return0;}}}return0;}■■:是不是错啦,运行不了,程序语言有问题补充:上面是C的,当然在VFP下不能运行(且上面要改>=0)
以下是VFP的
set echo off
clear
clear all
ct=0
for a=9 to 0 step -1
for b=9 to 0 step -1
for c=9 to 0 step -1
if a*100+b*10+c=a^3+b^3+c^3 then
ct=ct+1
if ct=2 then
? str(a*100+b*10+c)+""=""+str(a)+""^3""+str(b)+""^3""+str(c)+""^3""
return
endif
endif
endf
endf
endf补充:改上面的?部分为
? str(a*100+b*10+c)+""=""+allt(str(a))+""^3+""+allt(str(b))+""^3+""+allt(str(c))+""^3""
就完美了
结果
371=3^3+7^3+1^3"

1年前

7
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.068 s. - webmaster@yulucn.com