Jump to content
Nepenthe

C# math basic

Recommended Posts

Posted

public static void math4()
        {
            int sum = 0;
            int sum1 = 0;
            int C = 0;
            Console.Write("Enter a number: ");
            int N = Int32.Parse(Console.ReadLine());
           
            while(N > 0)
            {
                C = N % 10;
                if (C % 2 == 0)
                {
                    sum += C;
                    Console.WriteLine("Sum even of {0} is {1}.", N, sum);
                }
                else
                {
                    sum1 += C;
                    N /= 10;
                    Console.WriteLine("Suma odd of {0} is {1}.", N, sum1);
                }
            }
            Console.ReadLine();
        }

 

//Ideea e sa imi scoata suma cifrelor pare si a celor impare separat; am facut eu ceva pe aici dar nu prea e treaba. Mersi anticipat!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...