WAQAR AHMED KHAN
(5757)
Q1. Write a function power ( a, b ), to calculate the value of a raised to b. static void Main(string[] args) { Console.WriteLine("enter number with power is to be calculated"); int a = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("enter power"); int b = Convert.ToInt16(Console.ReadLine()); Program p = new Program(); double c=p.power(a, b); Console.WriteLine(a+ " rase to the power "+b+ "="+c);
}
private double power(int a, int b) { double power = Math.Pow(a, b); return power;
}
Q2. Write a general-purpose function to convert any given year into its roman equivalent.
Example:
Roman equivalent of 1988 is mdcccclxxxviii
Roman equivalent of 1525 is mdxxv
static void Main(string[] args) { Console.WriteLine("enter the year"); int number=Convert.ToInt16(Console.ReadLine());
Program p=new Program(); string samsung=p.ToRoman(number); Console.WriteLine(samsung); }
private string ToRoman(int number) { if ((number < 0) || (number > 3999)) throw new ArgumentOutOfRangeException("insert value betwheen 1 and 3999"); if (number < 1) return string.Empty; if (number >= 1000) return "M" + ToRoman(number - 1000); if (number >= 900) return "CM" + ToRoman(number - 900); if (number >= 500) return "D" + ToRoman(number - 500); if (number >= 400) return "CD" + ToRoman(number - 400); if (number >= 100) return "C" + ToRoman(number - 100); if (number >= 90) return "XC" + ToRoman(number - 90); if (number >= 50) return "L" + ToRoman(number - 50); if (number >= 40) return "XL" + ToRoman(number - 40); if (number