fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ConsoleApplication165
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Console.WriteLine("Unesite broj kartice : ");
  13. long brojKartice = long.Parse(Console.ReadLine());
  14. Console.WriteLine(zbrojParnih(brojKartice) + " + " + zbrojNeparnih(brojKartice));
  15. Console.WriteLine("Provjera broja kartice : "+isValid(brojKartice));
  16. }
  17. public static bool isValid(long number)
  18. {
  19.  
  20. int provjera = zbrojParnih(number) + zbrojNeparnih(number);
  21. if (provjera % 10 == 0) return true;
  22. else return false;
  23.  
  24.  
  25. }
  26. public static int zbrojParnih (long number)
  27. {
  28. int ostatak=0;
  29. int zbroj=0;
  30. int count = 1;
  31. while(number>0)
  32. {
  33. ostatak = (int)number%10;
  34. if(count%2==0)
  35. {
  36. ostatak*=2;
  37. if (ostatak>=10)
  38. zbroj+=getDigit(ostatak);
  39. else zbroj+=ostatak;
  40. }
  41. number/=10;
  42. count++;
  43. }
  44. return zbroj;
  45.  
  46.  
  47. }
  48. public static int getDigit(int broj)
  49. {
  50. int ostatak = broj % 10;
  51. broj /= 10;
  52. int zbroj = ostatak + broj;
  53. return zbroj;
  54.  
  55.  
  56. }
  57. public static int zbrojNeparnih(long broj)
  58. {
  59. int zbroj=0;
  60. int count =1;
  61. while(broj>0)
  62. {
  63. int ostatak = (int)broj%10;
  64. if (count% 2 != 0)
  65. {
  66. zbroj += ostatak;
  67. }
  68. broj /= 10;
  69. count++;
  70. }
  71. return zbroj;
  72. }
  73.  
  74. }
  75. }
  76.  
Runtime error #stdin #stdout 0.05s 36464KB
stdin
Standard input is empty
stdout
Unesite broj kartice :