Factorial nomli rekursiv funksiya tuzing. X sonini quyidagi formula yordamida hisoblovchi Formula
Download 53.48 Kb.
|
algoritm 29-talik topshiriq javoblari
1-savol N!! ni hisoblovchi butun tipli Factorial nomli rekursiv funksiya tuzing. X sonini quyidagi formula yordamida hisoblovchi Formula nomli rekursiv funksiya tuzing: 2-savol
class Program
int sum = yigindi(k); Console.WriteLine("K sonining raqamlari yig'indisi: {0}", sum); } public static int yigindi(int k) { if (k == 0) { return 0; } else { return k % 10 + yigindi(k / 10); } } } 3-savol
class Program
Console.Write("B ni kiriting: "); int b = Convert.ToInt32(Console.ReadLine()); int sum = Sum(a, b); Console.WriteLine("A dan B gacha sonlar yig'indisi: {0}", sum); } public static int Sum(int a, int b) { if (a == b) { return a; } else { return a + Sum(a + 1, b); } } } 4-savol
class Program { static void Main(string[] args) { Console.Write("A ni kiriting: "); int a = Convert.ToInt32(Console.ReadLine()); Console.Write("N ni kiriting: "); int n = Convert.ToInt32(Console.ReadLine()); double natija = daraja(a, n); Console.WriteLine("{0} ning {1}-darajasi: {2}", a, n, natija); } public static double daraja(int a, int n) { if (n == 0) { return 1; } else if (n < 0) { return 1 / daraja(a, -n); } else if (n % 2 == 0) { double x = daraja(a, n / 2); return x * x; } else { return a * daraja(a, n - 1); } } } 5-savol
Download 53.48 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling