Hướng dẫn write a 8 8 multiplication table using php - viết bảng cửu chương 8 8 bằng php

Ở đây trong chương trình PHP này, chúng tôi sẽ in bảng nhân mà người dùng muốn xem. Chúng tôi yêu cầu kiến ​​thức về các chủ đề sau đây để thực hiện chương trình này, chúng ta hãy xem chúng

  • BASIC & NBSP; Cú pháp của PHP
  • Hiển thị đầu ra trong PHP
  • Vòng lặp trong PHP

Bảng cửu chương

Trong chương trình này, chúng tôi chấp nhận một số từ người dùng và in bảng nhân của số đó lên đến & nbsp; 10.10.

Ví dụ: nếu số được nhập là 5, nó sẽ in bảng nhân từ 5 đến 10.5 it will print the multiplication table of 5 up to 10.

& nbsp; & nbsp; & nbsp; 5 x 1 = 5 & nbsp; & nbsp; & nbsp; 5 x 2 = 10 & nbsp; & nbsp; & nbsp; 5 x 3 = 15 & nbsp; & nbsp; & nbsp; 5 x 4 = 20 & nbsp; & nbsp; & nbsp; 5 x 5 = 25 & nbsp; & nbsp; & nbsp; 5 x 6 = 30 & nbsp; & nbsp; & nbsp; 5 x 7 = 35 & nbsp; & nbsp; & nbsp; 5 x 8 = 40 & nbsp; & nbsp; & nbsp; 5 x 9 = 45 & nbsp; & nbsp; & nbsp; 5 x 10 = 50
    5 x 2 = 10
    5 x 3 = 15
    5 x 4 = 20
    5 x 5 = 25
    5 x 6 = 30
    5 x 7 = 35
    5 x 8 = 40
    5 x 9 = 45
    5 x 10 = 50

Cách in bảng nhân bằng PHP bằng cách sử dụng PHP

Đầu tiên, chúng tôi phải đọc đầu vào từ người dùng và lưu trữ nó trong một số biến. Bắt đầu a & nbsp; ________ 2 & nbsp; từ i = 1 đến 10 & nbsp; để in bảng nhân số đầu vào của người dùng. Vòng lặp lặp lại & nbsp; 10 lần và in kết quả được tính toán của num x i & nbsp; ở định dạng của bảng nhân.num. Start a for loop from i =1 to 10 for printing the multiplication table of user input number. The loop iterates 10 times and print the computed result of num x i in the format of multiplication table.

Thuật toán

Bước 1: Chấp nhận đầu vào từ người dùng và lưu trữ nó vào NUM biến Accept the input from the user and store it to the variable num

Bước 2: & nbsp; sử dụng a & nbsp; ________ 2 & nbsp; với điều kiện i Using a for loop with condition i <= 10 do the following step (i) incrementing the value of variable i in every iteration

& nbsp; & nbsp; & nbsp; & nbsp; (i) In kết quả của num x i & nbsp; sử dụng & nbsp; ________ 4 làm phép nhânnum x i using echo as the multiplication of the entered number

Mã nguồn PHP

                                          
                                      

Đầu ra

Enter the number: 8
Multiplication table of 8 is

        8 x 1 = 8
        8 x 2 = 16
        8 x 3 = 24
        8 x 4 = 32
        8 x 5 = 40
        8 x 6 = 48
        8 x 7 = 56
        8 x 8 = 64
        8 x 9 = 72
        8 x 10 = 80

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc

    Bàn luận

    Example:

    Trong bài viết này, chúng ta sẽ xem cách in bảng nhân của bất kỳ số nào bằng PHP. Để tạo bảng nhân, trước tiên, chúng tôi nhận được một số đầu vào từ người dùng và sau đó sử dụng cho vòng lặp để hiển thị bảng nhân.

        

    Chúng tôi sử dụng HTML và PHP để hiển thị bảng nhân. Phần HTML được sử dụng để thiết kế một biểu mẫu để lấy đầu vào từ người dùng và phần PHP được sử dụng để thực hiện phép nhân và hiển thị kết quả ở định dạng bảng.

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    4
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    5

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    0
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    7

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    0
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    9

    PHP

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    4for loop5

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    0for loop7

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    0for loop9for loop0
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    3

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    4for loop3

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    0
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    1
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    2

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    4for loop5echo

    echo3echo4echo5

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    3

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    0echo8

        0

    1

    2

    3

    4567

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    4for loop1for loop2 for loop3

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    4for loop5for loop6 for loop7for loop8
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    3

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    0294

        6

        9 062for loop84

        echo 789

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    3

        8 5    0

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    4
    19
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    00    0
    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    02

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    06

        

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    06

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    06

    Enter the number: 8
    Multiplication table of 8 is
    
            8 x 1 = 8
            8 x 2 = 16
            8 x 3 = 24
            8 x 4 = 32
            8 x 5 = 40
            8 x 6 = 48
            8 x 7 = 56
            8 x 8 = 64
            8 x 9 = 72
            8 x 10 = 80
    08

    Output: