Câu 1:
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>;
#include<String.h>;
int i,n;
typedef struct {
char hoten;
char lop;
int tuoi;
}sinhvien;
sinhvien*sv;
void nhap (sinhvien*sv){
printf("Nhap danh sach sinh vien:\n");
scanf("%d",&n);
for(i=0;ifflush(stdin);
printf("sinh vien thu :\n",i+1);
fflush(stdin);
printf("Nhap ho ten :");
scanf(sv[i].hoten);
fflush(stdin);
printf("Nhap lop :");
scanf(sv[i].lop);
fflush(stdin);
printf("Nhap tuoi:");
scanf(sv[i].tuoi);
}
}
void hienthi(sinhvien*sv){
for(i=0;i
printf("Sinh vien thu :\n",i+1);
printf("Ho ten %s\n",sv[i].hoten);
printf("Lop %s\n",sv[i].lop);
printf("Tuoi %d\n",sv[i].tuoi);
}
}
void timkiem(sinhvien*sv){
int tk;
char ten[50];
printf("SInh vien ban muon tim la :");
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
scanf("%s",ten);
for(i=0;i
tk=strcmpi(ten,sv[i].hoten);
if(tk==0);
{
printf("Sinh vien muon tim la : %s\n",i+1);
printf("Ho ten :%s\n",sv[i].hoten);
printf("lop :%s\n",sv[i].lop);
printf("tuoi :%d\n",sv[i].tuoi);
}
}
}
void main(){
int chon;
do{
printf("\n THONG TIN SINH VIEN\n");
printf("\n 1.Nhap danh sach sinh vien");
printf("\n 2.Hien thi danh sach sinh vien");
printf("\n 3.Tim kiem sinh vien");
printf("\n 4.ket thuc");
printf("\n Moi ban chon");
scanf("%d",&chon);
switch(chon){
case 1: nhap(&sv); break;
case 2 :hienthi(&sv);break;
case 3 :timkiem(&sv);break;
case 4 : return 1; break;
}
}
while(chon !=4);
getch();
}
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
Câu 2 :
#include <stdio.h>
#include <stdlib.h>
#include<String.h>;
#include<conio.h>;
void nhap(int*n){
printf("Nhap so nguyen duong :");
scanf("%d",n);
}
void timkiem(int n){
int i;
for(i=2;i
if(n%i==0);
return 0;
}
return 1;
}
void vong_lap(int n){
int i=0;
printf("cac so nguyen to nho hon so %d la :",n);
scanf("%d",&n);
for(i=0;i>n;i++){
if(kiemtra(n));
printf("%3d",i);
}
printf("\n");
}
void de_quy(int n){
if(n>=2){
de_quy(n-1);
if(kiemtra(n));
printf("%3d",n);
}
int run();
{
int n;
int check;
here:
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
system("cls");
printf("\t\t\tMenu:\n");
printf("Nhap 1 de nhap so nguyen duong\n");
printf("Nhap 2 Hien thi cac so nguyen to su dung vong lap\n");
printf("Nhap 3 Hien thi cac so nguyen to su dung de quy\n");
printf("Nhap 4 de ket thuc\n");
printf("Moi ban chon ");
scanf("%d",&check);
system("cls");
switch(check)
{
case 1: nhap(&n);break;
case 2:vong_lap(&n);break;
case 3: de_quy(&n);break;
case 4: return 0;
}
getch();
goto here;
}
int main(); {
run();
}
Câu 3:
#include <stdio.h>
#include <stdlib.h>
#include<String.h>
#include<conio.h>
void nhap(float a[100], int *n)
{
int i;
printf("Nhap so phan tu cua mang :\n");
scanf("%d",n);
for(i=0;i
printf("Nhap so phan tu cua mang :\n",i);
scanf("%f",&a[i]);
}
}
void in (float a[100],int n){
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
int i;
printf("Day %c vua nhap la :",n);
for(i=0;i
printf("%6,2f",a[i]);
}
}
void max(float a[100],int n){
int i;
int max=0;
for(i=0;i
if(max
max=a[i];
}
}
printf("gia tri lon nhat cua day la %d",max);
}
void tong(float a[100],int n){
int i;
int tong =0;
for(i=0;i
tong=tong+a[i];
}
printf("Tong cua day la %d",tong);
}
void main()
{
int i;
int chon;
float a[100];
do{
printf("\n 1.Nhap day");
printf("\n 2.phan tu lon nhat");
printf("\n 3.tinh tong");
printf("\n 4.ket thuc");
printf("\nchon 5 : in day ");
printf("\n moi ban chon :\n");
scanf("%d",&chon);
switch(chon)
{
case 1 :nhap(&n);
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
break;
case 3 :max(a,n);
break;
case 4 :tong(a,n);
break;
}
}
while(tong=!5);
getch();
}
Câu 4:
#include<stdio.h>
void nhap(int *d)
{
printf("nhap so can doi: ");
scanf("%d",d);
if(*d<=0){
printf("nhap so duong");
}
}
void chuyen10to2(int i)//sometime,it will be easy and beautiful with recursion
{
if(i>0)
{
chuyen10to2(i/2);
printf("%d",i%2);
}
}
void chuyen10to8(int d)
{
printf("\n%o\n",d);
}
int menu()
{
int chon;
printf("\n1 de nhap");
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
printf("\n2 de in co so 2");
printf("\n3 de in co so 8");
printf("\n4 de rmk\n");
scanf("%d",&chon);
return chon;
}
int main()
{
int d,chon;
while(1)
{
chon=menu();
switch(chon)
{
case 1:nhap(&d);
break;
case 2:chuyen10to2(d);
break;
case 3:chuyen10to8(d);
break;
}
if(chon==4)break;
}
}
Câu 5:
#include<stdio.h>
#include<conio.h>
void nhap(int*n)
{
printf("Nhap so nguyen duong");
scanf("%d",n);
if(n<=0){
printf("vui long nhap so duong");
}
}
void chuyen10to2(int n){
if(n>0);{
chuyen10to2(n/2);
printf("%d",n%2);
}
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
}
void chuyen10to8(int n){
if(n>0);{
chuyen1oto8(n/8);
printf("%d",n%8);
}
}
int main()
{
int chon;
printf("\n=====menu====\n");
printf("\n 1.Nhap so nguyen duong");
printf("\n 2.chuyen sang co so 2");
printf("\n 3.chuyen sang co so 8");
printf("\n moi ban chon:");
scanf("%d",&chon);
}
switch(chon)
{
case 1:nhap(&d);
break;
case 2:chuyen10to2(d);
break;
case 3:chuyen10to8(d);
break;
}
if(chon==4);break;
}
}
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
Câu 6 :
#include <stdio.h>
#include <stdlib.h>
#include<String.h>
#include<stdlib.h>
typedef struct sach{
int maNXB;
char tensach[100];
char tacgia[100];
int masach;
} s;
void nhap(s mang[],int*n)
{
int i;
printf("Nhap vao so luong sach");
scanf("%d",&n);
for(i=0;i
printf("Nhap thong tin sach \n",i+1);
fflush(stdin);
printf("Nhap ma sach :\n");
scanf("%d",mang[i].masach);
fflush(stdin);
printf("Nhap ten sach \n");
scanf("%s",mang[i].tensach);
fflush(stdin);
printf("Nhap ten tac gia \n");
scanf("%s",mang[i].tacgia);
fflush(stdin);
printf("nhap ma NXB");
scanf("%d",mang[i].maNXB);
}
}
void hienthi(s mang[],int n)
{
int tim;
int i;
int kq=0;
printf("nhap ma NXB\n",tim);
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
scanf("%d",tim);
printf("Danh sach cac sach cua NXB \n",tim);
printf("Masach\t\ttensach\t\ttacgia\t\tmaNXB\n",tim);
for(i=0;i
if(mang[i].maNXB=tim){
kq=1;
printf("%3d\t%20s\t%20s\t\t
%3d\n",mang[i].masach,mang[i].tensach,mang[i].tacgia,mang[i].maNXB);
}
if(!kq){
printf("ko co sach nay");
}
int run()
{
int n;
int check;
int sach[100];
here :
{
system ("cls");
printf("\t\t\tMenu:\n");
printf("Nhap 1 nhap thong tin sach\n");
printf("Chon 2 de Hien thi cac sach trong cung nha xuat ban\n");
printf("Nhap 3 de ket thuc\n");
printf("Moi ban chon ");
scanf("%d",&check);
system ("cls");
switch( check) {
case 1: nhap(sach,&n);break;
case 2: in (sach ,n);break;
case 3: return 0;
default : printf( "khong hop le");getch();goto here;
}
}
getch();
goto here;
}
int main() {
run();
}
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
Câu 8 :
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bt8;
import java.util.Scanner;
public class Bt8 {
int i, n;
int []tuoi = new int[5];
String []hoten = new String[50];
String []lop = new String[10];
public void nhap() {
Scanner input = new Scanner(System.in);
System.out.println("Nhap so sinh vien: ");
n = input.nextInt();
for (i = 1; i <= n; i++) {
System.out.println("Nhap thong tin cho sinh vien thu " + i);
System.out.println("Ho va ten: ");
hoten[i] = input.next();
System.out.println("Tuoi:");
tuoi[i] = input.nextInt();
System.out.println("Lop: ");
lop[i] = input.next();
}
}
public void hienthi() {
System.out.println("================THONG TIN SINH
VIEN==============");
System.out.println("\n\t Ho va ten \t\t Tuoi \t\t Lop \n");
for (i = 1; i <= n; i++) {
System.out.println("\t"+hoten[i] + "\t\t" + tuoi[i] + "\t\t" + lop[i]);
}
}
public void timkiem() {
String search;
Scanner input1 = new Scanner(System.in);
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
System.out.println("Nhap ten sinh vien ban can tim kiem:");
search = input1.nextLine();
for (i = 1; i <= n; i++) {
if (search.compareToIgnoreCase(hoten[i]) == 0) {
System.out.println("Thong tin sinh vien ban can tim; ");
System.out.println(hoten[i] + "\t\t" + tuoi[i] + "\t\t" + lop[i]);
} else {
System.out.println("Sinh vien ban can tim khong co trong he thong!!!");
}
}
}
public static void main(String[] args) {
Bt8 sbj = new Bt8();
System.out.println("============CHUONG TRINH QUAN LY SINH
VIEN============");
System.out.println("\n\n 1. Nhap danh sach sinh vien \n 2. Hien thi danh sach
sinh vien \n 3. Tim kiem sinh vien theo ten \n 4. Ket thuc \n");
System.out.println("========================================");
while (true) {
int check;
System.out.println("Nhap chuc nang ban can thuc hien: ");
Scanner input = new Scanner(System.in);
check = input.nextInt();
switch (check) {
case 1:
sbj.nhap();
break;
case 2:
sbj.hienthi();
break;
case 3:
sbj.timkiem();
break;
case 4:
System.exit(0);
}
}
}
}
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
Bai 9 :
package bt9;
import java.util.Scanner;
/**
*
* @author Mirrors
*/
public class SND {
int n,i,j,k1;
public void nhap()
{
System.out.println("Nhap vao so nguyen duong : ");
Scanner nd= new Scanner(System.in);
this.n = nd.nextInt();
}
public void vl()
{
if(n==1) System.out.println(n + " ");
else System.out.println("1 ");
for(i=2;i
{
k1=0;
for(j=2;j<=i;j++)
{
if((i%j)==0) k1++;
}
if(k1==1) System.out.println(i+" ");
}
}
public int ktnt(int k,int i)
{
if(k==i) return k1;
else
{
if((i%k)==0) k1=1;
ktnt(k+1,i);
}
return k1;
}
public int dq(int k)
{
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
k1=0;
if(n==1) {
System.out.println("1");
return 0;
}
if(k==n) return 0;
else
if(ktnt(2,k)==0)
{
System.out.println(k+" ");
}
dq(k+1);
return 0;
}
}
--------------------------------------------------------------------------package bt9;
import java.util.Scanner;
/**
*
* @author Mirrors
*/
public class Bt9 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int k;
SND th= new SND();
do {
System.out.println("\n1. Chon 1 de Nhap so nguyen duong.");
System.out.println("\n2. Chon 2 de Hien thi cac so nguyen to su dung vong
lap.");
System.out.println("\n3. Chon 4 de Hien thi cac so nguyen to su dung de
quy.");
System.out.println("\n4. Chon 3 de Ket thuc.");
System.out.print("Chon: ");
Scanner scank=new Scanner(System.in);
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
k=scank.nextInt();
while(k<1||k>4)
{
System.out.println("\nMoi ban chon lai (1->4): ");
k=scank.nextInt();
}
switch(k)
{
case 1: th.nhap(); break;
case 2: th.vl(); break;
case 3: th.dq(1); break;
}
}while(k!=4);
}
}
Câu 10:
Code:
package bai10;
import java.util.*;
public class Bai10 {
int i, n;
Scanner nhap = new Scanner(System.in);
int[]a = new int[100];
public void nhap() {
System.out.println("Nhap so phan tu cua day: ");
n = nhap.nextInt();
for (i = 0; i < n; i++) {
System.out.println("a[" + (i+1) + "]=");
a[i] = nhap.nextInt();
}
}
public int phantulonnhat(int n, int... a){
if (n == 1) {
return a[0];
}
if (n > 1) {
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
int max = phantulonnhat(n - 1, a);
if (a[n - 1] > max) {
return a[n - 1];
} else {
return (max);
}
}
return 1;
}
public int tongday (int n, int... a){
int tong = a[n-1];
if (n==1)
return a[0];
if (n>1){
return tong + tongday(n-1,a);
}
return 1;
}
public static void main(String[] args) {
int kt;
Scanner nhap = new Scanner(System.in);
Bai10 sbj = new Bai10();
System.out.println("=================== DAY SO =================\n");
System.out.println(" 1. Nhap day so \n");
System.out.println(" 2. Tim phan tu lon nhat \n");
System.out.println(" 3. Tinh tong day \n");
System.out.println(" 4. Ket thuc \n");
System.out.println("===========================================");
while (true){
System.out.println("Nhap chuc nang ban can thuc hien: ");
kt = nhap.nextInt();
switch (kt){
case 1: sbj.nhap();
break;
case 2: System.out.println("Phàn tử lớn nhất của dãy là: " +
sbj.phantulonnhat(sbj.n, sbj.a));
break;
case 3: System.out.println("Tong cua day la: "+ sbj.tongday(sbj.n, sbj.a));
break;
case 4: System.exit(0);
}
}
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
}
}
Câu 11 :
Code:
Interface Ihinh.java:
package bai11;
interface IHinh {
void show();
}
Class HinhVuong.java
package bai11;
import java.util.*;
public class HinhVuong implements IHinh {
@Override
public void show() {
int a, i, j;
Scanner nhap = new Scanner(System.in);
System.out.println("Nhap vao canh:");
a = nhap.nextInt();
System.out.println("chu vi hinh vuong la: " + a * 4);
System.out.println("DIen tich hinh vuong la: " + a * a);
System.out.println("Ve hinh vuong: ");
for (i = 1; i <= a; i++) {
for (j = 1; j <= a; j++) {
System.out.print("*\t");
}
System.out.println("");
}
}
}
Class HinhChuNhat.java
package bai11;
import java.util.*;
public class HinhChuNhat implements IHinh {
@Override
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
public void show() {
int a, b, i, j;
Scanner nhap = new Scanner(System.in);
System.out.println("Nhap vao canh a:");
a = nhap.nextInt();
System.out.println("Nhap vao canh b:");
b = nhap.nextInt();
System.out.println("Chu vi hinh chu nhat la: " + (a + b) * 2);
System.out.println("Dien tich hinh chu nhat la: " + a * b);
System.out.println("Ve hinh chu nhat: ");
for (i = 1; i <= a; i++) {
for (j = 1; j <= b; j++) {
System.out.print("*\t");
}
System.out.println("");
}
}
}
Class Bai11.java
package bai11;
import java.util.*;
public class Bai11 {
public static void main(String[] args) {
int kt;
Scanner nhap = new Scanner(System.in);
HinhVuong sbj1 = new HinhVuong();
HinhChuNhat sbj2 = new HinhChuNhat();
System.out.println(" 1. Thao tac voi hinh vuong \n 2. Thao tac voi hinh chu nhat \n
3.Ket thuc");
System.out.println("=========================================");
while (true) {
System.out.println("Nhap chuc nang ban can thuc hien");
kt = nhap.nextInt();
switch (kt) {
case 1:
sbj1.show();
break;
case 2:
sbj2.show();
break;
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
case 3:
System.exit(0);
}
}
}
}
Câu 12:
Interface IquanLy.java
package bai12;
interface IQuanLy {
public void show();
}
Class GiaoVien.java
package bai12;
import java.util.*;
public class GiaoVien implements IQuanLy {
@Override
public void show() {
int i, n;
Scanner nhap = new Scanner(System.in);
String[] hoten = new String[100];
String[] gioitinh = new String[10];
String[] chuyennganh = new String[30];
String[] ngaysinh = new String[20];
System.out.println("Nhap so giao vien: ");
n = nhap.nextInt();
for (i = 1; i <= n; i++) {
System.out.println("Nhap thong tin cho giao vien thu " + i + "\n");
System.out.println("Nhap ho ten:");
hoten[i] = nhap.next();
System.out.println("Nhap gioi tinh: ");
gioitinh[i] = nhap.next();
System.out.println("Nhap ngay sinh:");
ngaysinh[i] = nhap.next();
System.out.println("Nhap chuyen nganh:");
chuyennganh[i] = nhap.next();
}
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
System.out.println("======================THONG TIN GIAO
VIEN====================");
System.out.println("");
System.out.println("Ho va ten \t Ngay sinh \t Gioi tinh \t\t Chuyen nganh \t\n");
for (i = 1; i <= n; i++) {
System.out.println(hoten[i]+"\t"+ngaysinh[i]+"\t"+gioitinh[i]+"\t"+chuyennganh[i]
+"\n");
}
}
}
Class NhanVien.java
package bai12;
import java.util.*;
public class NhanVien implements IQuanLy{
@Override
public void show() {
String[] hoten = new String[100];
String[] gioitinh = new String[10];
String []congviec = new String[30];
String[] ngaysinh = new String[20];
String []phong = new String[100];
int i,n;
Scanner nhap = new Scanner(System.in);
System.out.println("Nhap so nhan vien: ");
n = nhap.nextInt();
for (i = 1; i <= n; i++) {
System.out.println("Nhap thong tin cho nhan vien thu " + i + "\n");
System.out.println("Nhap ho ten:");
hoten[i] = nhap.next();
System.out.println("Nhap gioi tinh: ");
gioitinh[i] = nhap.next();
System.out.println("Nhap ngay sinh:");
ngaysinh[i] = nhap.next();
System.out.println("Nhap cong viec:");
congviec[i] = nhap.next();
System.out.println("Nhap phong:");
phong[i] = nhap.next();
}
System.out.println("======================THONG TIN NHAN
VIEN====================");
System.out.println("");
System.out.println("Ho va ten \t Ngay sinh \t Gioi tinh \t Cong viec \t Phong\n");
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
for (i = 1; i <= n; i++) {
System.out.println(hoten[i]+"\t"+ngaysinh[i]+"\t"+gioitinh[i]+"\t"+congviec[i]
+"\t"+phong[i]+"\n");
}
}
}
Class Bai12.java
package bai12;
import java.util.*;
public class Bai12 {
public static void main(String[] args) {
int kt;
Scanner nhap = new Scanner(System.in);
GiaoVien sbj1 = new GiaoVien();
NhanVien sbj2 = new NhanVien();
System.out.println("=====================CHUONG TRINH QUAN LY NHAN
SU=====================\n");
System.out.println(" 1. Nhap danh sach giao vien \n 2. Nhap danh sach nhan vien \n
3.Ket thuc");
System.out.println("=========================================");
while (true) {
System.out.println("Nhap chuc nang ban can thuc hien");
kt = nhap.nextInt();
switch (kt) {
case 1:
sbj1.show();
break;
case 2:
sbj2.show();
break;
case 3: System.exit(0);
}
}
}
}
Câu 13:
<!DOCTYPE html>
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
<html>
<head>
<meta charset="UTF-8">
<title>Bài 13</title>
<style>
}
</style>
</head>
<body>
<form action="#" method="POST" class="container">
<table>
<thead>
<tr>
<td colspan="2">Form Đăng ký</td>
</tr>
</thead>
<tbody>
<tr>
<td>Tên</td>
<td><input type="text" placeholder="Nhập tên" name="name"></td>
</tr>
<tr>
<td>Địa chỉ</td>
<td><input type="text" placeholder="Địa chỉ" name="address"></td>
</tr>
<tr>
<td>Nghề</td>
<td><input type="text" placeholder="Nghề" name="job"></td>
</tr>
<tr>
<td>Ghi chú</td>
<td><input type="text" placeholder="Ghi chú" name="note"></td>
</tr>
<tr>
<td colspan="2" class="submit"><input type="reset" value="Xóa">
<input type="submit" name="ok" value="Đăng ký"></td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
/**
* Created by PhpStorm.
* User: Duong Tan
* Date: 20/05/2015
* Time: 9:05 CH
*/
if(isset($_POST["ok"]))
{
echo '<div class="result">';
echo '<table class="info" border="1">';
echo '<tbody>';
if((isset($_POST["name"])) && $_POST["name"] !== "")
{
echo '<tr><td>Tên</td><td>
'.$_POST["name"].'
</td></tr>';
}
if((isset($_POST["address"]))&& $_POST["address"] !== "")
{
echo '<tr><td>Địc chỉ</td><td>
'.$_POST["address"].'
</td></tr>';
}
if((isset($_POST["job"]))&& $_POST["job"] !== "")
{
echo '<tr><td>Nghề</td><td>
'.$_POST["job"].'
</td></tr>';
}
if((isset($_POST["note"]))&& $_POST["note"] !== "")
{
echo '<tr><td>Ghi chú</td><td>
'.$_POST["note"].'
</td></tr>';
}
echo '</tbody>';
echo '</table>';
echo '<div class="error">';
if(!(isset($_POST["name"]))|| $_POST["name"] == "")
{
echo '
Bạn chưa nhập tên
';
}
if(!(isset($_POST["address"]))|| $_POST["address"] == "")
{
echo '
Bạn chưa nhập Địa chỉ
';
}
if(!(isset($_POST["job"]))|| $_POST["job"] == "")
{
echo '
Bạn chưa nhập Nghề
';
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
}
if(!(isset($_POST["note"]))|| $_POST["note"] == "")
{
echo '
Bạn chưa nhập Ghi chú
';
}
echo '</div>';
echo '</div>';
}
?>
Câu 14:
<html>
<head>
<meta charset="UTF-8">
<title>bài 14</title>
<style>
td{
width: 20px;
height: 20px;
}
</style>
</head>
<body>
<form action="#" method="post">
<table>
<thead>
<tr>
<td colspan="2"> Nhập thông tin</td>
</tr>
</thead>
<tbody>
<tr>
<td>
Số cột
</td>
<td><input type="number" placeholder="Nhập số cột" name="cot"></td>
</tr>
<tr>
<td>
Số Hàng
</td>
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D
<td><input type="number" placeholder="Nhập số Hàng" name="hang"></td>
</tr>
<tr>
<td colspan="2">
<input type="reset" value="Nhập lại">
<input type="submit" name="ok" value="Vẽ">
</td>
</tr>
</tbody>
</table>
</form>
</body>
</html>
/**
* Created by PhpStorm.
* User: duong tan
* Date: 20/05/2015
* Time: 9:54 CH
*/
if(isset($_POST["ok"]))
{
if(isset($_POST["cot"]) && isset($_POST["hang"]))
{
echo '<table border="1">';
for($i = 0; $i < $_POST["hang"];$i++)
{
echo '<tr>';
for($j = 0; $j< $_POST["cot"];$j++)
{
echo '<td>';
//cải tiến
// if($i>=$j) echo $j+1;
echo '</td>';
// cải tiến: trước hơn sau 100px echo'<td style="width: '. ($j+1)*100 .'px">'.
($j+1)*100 .'px</td>';
}
echo '</tr>';
}
echo '</table>';
}
Ôn tập Kỹ thuật Lập trình
Đỗ Vệt Hưng –AT10D