Interviews3 answers
Write a program to print Armstrong numbers between 1 to 1000
3 Answers
/*
* C# Program to Print all the Armstrong Numbers from 1 to 1000
*/
using System;
class Program
{
static void Main()
{
int a, b, c, d;
for (int i = 1; i <= 1000; i++)
{
a = i / 100;
b = (i - a * 100) / 10;
c = (i - a * 100 - b * 10);
d = a * a * a + b * b * b + c * c * c;
if (i == d)
{
System.Console.WriteLine("{0}", i);
}
}
Console.Read();
}
}
Avikshith AradhyaPosted May 30, 2016, 3:25 AM EDT
int num,r ,save, newnum =0,count=0;
console.writeline("enter a name");
num = console.readline();
save =num;
while(num <= 1000)
{
while(num!=0)
{
num = num/10;
count++;
}
num = save;
whaile(num!=0)
{
r=num%10;
newnum = newnum+p0w(r,count);
num =num/10;
}
if(newnum ==save)
console.writeline("number is nor armstrong{0}", save);
else
console.writeline("number is nor armstrong");
}
}
Munesh SharmaPosted Apr 4, 2014, 1:39 AM EDT
int a, b, c, d;
for (int i = 1; i <= 1000; i++)
{
a = i / 100;
b = (i - a * 100) / 10;
c = (i - a * 100 - b * 10);
d = a * a * a + b * b * b + c * c * c;
if (i == d)
{
System.Console.WriteLine("{0}",i);
}
}
for (int i = 1; i <= 1000; i++)
{
a = i / 100;
b = (i - a * 100) / 10;
c = (i - a * 100 - b * 10);
d = a * a * a + b * b * b + c * c * c;
if (i == d)
{
System.Console.WriteLine("{0}",i);
}
}
Sarath KumarPosted Feb 25, 2014, 3:51 AM EST

