Thursday, February 21, 2019
Advantages of Science
fitting 3 WAQAR AHMED KHAN (5757) Q1. Write a function big businessman ( a, b ), to calculate the value of a raised to b. static overturn Main(string args) Console. WriteLine( submit number with power is to be calculated) int a = Convert. ToInt16(Console. ReadLine()) Console. WriteLine( tuck power) int b = Convert. ToInt16(Console. ReadLine()) Program p = new Program() double c=p. power(a, b) Console. WriteLine(a+ destroy to the power +b+ =+c) toffee-nosed double power(int a, int b) double power = Math. Pow(a, b) blow over power Q2.Write a general-purpose function to convert any apt(p) year into its roman akin. Example Roman equivalent of 1988 is mdcccclxxxviii Roman equivalent of 1525 is mdxxv static void Main(string args) Console. WriteLine( take down 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)) thro w new ArgumentOutOfRangeException( stack away value betwheen 1 and 3999) if (number 1) happen string. Empty f (number = 1000) hand over M + ToRoman(number 1000) if (number = 900) return CM + ToRoman(number 900) if (number = 500) return D + ToRoman(number 500) if (number = cd) 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 = 10) return X + ToRoman(number 10) if (number = 9) return IX + ToRoman(number 9) if (number = 5) return V + ToRoman(number 5) if (number = 4) return IV + ToRoman(number 4) if (number = 1) return I + ToRoman(number 1) throw new ArgumentOutOfRangeException(something bad happened) Q3. all in all year is entered through the keyboard. Write a function to determine whether the year is a pass over year or not. static void Main(string args) Console. WriteLine(enter the year) int a = Convert. ToInt16(Console. ReadLine()) Program p=new Program() . leap(a) private void leap(int a) if (a%4 =0 && a%100==0 && a%400==0) Console. WriteLine(this year is a leap year) else Console. WriteLine(this is not a leap year) Q4. Write a function that receives 5 integers and returns the sum, average and meter deviation of these verse. int a, b, c, d, e Console. WriteLine(enter first number) a = Convert. ToInt16(Console. ReadLine()) Console. WriteLine(enter second number) b = Convert. ToInt16(Console. ReadLine()) Console. WriteLine(enter third number) c = Convert. ToInt16(Console. ReadLine()) Console. WriteLine(enter forth number) = Convert. ToInt16(Console. ReadLine()) Console. WriteLine(enter fifth number) e = Convert. ToInt16(Console. ReadLine()) Program p = new Program() int f = p. sum(a, b, c, d, e) int g = p. average(f) double h = p. standard_deviation(a, b, c, d, e, f, g) Console. WriteLine(sum of numbers are=+f) Console. WriteLine(averge of numbers a re=+g) Console. WriteLine(stardard derivation of numbers is=+h) private double standard_deviation(int a, int b, int c, int d, int e, int f, int g) double i, j, k, l, m,deri,squ i = a g j = b g k = c g l = d g m = e g i = Math. Pow(i, 2) j = Math. Pow(j, 2) = Math. Pow(k, 2) l = Math. Pow(l, 2) m = Math. Pow(m, 2) deri = (i + j + k + l + m) / g squ = Math. Sqrt(deri) return squ private int average(int f) int avg = f / 5 return avg private int sum(int a, int b, int c, int d, int e) int sum = a + b + c + d + e return sum Q5. If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. int sum = 0 for (int i = 3 i 1000 i++) if (i % 3 == 0 i % 5 == 0) sum += i Console. WriteLine(sum. ToString()) Q6. A palindromic number reads the same both ways.The largest palindrome make from the return of two 2-digit numbers is 9009 = 91 99. Find the largest pal indrome made from the product of two 3-digit numbers. int maxPalindrome = 0 for (int i = 100 i 1000 i++) for (int j = i j 1000 j++) int product = i * j if (product. IsPalindrome() && product maxPalindrome) maxPalindrome = product System. Console. WriteLine(maxPalindrome) frequent static class Extensions public static bool IsPalindrome(this int i) List chars = new List(i. ToString(). ToCharArray()) chars. Reverse() return i == int. Parse(new string(chars. ToArray()))
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.