Advertisement
leandrocr

tp00 ejercicio 9 en C#

Aug 17th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 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 TP00EJ9
  8. {
  9.     class Program
  10.     {
  11.         //PROGRAMA QUE DETERMINE SI UN NUMERO ES PERFECTO
  12.         static void Main(string[] args)
  13.         {
  14.             int num;
  15.            Console.Write("Ingrese un numero: ");
  16.             num= int.Parse (Console.ReadLine());
  17.             perfecto(num);
  18.          
  19.             Console.ReadKey();
  20.         }
  21.         public static void perfecto (int num)
  22.         {
  23.            
  24.             int suma = 0;
  25.             for (int i = 1; i < num; i++)
  26.             {
  27.                 if (num % i== 0)  // % resto
  28.                 {
  29.                     suma = suma + i;
  30.                 }
  31.             }
  32.             if (suma == num)
  33.             {
  34.                 Console.WriteLine("");
  35.                 Console.WriteLine("  El Numero es perfecto");
  36.              
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine("");
  41.                 Console.WriteLine("El Numero no es perfecto");
  42.             }
  43.         }
  44.  
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement