Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.93 KB | None | 0 0
  1. ///////lab4/////
  2. ////1
  3. using System;
  4. public class lab4_1
  5.     {
  6.         public static void Main(string[] args)
  7.         {
  8.             int num = int.Parse(Console.ReadLine());
  9.             int sum = num % 10;
  10.             while (num != 0)
  11.             {
  12.                 Console.Write(num % 10 + " ");
  13.                 num = num / 10;
  14.                 if (num / 10 == 0)
  15.                     sum += num;
  16.             }
  17.  
  18.             Console.Write("\nСумма цифр на первом и последнем месте  = " + sum + "\n");
  19.         }
  20.     }
  21.  
  22.  
  23. ////2
  24. using System;
  25.    
  26.     public class lab4_2
  27.     {
  28.         public static bool IsPerfect(int n)
  29.         {
  30.             int sum = 0;
  31.             for (int i = 1; i < n; i++)
  32.             {
  33.                 if (n % i == 0)
  34.                     sum += i;
  35.             }
  36.  
  37.             return sum == n;
  38.         }
  39.  
  40.         public static void Main(string[] args)
  41.         {
  42.             Console.Write("a=");
  43.             int a = int.Parse(Console.ReadLine());
  44.             Console.Write("b=");
  45.             int b = int.Parse(Console.ReadLine());
  46.             for (int i = a; i <= b; i++)
  47.             {
  48.                 if (IsPerfect(i))
  49.                     Console.WriteLine(i);
  50.             }
  51.         }
  52.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement