[英]Realize equations with C#
如何使用自定義輸入在 C# 中實現這樣的方程?
輸入是腿的數量和動物的數量。
animals: 35
legs: 94
x: Cows
y: Hens
Amount of animals
x + y = 35
y = 35 - x
Amount of legs
Hens: 2 legs
Cows: 4 legs
4x + 2y = 94
->
4x + 2y = 94
4x + 2(35 - x) = 94
4x + 70 - 2x = 94
2x = 24
x = 12
y = 35 - x = 35 - 12 = 23
-> 12 頭奶牛 -> 23 只母雞
如果您只有這兩種動物,我的解決方案適用。
int animals = 35;
int legs = 94;
int x = (legs - 2*animals)/2;
int y = animals -x;
Console.WriteLine(x + " Cows and " + y + " hens");
如果你想解線性方程,那么你可以按照這個鏈接
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.