Monday, March 24, 2014

Question No. 32 _35(Decimal, Mod, Bool)

//=================Code for Question No 32=============================== 
Ex 32.    Calculate the volume (ONLY) of a cone. Request radius and height from user, calculate the volume and display it, with 2 decimal points.


 
        static void Main(string[] args)
        {
            Console.Write("Enter radius: ");
            double r = double.Parse(Console.ReadLine());
            Console.Write("Enter height: ");
            double h = double.Parse(Console.ReadLine());

            double volume = 1 / 3.0 * Math.PI * Math.Pow(r, 2) * h;

            Console.WriteLine("Volume: {0:f2}", volume);
            Console.ReadLine();
        }
    }
}
//=================Code for Question No 33===============================
Ex 33.    Request two integer values. Divide the larger value by the smaller value. Display quotient and remainder.

        static void Main(string[] args)
        {
            Console.Write("Enter first integer x: ");
            int x = int.Parse(Console.ReadLine());
            Console.Write("Enter second integer y: ");
            int y = int.Parse(Console.ReadLine());
            double remainder, quotient;
            if (x > y)
            {
                quotient = x / y;
                remainder = x % y;
            }
            else
            {
                quotient = y / x;
                remainder = y % x;
            }
            Console.WriteLine("Quotient: {0}", quotient);
            Console.WriteLine("Remainder: {0}", remainder);
            Console.ReadLine();
        }
 //=================Code for Question No 34===============================
Ex 34.    Write a boolean expression that evaluates to true, when X is greater or equal to Y and Y is different from 12.        static void Main(string[] args)
        {
            Console.Write("Enter value x: ");
            int x = int.Parse(Console.ReadLine());
            Console.Write("Enter value y: ");
            int y = int.Parse(Console.ReadLine());

            bool b1;
            b1 = (x >= y && y != 12);
            Console.WriteLine("b1: {0}", b1);
           
//=================Code for Question No 35===============================
Ex 35.    Write a boolean expression that evaluates to true, when X is either less than half Y, or greater than 10.
            bool b2 = ((x < y/2) || (x > 10));

            Console.WriteLine("b2: {0}", b2);
            Console.ReadLine();
        }

No comments:

Post a Comment