บทนำ
ในบทช่วยสอนนี้ เราจะหาค่า ΔX ที่ทำให้สมการต่อไปนี้เป็นจริง:
(a + ΔX) / (b + ΔX) = c / d
การแก้สมการ
คูณไขว้: d(a + ΔX) = c(b + ΔX)
da + dΔX = cb + cΔX
dΔX - cΔX = cb - da
ΔX(d - c) = bc - ad
ΔX = (bc - ad) / (d - c)
ตัวอย่างโค้ด
#include <bits/stdc++.h>
using namespace std;
int findTheXValue(int a, int b, int c, int d) {
return (b * c - a * d) / (d - c);
}
int main() {
int a = 5, b = 2, c = 8, d = 7;
cout << findTheXValue(a, b, c, d) << endl;
return 0;
}
ผลลัพธ์
19
ตรวจสอบ: (5+19)/(2+19) = 24/21 = 8/7 ✓
ข้อควรระวัง
- ต้องมี d ≠ c (ไม่เช่นนั้นหารด้วยศูนย์)
- ผลลัพธ์ควรเป็นจำนวนเต็ม (โจทย์มักออกแบบให้เป็นจำนวนเต็ม)
- ควรตรวจสอบว่า (b*c - a*d) หาร (d-c) ลงตัว
สรุป
โจทย์นี้เป็นการประยุกต์ใช้พีชคณิตพื้นฐานแก้สมการหาค่าที่ไม่ทราบ หากมีคำถาม สามารถถามได้ในส่วนความคิดเห็นครับ