AvengersAssemble

IsNumberPerfect

Sep 6th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 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 IsNumberPerfect
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //לקלוט מספר, לבדוק אם הוא מושלם, אם כן - להציג חישוב
  14.             Console.WriteLine("Please specify number.");
  15.             int perfectInQuestion = int.Parse(Console.ReadLine());
  16.             int[] Perfect = new int[perfectInQuestion];
  17.             int arrNum = 0;
  18.             for (int i = perfectInQuestion - 1; i > 0; i--)
  19.             {
  20.                 if (perfectInQuestion % i == 0)
  21.                 {
  22.                     Perfect[arrNum] = i;
  23.                     arrNum++;
  24.                 }
  25.             }
  26.             int sum = 0;
  27.             for (int arr = 0; arr < arrNum; arr++)
  28.             {
  29.                 sum += Perfect[arr];
  30.             }
  31.             if (sum == perfectInQuestion)
  32.             {
  33.                 Console.WriteLine("Number " + perfectInQuestion + " is perfect.");
  34.                 for (int a = 0; a < arrNum-1; a++)
  35.                     Console.Write(Perfect[a] + "+");
  36.                 Console.WriteLine(Perfect[arrNum - 1] +"=" + sum);
  37.             }
  38.             else
  39.                 Console.WriteLine("Number " + perfectInQuestion + " isn't perfect.");
  40.            
  41.            
  42.  
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment