fork download
  1. #include <stdio.h>
  2.  
  3. int main(void)
  4. {
  5. int i, j;
  6. long dec; /* ให้รับค่าอินพุทแบบ Long Integer - เลขจำนวนเต็มแบบยาว */
  7. int bit[32]; /* จองพื้นที่ในการเก็บข้อมูลเลขฐาน 2 ลงใน Array */
  8.  
  9. clrscr(); /* เคลียร์หน้าจอ */
  10. printf("Decimal Number : "); /* แจ้งผู้ใช้เพื่อเตรียมป้อนค่าเลขฐาน 10 */
  11. scanf("%ld", &dec); /* ต้องใช้ ld เพราะ Input มันเป็นแบบ Long Integer */
  12. i = 0; /* กำหนดค่าเริ่มต้นของ Array */
  13. /* ทำตามที่ได้ออกแบบโปรแกรมเอาไว้ ... ยังไงยังงั้นเลย 55555+ */
  14. do {
  15. bit[i++] = dec % 2; /* การหารเอาเศษ เพื่อให้เป็นคำตอบ */
  16.  
  17. /* การหารทั่วไป แต่ตัวแปร dec ของภาษา C มันเป็น Integer หรือ เลขจำนวนเต็ม */
  18. /* ดังนั้นมันจึงตัดเศษ (หรือทศนิยม) ทิ้งไปโดยอัตโนมัติ */
  19. dec = dec / 2;
  20.  
  21. } while (dec > 0); /* เงื่อนไขที่ทำจนกระทั่ง dec = 0 ก็ออกจากวังวนเงื่อนไข */
  22.  
  23. /* การแสดงผลของการแปลงเลขฐาน 10 เป็นเลขฐาน 2*/
  24. /* j = i - 1 และให้ j ลดค่าลงทีละ 1 ... ก็คืออ่านข้อมูลถอยหลังกลับเท่านั้นเองครับ */
  25. /* เพราะตัวแปรแบบ Array ในภาษา C มันเก็บข้อมูลจากซ้ายไปขวา */
  26. /* ทำให้ LSB มันไปอยู่ทางซ้าย ส่วน MSB มันไปอยู่ทางขวา */
  27. for(j = i - 1; j >= 0; j--)
  28. printf("%d", bit[j]);
  29.  
  30. printf("\n");
  31. return 0;
  32.  
  33. }
Success #stdin #stdout 0.03s 25024KB
stdin
<!DOCTYPE html>
<html lang="th">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>เครื่องคำนวณการเงิน</title>
    <script src="https://c...content-available-to-author-only...s.com"></script>
    <link rel="preconnect" href="https://f...content-available-to-author-only...s.com">
    <link rel="preconnect" href="https://f...content-available-to-author-only...c.com" crossorigin>
    <link href="https://f...content-available-to-author-only...s.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Inter', sans-serif;
        }
    </style>
</head>
<body class="bg-gradient-to-r from-blue-100 to-purple-100 flex justify-center items-center min-h-screen p-4">
    <div class="bg-white rounded-lg shadow-xl p-8 w-full max-w-md transition-transform hover:scale-105">
        <h1 class="text-2xl font-semibold text-blue-600 text-center mb-6">เครื่องคำนวณการเงิน</h1>
        <div class="mb-4">
            <label for="initialAmount" class="block text-gray-700 text-sm font-bold mb-2">เงินต้น:</label>
            <input type="number" id="initialAmount" placeholder="ระบุเงินต้น" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
        </div>
        <div class="mb-4">
            <label for="interestRate" class="block text-gray-700 text-sm font-bold mb-2">อัตราดอกเบี้ย (% ต่อปี):</label>
            <input type="number" id="interestRate" placeholder="ระบุอัตราดอกเบี้ย" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
        </div>
        <div class="mb-4">
            <label for="years" class="block text-gray-700 text-sm font-bold mb-2">จำนวนปี:</label>
            <input type="number" id="years" placeholder="ระบุจำนวนปี" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
        </div>
        <div class="mb-6">
            <label for="compoundFrequency" class="block text-gray-700 text-sm font-bold mb-2">ความถี่ในการทบต้น:</label>
            <select id="compoundFrequency" class="shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline">
                <option value="1">รายปี</option>
                <option value="2">ทุกครึ่งปี</option>
                <option value="4">ทุกไตรมาส</option>
                <option value="12">รายเดือน</option>
            </select>
        </div>
        <button id="calculateBtn" class="bg-gradient-to-r from-green-400 to-blue-500 hover:from-green-500 hover:to-blue-600 text-white font-bold py-2 px-4 rounded focus:outline-none focus:shadow-outline w-full transition duration-300 ease-in-out">คำนวณ</button>
        <div id="result" class="mt-6 text-center text-lg font-semibold text-green-600"></div>
    </div>

    <script>
        const initialAmountInput = document.getElementById("initialAmount");
        const interestRateInput = document.getElementById("interestRate");
        const yearsInput = document.getElementById("years");
        const compoundFrequencySelect = document.getElementById("compoundFrequency");
        const calculateBtn = document.getElementById("calculateBtn");
        const resultDiv = document.getElementById("result");

        calculateBtn.addEventListener("click", function() {
            const initialAmount = parseFloat(initialAmountInput.value);
            const interestRate = parseFloat(interestRateInput.value);
            const years = parseInt(yearsInput.value);
            const compoundFrequency = parseInt(compoundFrequencySelect.value);

            if (isNaN(initialAmount) || isNaN(interestRate) || isNaN(years)) {
                resultDiv.textContent = "กรุณาระบุข้อมูลให้ครบถ้วน";
                resultDiv.classList.remove("text-green-600");
                resultDiv.classList.add("text-red-600");
                return;
            }

            if (interestRate < 0) {
                resultDiv.textContent = "กรุณาระบุอัตราดอกเบี้ยเป็นค่าบวก";
                resultDiv.classList.remove("text-green-600");
                resultDiv.classList.add("text-red-600");
                return;
            }

            const futureValue = initialAmount * Math.pow(1 + (interestRate / 100) / compoundFrequency, compoundFrequency * years);
            resultDiv.textContent = `มูลค่าในอนาคต: ${futureValue.toFixed(2)} บาท`;
            resultDiv.classList.remove("text-red-600");
            resultDiv.classList.add("text-green-600");
        });
    </script>
</body>
</html>

stdout
#include <stdio.h>

int main(void)
{
int i, j;
long dec;  /* ให้รับค่าอินพุทแบบ Long Integer - เลขจำนวนเต็มแบบยาว */
int bit[32];  /* จองพื้นที่ในการเก็บข้อมูลเลขฐาน 2 ลงใน Array */

    clrscr();  /* เคลียร์หน้าจอ */
    printf("Decimal Number : ");  /* แจ้งผู้ใช้เพื่อเตรียมป้อนค่าเลขฐาน 10 */
    scanf("%ld", &dec);  /* ต้องใช้ ld เพราะ Input มันเป็นแบบ Long Integer */
    i = 0;  /* กำหนดค่าเริ่มต้นของ Array */
    /* ทำตามที่ได้ออกแบบโปรแกรมเอาไว้ ... ยังไงยังงั้นเลย 55555+ */
    do {
        bit[i++] = dec % 2;  /* การหารเอาเศษ เพื่อให้เป็นคำตอบ */

        /* การหารทั่วไป แต่ตัวแปร dec ของภาษา C มันเป็น Integer หรือ เลขจำนวนเต็ม */
        /* ดังนั้นมันจึงตัดเศษ (หรือทศนิยม) ทิ้งไปโดยอัตโนมัติ */
        dec = dec / 2;

    } while (dec > 0);  /* เงื่อนไขที่ทำจนกระทั่ง dec = 0 ก็ออกจากวังวนเงื่อนไข */

    /* การแสดงผลของการแปลงเลขฐาน 10 เป็นเลขฐาน 2*/
    /* j = i - 1 และให้ j ลดค่าลงทีละ 1 ... ก็คืออ่านข้อมูลถอยหลังกลับเท่านั้นเองครับ */
    /* เพราะตัวแปรแบบ Array ในภาษา C มันเก็บข้อมูลจากซ้ายไปขวา */
    /* ทำให้ LSB มันไปอยู่ทางซ้าย ส่วน MSB มันไปอยู่ทางขวา */
    for(j = i - 1; j >= 0; j--)
        printf("%d", bit[j]);

printf("\n");
return 0;

}