[ create a new paste ] login | about

Link: http://codepad.org/CZKyy8Ry    [ raw code | output | fork ]

C, pasted on May 6:
# De Bai : Nhap vao mot so nguyen n,di tinh ra ket qua : + Cac so chan tu 1 -> n , + Cac so le tu 1 -> n
/* 

Tác giả: Nguyễn Việt Nam Sơn
Trung tâm đào tạo tin học - Thiết kế phần mềm - Sơn Đẹp Trai: www.SonDepTrai.com

Nguồn source code này Tôi viết vào năm 2012 lúc mới bắt đầu học lập trình C/C++ nên một số cách sẽ không được tối ưu - Bạn chỉ nên dùng trên tinh thần tham khảo thôi nhé.
Mong giúp đỡ được Bạn trên con đường Học Lập Trình.
TẤT CẢ VÌ SỰ THÀNH CÔNG CỦA BẠN

*/
.data
	tb1:.asciiz "Nhap vao so nguyen n = "
	tb2:.asciiz "Tong cac so chan tu 1 -> n = "
	tb3:.asciiz "Tong cac so le tu 1 -> n = "
	XuongDong:.asciiz "\n"
	n:.word 0
.text
main:
	# Xuat tb1
	li $v0,4
	la $a0,tb1
	syscall
	
	# Nhap so nguyen
	li $v0,5
	syscall
	
	# Luu tru vao n
	sw $v0,n
	
	# Khoi tao gia tri vong lap tinh cac gia tri chan
	li $t0,0 # Tong = 0
	li $t1,2 # i = 2
	lw $t2,n # Chep gia tri n vao thanh ghi tam $t2 
	
LapChan:
	sub $t3,$t2,$t1 # $t3 = n - i
	bltz $t3,KetThucLapChan
	add $t0,$t0,$t1 # Tong = Tong + i
	addi $t1,$t1,2 # i = i + 2
	j LapChan
	
KetThucLapChan:
	# Xuat tb2
	li $v0,4
	la $a0,tb2
	syscall
	
	move $a0,$t0 # Dua gia tri Tong trong thanh ghi tam $t0 vao trong thanh ghi $a0 .
	
	# Xuat Tong
	li $v0,1
	syscall

	# Xuong Dong
	li $v0,4
	la $a0,XuongDong
	syscall
	
	# Khoi tao gia tri vong lap tinh cac gia tri le
	li $t0,0 # Tong = 0
	li $t1,1 # i = 1
	lw $t2,n # Chep gia tri n vao thanh ghi tam $t2 
	
LapLe:
	sub $t3,$t2,$t1 # $t3 = n - i
	bltz $t3,KetThucLapLe
	add $t0,$t0,$t1 # Tong = Tong + i
	addi $t1,$t1,2 # i = i + 2
	j LapLe
	
KetThucLapLe:
	# Xuat tb3
	li $v0,4
	la $a0,tb3
	syscall
	
	move $a0,$t0 # Dua gia tri Tong trong thanh ghi tam $t0 vao trong thanh ghi $a0 .
	
	# Xuat Tong
	li $v0,1
	syscall
Exit:
	li $v0,10
	syscall
	


Output:
Line 2: error: invalid preprocessing directive #De
Line 12: error: expected identifier or '(' before '.' token
Line 3: error: invalid preprocessing directive #Xuat
Line 3: error: invalid preprocessing directive #Nhap
Line 3: error: invalid preprocessing directive #Luu
Line 3: error: invalid preprocessing directive #Khoi
Line 33: error: stray '#' in program
Line 34: error: stray '#' in program
Line 35: error: stray '#' in program
Line 38: error: stray '#' in program
Line 40: error: stray '#' in program
Line 41: error: stray '#' in program
Line 3: error: invalid preprocessing directive #Xuat
Line 50: error: stray '#' in program
Line 3: error: invalid preprocessing directive #Xuat
Line 3: error: invalid preprocessing directive #Xuong
Line 3: error: invalid preprocessing directive #Khoi
Line 62: error: stray '#' in program
Line 63: error: stray '#' in program
Line 64: error: stray '#' in program
Line 67: error: stray '#' in program
Line 69: error: stray '#' in program
Line 70: error: stray '#' in program
Line 3: error: invalid preprocessing directive #Xuat
Line 79: error: stray '#' in program
Line 3: error: invalid preprocessing directive #Xuat


Create a new paste based on this one


Comments: