Advertisement
Yonka2019

Untitled

Apr 8th, 2021
86
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.  
  3. class Program
  4. {
  5.     private static readonly Random rnd = new Random();
  6.     private static void Main()
  7.     {
  8.         int numOfNumbers = 1000;
  9.         for (int i = 0; i < numOfNumbers; i++)
  10.         {
  11.             Console.WriteLine($"Palindrome number {i}: {RandomPalindrome(100, 1000)}");
  12.         }
  13.         Console.ReadKey();
  14.     }
  15.     private static int RandomPalindrome(int min, int max)
  16.     {
  17.         int randomized;
  18.         do
  19.         {
  20.             randomized = rnd.Next(min, max);
  21.  
  22.         } while (!randomized.IsPalindrome());
  23.         return randomized;
  24.     }
  25.  
  26. }
  27. static class MethodExtensions
  28. {
  29.     public static bool IsPalindrome(this int randomized)
  30.     {
  31.         int r, sum = 0, temp;
  32.         temp = randomized;
  33.         while (randomized > 0)
  34.         {
  35.             r = randomized % 10;
  36.             sum = (sum * 10) + r;
  37.             randomized /= 10;
  38.         }
  39.         if (temp == sum)
  40.             return true;
  41.         else
  42.             return false;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement