文章

2

粉丝

0

获赞

1

访问

500

头像
打印杨辉三角形 题解:c语言递归
P4922
发布于2026年4月3日 20:00
阅读数 278

#include<stdio.h>

int S(int n ,int m){                                                       //n是行 m是列
    if(m==1 || m==n ) return 1;
    else if(m>n) return 0;
   else return S(n-1,m)+S(n-1,m-1);
}
int main(){
    int n=0;
    scanf("%d",&n);
    int temp=0;
    int curRow=1,i=0;
    while(curRow<=n){
        for(i=1;i<=curRow;i++){
           temp=S(curRow,i);                              //curRow是行 i是列
           printf("%d ",temp);
        }
         ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发