hey, i made this class and it works the only problem is that it gives meonly one
ID: 3616021 • Letter: H
Question
hey,i made this class and it works the only problem is that it gives meonly one armstrong number where there should be 11 numbers as aresult.
Please help me fix my error. Here is my code:
using System;
namespace armstrong
{
public class armstrong
{
public static voidMain(string[]args)
{
Console.WriteLine(" ARMSTRONG NUMBERS FOUND FROM 10 THROUGH999999 ");
int sub = 000010, a,b,c,d,e,f,sum=0,total=0;
while(sub<=999999)
{
/* i = sub;
a = i % 10;
sum = sum + (a * a * a);
i = i / 10;
*/
a = sub-((sub/10)*10);
b = (sub/10)-((sub/100)*10);
c = (sub/100)-((sub/1000)*10);
d = (sub/1000)-((sub/10000)*10);
e = (sub/10000)-((sub/100000)*10);
f = (sub/100000)-((sub/1000000)*10);
sum =(a*a*a*a*a*a)+(b*b*b*b*b*b)+(c*c*c*c*c*c)+(d*d*d*d*d*d)+(e*e*e*e*e*e)+(f*f*f*f*f*f);
if (sub == sum)
{
Console.WriteLine(sub);
total++;
}
sub++;
}
Console.WriteLine(" TOTAL NUMBER OF ARMSTRONG NUMBERS FOUND WAS "+ total);
}
}
}
Explanation / Answer
Here is what you might be looking for. using System; namespace armstrong { public class armstrong { public static void Main(string[]args) { Console.WriteLine(" ARMSTRONG NUMBERS FOUND FROM 10 THROUGH999999 "); int a, b, c, d, e, f, i,sub = 10, sum = 0, total = 0, digit = 0; while (subRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.