Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace IsNumberPerfect
- {
- class Program
- {
- static void Main(string[] args)
- {
- //לקלוט מספר, לבדוק אם הוא מושלם, אם כן - להציג חישוב
- Console.WriteLine("Please specify number.");
- int perfectInQuestion = int.Parse(Console.ReadLine());
- int[] Perfect = new int[perfectInQuestion];
- int arrNum = 0;
- for (int i = perfectInQuestion - 1; i > 0; i--)
- {
- if (perfectInQuestion % i == 0)
- {
- Perfect[arrNum] = i;
- arrNum++;
- }
- }
- int sum = 0;
- for (int arr = 0; arr < arrNum; arr++)
- {
- sum += Perfect[arr];
- }
- if (sum == perfectInQuestion)
- {
- Console.WriteLine("Number " + perfectInQuestion + " is perfect.");
- for (int a = 0; a < arrNum-1; a++)
- Console.Write(Perfect[a] + "+");
- Console.WriteLine(Perfect[arrNum - 1] +"=" + sum);
- }
- else
- Console.WriteLine("Number " + perfectInQuestion + " isn't perfect.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment