Advertisement
Dianov

Basic Syntax, Conditional Statements and Loops - Exercise (06. Strong number)

Mar 26th, 2021
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 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 StrongNumber
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string givenNumber = Console.ReadLine();
  14.             string singleNumber = string.Empty;
  15.             int factoriel = 1;
  16.             int sum = 0;
  17.  
  18.             for (int i = 0; i <= givenNumber.Length - 1; i++)
  19.             {
  20.                 singleNumber += givenNumber[i];
  21.                 for (int j = 1; j <= int.Parse(singleNumber); j++)
  22.                 {
  23.                     factoriel *= j;
  24.                 }
  25.                 sum += factoriel;
  26.                 factoriel = 1;
  27.                 singleNumber = string.Empty;
  28.             }
  29.  
  30.             if (sum == int.Parse(givenNumber))
  31.             {
  32.                 Console.WriteLine("yes");
  33.             }
  34.             else
  35.             {
  36.                 Console.WriteLine("no");
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement