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 25552KB
stdin
<!DOCTYPE html>
<html lang="th">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>เข้าสู่ระบบ</title>
  <style>
    body {
      font-family: sans-serif;
      background-color: #f0f2f5;
      display: flex;
      justify-content: center;
      align-items: center;
      height: 100vh;
    }
    .login-box {
      background: white;
      padding: 2rem;
      border-radius: 8px;
      box-shadow: 0 4px 12px rgba(0,0,0,0.1);
      width: 300px;
    }
    .login-box h2 {
      text-align: center;
      margin-bottom: 1.5rem;
    }
    .login-box input {
      width: 100%;
      padding: 0.75rem;
      margin-bottom: 1rem;
      border: 1px solid #ccc;
      border-radius: 4px;
    }
    .login-box button {
      width: 100%;
      padding: 0.75rem;
      background-color: #1877f2;
      border: none;
      color: white;
      font-weight: bold;
      border-radius: 4px;
      cursor: pointer;
    }
    .login-box button:hover {
      background-color: #155bcb;
    }
  </style>
</head>
<body>

  <div class="login-box">
    <h2>เข้าสู่ระบบ</h2>
    <form id="loginForm">
      <input type="text" id="username" placeholder="ชื่อผู้ใช้" required>
      <input type="password" id="password" placeholder="รหัสผ่าน" required>
      <button type="submit">เข้าสู่ระบบ</button>
    </form>
  </div>

  <script>
    document.getElementById('loginForm').addEventListener('submit', function(e) {
      e.preventDefault();
      const username = document.getElementById('username').value;
      const password = document.getElementById('password').value;

      // ตัวอย่างเงื่อนไข (สามารถเชื่อม backend จริงได้)
      if (username === 'admin' && password === '1234') {
        alert('เข้าสู่ระบบสำเร็จ');
        // window.location.href = 'home.html'; // เปลี่ยนหน้า
      } else {
        alert('ชื่อผู้ใช้หรือรหัสผ่านไม่ถูกต้อง');
      }
    });
  </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;

}