Asp . Net || SQL Server
Friday, 23 January 2015
C# Program to check whether a given number is a armstrong number or not
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace armstrong_number_or_not
{
class Program
{
static void Main(string[] args)
{
int num, remainder, sum = 0;
Console.Write("Enter a Number : ");
num = int.Parse(Console.ReadLine());
for (int i = num; i > 0; i = i / 10)
{
remainder = i % 10;
sum = sum + remainder * remainder * remainder;
}
if (sum == num)
{
Console.Write("Entered Number is an Armstrong Number.");
}
else
Console.Write("Entered Number is not an Armstrong Number.");
Console.ReadLine();
}
}
}
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment