Advertisement
Hazem3529

ArmStrong

Oct 19th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace armstrong
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.            Console.WriteLine("Enter The Number");
  15.            int num = int.Parse(Console.ReadLine());
  16.            bool check= IsArmStrong(num);
  17.            if (check)
  18.            {
  19.                Console.WriteLine("This Is An ArmStrong Number");
  20.            }
  21.            else Console.WriteLine("LOL NO!");
  22.         }
  23.  
  24.  
  25.         public static bool IsArmStrong(int n)
  26.         {
  27.             int orinal = n;
  28.             int sum = 0;
  29.  
  30.             while(n>0)
  31.             {
  32.                 sum += cube(n % 10);
  33.                 n = n / 10;
  34.                
  35.             }
  36.             if (sum == orinal)
  37.             {
  38.                 return true;
  39.             }
  40.             else return false;
  41.  
  42.  
  43.         }
  44.  
  45.         public static int cube(int X)
  46.         {
  47.  
  48.             return X * X * X;
  49.  
  50.         }
  51.  
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement