SHARE
TWEET

Untitled

a guest Jun 25th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CreditCards
  8. {
  9.     class Program
  10.     {
  11.         static bool CreditCardValid(string CreditCardNum)
  12.         {
  13.             int len = CreditCardNum.Length;
  14.             if (CreditCardNum[0] < '3' || CreditCardNum[0] > '7'
  15.                 || len > 16 || len < 13)
  16.                 return false;
  17.             int sum = 0;
  18.  
  19.             for (int i = 1, num = 0; i < len; i += 2)
  20.             {
  21.                 if (!Char.IsDigit(CreditCardNum[len - i - 1]))
  22.                     return false;
  23.                 num = CreditCardNum[len - i - 1] - '0';
  24.                 if (num * 2 >= 10)
  25.                 {
  26.                     sum += (num * 2) % 10 + (num * 2) / 10;
  27.                 }
  28.                 else
  29.                     sum += num * 2;
  30.             }
  31.             for (int i = 0; i < len; i += 2)
  32.             {
  33.                 sum += CreditCardNum[len - i - 1] - '0';
  34.             }
  35.             if (sum % 10 == 0)
  36.                 return true;
  37.             return false;
  38.         }
  39.         static void Main(string[] args)
  40.         {
  41.             if (CreditCardValid("37976208600299"))
  42.             {
  43.                 Console.WriteLine("valid card!");
  44.             }
  45.             else
  46.                 Console.WriteLine("invalid card!");
  47.  
  48.  
  49.         }
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top