Monday, March 17, 2014

Generating_Random_Value_Ex_2 (Wk-4), Jan 27-31, 2014

Question: Generate 2 random values n1, n2, (0 to 99).
Display their sum and product. 
Then, indicate if n1 is divisible by n2, or n2 is divisible by n1 or none.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Generate_Random_Value_Ex_2
{
    class Program
    {
        static void Main(string[] args)
        {
            repeat:
            Random rand = new Random();
            int n1 = rand.Next(0, 100);
            int n2 = rand.Next(0, 100);

            Console.WriteLine("Two random value are: n1 = {0} n2 = {1}", n1, n2);
            Console.WriteLine("Sum: {0} Product: {1}", (n1 + n2), (n1 * n2));
            if (n1 % n2 == 0)
            {
                Console.WriteLine("n1 is divisible by n2");
            }
            else if (n2 % n1 == 0)
            {
                Console.WriteLine("n2 is divisible by n1");
            }
            else
            {
                Console.WriteLine("Neither can devide by each other");
            }
            Console.ReadLine();
            Console.Clear();
            goto repeat;
        }
    }
}

No comments:

Post a Comment