Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- private static void Main()
- {
- Random rnd = new Random();
- int numOfNumbers = 1000;
- int palindromeCount = 0;
- for (int i = 0; i < numOfNumbers; i++)
- {
- if (rnd.Next(100, 1000).IsPalindrome())
- {
- palindromeCount++;
- }
- }
- Console.WriteLine((100 * palindromeCount + numOfNumbers / 2) / numOfNumbers + "% Of palindromes");
- Console.ReadKey();
- }
- }
- static class MethodExtensions
- {
- public static bool IsPalindrome(this int randomized)
- {
- int r, sum = 0, temp;
- temp = randomized;
- while (randomized > 0)
- {
- r = randomized % 10;
- sum = (sum * 10) + r;
- randomized /= 10;
- }
- if (temp == sum)
- return true;
- else
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement