某些要求的数字 [英] numbers for a certain requirements

查看:51
本文介绍了某些要求的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此计划有两个部分。

第一部分:

编写一个C ++程序,确定哪个四位数符合以下条件:

将前两位数字添加为数字最后两位数字作为数字。此总和的平方等于原始数字。

例如:

原始数字是4321.确定43 + 21等于63,平方时是3969等于原始数字(4321)。

第二部分:

程序继续确定哪个2,3和4位数字等于其数字立方体的总和。

例如:

如果原始数字是234,确定2立方(8)+ 3立方(27)+ 4立方(64)是99等于原来的234.


到目前为止:

There are two sections to this program.
Section one:
Write a C++ program that determines which four digit numbers meet the following conditions:
Add the first two digits as a number to the last two digits as a number. The square of this sum equals the original number.
Example:
Original number is 4321. Determine if 43 + 21 which equals 63, when squared, is 3969 is equal to the original number (4321).
Section two:
The program continues by determining which 2, 3, and 4 digit numbers are equal to the sum of the cubes of their digits.
Example:
If the original number is 234, determine if 2 cubed (8) + 3 cubed (27) + 4 cubed (64) which is 99 is equal to the original 234.

So far:

展开 | 选择 | Wrap | 行号

推荐答案

您正确地将变量secA设置为partA和partB的总和,然后检查temp的平方是否等于j。 temp甚至声明或使用在哪里?
You correctly set the variable secA to the sum of partA and partB, but then you check whether the square of temp is equal to j. Where is temp even declared or used?


展开 | 选择 | Wrap | 行号


嗯,这将是一个简单的方法,但是可能要长得多。

将数字加载为字符串[string1],请求[在1或2位置] s />
然后你有两个字符串[string2]和string3]

然后你可以将两个字符串转换为整数(int1和int2)

然后int3 = int1 + int2

然后int4 = int3 * int3

然后将int4转换为字符串[string4]

if(string4 == string1){THEY A RE EQUAL!}
Well, this would be a simple way, but proably a lot longer.
load the number as a string[string1], sepreate the sring [at pos 1 or 2]
then youd have two strings[string2 and string3]
then you could convert the two strings each to ints (int1 and int2)
then int3=int1+int2
then int4=int3*int3
then convert int4 to a string[string4]
if(string4==string1){THEY ARE EQUAL!}


这篇关于某些要求的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆