Last active
November 28, 2022 09:49
-
-
Save RimuruDev/d75fc5f373b7d29f8cea66ebda9139c9 to your computer and use it in GitHub Desktop.
Дано действительное число х. Не пользуясь никакими други- ми арифметическими операциями, кроме умножения, сложения и вычитания, вычислить за минимальное число операций 2Х4- Зх3+ 4х2- 5х + 6. #RimuruDev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Если это решение вам помогло, ставьте + в комментариях. | |
// If this solution helped you, put + in the comments. | |
using System; | |
namespace Honey | |
{ | |
internal sealed class Kaipal | |
{ | |
private static void Main() | |
{ | |
Console.WriteLine(ComputingWithLocalPow(4)); // result: 370 | |
Console.ReadKey(); | |
} | |
private static int ComputingWithLocalPow(int x) => 2 * Pow(x, 4) - 3 * Pow(x, 3) + 4 * Pow(x, 2) - 5 * x + 6; | |
private static int Pow(int num, int pow) | |
{ | |
int result = 1; | |
for (int i = 0; i < pow; i++) | |
{ | |
result *= num; | |
} | |
return result; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Made Rimuru Dev for Kaipal 28.11.2022 11:08 Samara | |
// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// | |
// Task: => /// | |
// Дано действительное число х. Не пользуясь никакими другими /// | |
// арифметическими операциями, кроме умножения, сложения /// | |
// и вычитания, вычислить за минимальное число операций 2Х4- Зх3+ 4х2- 5х + 6. /// | |
// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// | |
namespace Honey | |
{ | |
using System; | |
internal sealed class Kaipal | |
{ | |
private static void Main() | |
{ | |
Console.WriteLine(Pow(6, 6)); // result: 46656 | |
Console.WriteLine(ComputingWithLocalPow(4)); // result: 370 | |
Console.WriteLine(ComputingWithMathPow(4)); // result: 370 | |
Console.ReadKey(); | |
} | |
// Решение задачи с помощью Math.Pow, что противоречит условию задачи. | |
private static int ComputingWithMathPow(int x) => (int)(2 * Math.Pow(x, 4) - 3 * Math.Pow(x, 3) + 4 * Math.Pow(x, 2) - 5 * x + 6); | |
// Решение задачи с помощью своего метода Pow, что удовлетворяет условию задачи. | |
private static int ComputingWithLocalPow(int x) => 2 * Pow(x, 4) - 3 * Pow(x, 3) + 4 * Pow(x, 2) - 5 * x + 6; | |
/// <param name="num"> Число Х из формулы.</param> | |
/// <param name="pow">Возвение в степень.</param> | |
private static int Pow(int num, int pow) | |
{ | |
int result = 1; | |
for (int i = 0; i < pow; i++) | |
{ | |
result *= num; | |
} | |
return result; | |
} | |
} | |
} |
Author
RimuruDev
commented
Nov 28, 2022
Если это решение вам помогло, ставьте + в комментариях.
If this solution helped you, put + in the comments.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment