Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as C# by hans Luhn ( 13 years ago )
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication165
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Unesite broj kartice : ");
            long brojKartice = long.Parse(Console.ReadLine());
            Console.WriteLine(zbrojParnih(brojKartice) + "  +  " + zbrojNeparnih(brojKartice));
            Console.WriteLine("Provjera broja kartice : "+isValid(brojKartice));
        }
        public static bool isValid(long number)
        {
            
            int provjera = zbrojParnih(number) + zbrojNeparnih(number);
            if (provjera % 10 == 0) return true;
            else return false;

 
        }
        public static int zbrojParnih (long number)
        {
            int ostatak=0;
            int zbroj=0;
            int count = 1;
            while(number>0)
   {
                ostatak = (int)number;
                if(count%2==0)
                {
                    ostatak*=2;
           if (ostatak>=10)
                        zbroj+=getDigit(ostatak);
                    else zbroj+=ostatak;
                }
                number/=10;
                count++;
   }
            return zbroj;
            

        }
        public static int getDigit(int broj)
        {
                int ostatak = broj % 10;
                broj /= 10;
                int zbroj = ostatak + broj;
                return zbroj;
             
            
        }
        public static int zbrojNeparnih(long broj)
        {
            int zbroj=0;
            int count =1;
            while(broj>0)
            {
                int ostatak = (int)broj;
                if (count% 2 != 0)
                {
                    zbroj += ostatak;
                }
                broj /= 10;
                count++;
            }
            return zbroj;
        }

    }
}

 

Revise this Paste

Your Name: Code Language: