Today I would like to share with you guys a program that is written by a close friend of mind, a fellow software engineer and expert C# developer Mr. Alfel Benvic G. Go he wrote this program we called Armstrong Number Checker using C#. First of all thank you Sir Bon for sharing this program to us. What does the program will do is to ask the user to give a number and then our program will compute the armstrong number based on the given number by our user. Thank you once again Sir Bon for sharing your codes to us.
Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArmstrongNumber
{
/*Armstrong number is a number which is equal to sum of digits raise to the power total number of digits in the number. */
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a Number: ");
String a = Convert.ToString(Console.ReadLine());
Int32 size = a.Length;
Console.WriteLine("Length of the Input Number is = " + size);
Console.WriteLine("\n");
Int32 num = Int32.Parse(a);
Int32 n = num;
Int32 check = 0, remainder;
while (num > 0)
{
remainder = num % 10;
check = check + (Int32)Math.Pow(remainder, size);
num = num / 10;
}
if (check == n)
Console.WriteLine(n + " is an Armstrong Number");
else
Console.WriteLine(n + " is not an Armstrong number");
Console.ReadLine();
}
}
}
No comments:
Post a Comment