![]() |
#2
zklhp2008-11-23 08:20
|
先把c的帖一下

#include <stdio.h>
int c(x,y);
main()
{
int i,j,n=13;
printf("N=");
while(n>12)
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(j=0;j<12-i;j++)
printf(" ");
for(j=1;j<i+2;j++)
printf("%d ",c(i,j));
printf("\n");
}
}
int c(x,y)
int x,y;
{
int z;
if((y==1)||(y==x+1))return(1);
z=c(x-1,y-1)+c(x-1,y);
return(z);
}
再帖一下汇编的 简单加了几句注释 希望大家看懂~~~

;MASMPlus 代码模板 - 控制台程序
.386
.model flat, stdcall
option casemap :none
include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc
include gdi32.inc
include libc.inc
includelib gdi32.lib
includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
includelib msvcrt.lib
include macro.asm
.data
dwLine dd 0
.data?
buffer db MAX_PATH dup(?)
.CODE
;用递归实现
_func proc uses ebx esi edi paramX:DWORD,paramY:DWORD
;这里按api的习惯保护了 ebx esi edi 下面可以尽情破坏数据了 呵呵
mov eax,paramY
mov ecx,paramX
;int 3h
inc ecx
.if (eax==1) || (eax==ecx)
xor eax,eax
inc eax
ret
.endif
dec eax
dec ecx
dec ecx
; z=c(x-1,y-1)+c(x-1,y);
invoke _func,ecx,eax
mov ebx,eax
mov eax,paramY
mov ecx,paramX ;数据变了~~
dec ecx
invoke _func,ecx,eax
add eax,ebx
ret
_func endp
START:
invoke scanf,CTXT('%d'),offset dwLine ;直接用c的函数吧 呵呵
xor ecx,ecx ;ecx=i
.while ecx < dwLine
mov esi,ecx ;保护ecx
neg ecx
add ecx,dwLine
;输出空格 注意对ecx保护
@@:
jecxz @next
push ecx
invoke printf,CTXT(' ')
pop ecx
dec ecx
jmp @B
@next:
mov ecx,esi
mov edi,esi ;保护ecx
inc esi
inc esi ;esi=i+2
xor ebx,ebx
inc ebx
;for(j=1;j<i+2;j++) printf("%d",c(i,j));
;j=ebx
.while ebx < esi
push ecx
invoke _func,ecx,ebx
invoke printf,CTXT('%d '),eax
pop ecx
inc ebx
.endw
invoke StdOut,CTXT(0dh,0ah)
mov ecx,edi
inc ecx
.endw
;暂停显示,回车键关闭
invoke StdIn,addr buffer,sizeof buffer
invoke ExitProcess,0
end START
呵呵 输入的行数别太大 大了就不好看了
程序中的错误还请各位高手指出 不胜感谢
程序+源码
只有本站会员才能查看附件,请 登录