用于循环分隔数字 [英] For loop divide numbers
问题描述
任务是输入数字n,m。程序必须把它作为一个时间间隔,在这个时间间隔里,它检查是否有任何数字是指数相同的数字的总和。
编辑:(18.10 .15)
原来我没有正确理解我的任务。这里是:
用户输入两个数字,程序把它作为它检查所有数字的间隔,如果有一个数字在间隔中,
例如,我输入100和200.在这个区间里有153.
153 = 1 ^ 3 + 5 ^ 3 + 3 ^ 3(1 + 125 + 27)
节目显示为153元。 ;> N;
cin>>米;
for(int i = n; i <= m; i ++)
{
for(int k = n; k< = i; k ++)
{
a = n%10; //例如,我输入153,然后a = 3
f = n / = 10; // f = 15
b = f%10; // b = 5
f = f / = 10; // f = 1
c = f%10; // c = 1
f = f / = 10;
d = f%10;
(int j = 1; j <= 5; j ++)
{
a = a * a;
b = b * b;
c = c * c;
d = d * d;
if(a + b + c + d == n)
{
cout< n<< ENDL;
帮助将不胜感激。
任务是输入数字n,m。程序必须把它作为一个时间间隔,在这个时间间隔里,它检查是否有任何数字是指数相同的数字的总和。
假设范围是 [n,m)
,那么这里是你的程序:
return(n!= m);
任何数字都可以看作是指数相同的数字之和。例如:
0 = 0 ^ 3 + 0 ^ 3 + 0 ^ 3
1 = 1 ^ 3 + 0 ^ 3
2 = 1 ^ 3 + 1 ^ 3
3 = 1 ^ 3 + 1 ^ 3 + 1 ^ 3
等等。即使是负数也是如此。
所以在任何非空范围内至少有一个这样的数字。
I'm an amateur when it comes to C++ but I've already received a task which is over my knowledge.
Task is to enter numbers n,m. Programme must take it as an interval, in which it checks if there is any number which is a sum of numbers with the same exponent.
EDIT:(18.10.15) Turns out I didn't understood my task correctly. Here it is:
"User enter two numbers. Programme takes it as the interval in which it checks all the numbers. If there's a number in interval which all digit's sum of SAME exponent is that number, then programme shows it."
For example, I enter 100 and 200. In this interval there's 153. 153 = 1^3 + 5^3 + 3^3 (1+125+27) Programme shows 153.
cin >> n;
cin >> m;
for (int i=n; i<=m; i++)
{
for (int k=n; k<=i; k++)
{
a = n % 10; //for example, I enter 153, then a=3
f = n /= 10; //f=15
b = f % 10; //b=5
f = f /= 10; //f=1
c = f % 10; //c=1
f = f /= 10;
d = f % 10;
for (int j=1; j<=5; j++)
{
a = a * a;
b = b * b;
c = c * c;
d = d * d;
if (a + b + c + d == n)
{
cout << n << endl;
}
}
}
}
Any help will be appreciated.
Task is to enter numbers n,m. Programme must take it as an interval, in which it checks if there is any number which is a sum of numbers with the same exponent.
Assuming the range is given as [n, m)
, then here's your program:
return (n != m);
Any number can be seen as a sum of numbers with the same exponent. For example:
0 = 0 ^ 3 + 0 ^ 3 + 0 ^ 3
1 = 1 ^ 3 + 0 ^ 3
2 = 1 ^ 3 + 1 ^ 3
3 = 1 ^ 3 + 1 ^ 3 + 1 ^ 3
and so on. This is true even for negative numbers.
So in any non-empty range there exists at least 1 such number.
这篇关于用于循环分隔数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!