2 条题解

  • 0
    @ 2024-3-16 11:26:17
    #include <iostream>
    #include<algorithm>
    #include<iomanip>
    using namespace std;
    int arr[100][100];
    int main(){ //C++ L18 杨辉三角形(要求背诵)
    	int n;
    	cin>>n;
    	//第一个元素手动赋值为1
    	arr[1][1]=1; 
    	for(int i=2;i<=n;i++)
    		for(int j=1;j<=i;j++)
    			arr[i][j]=arr[i-1][j]+arr[i-1][j-1];
    	
    	
    	for(int i=1;i<=n;i++){
    		//空格组成的倒三角形 
    		for(int j=0;j<n-i;j++)
    			cout<<"   ";
    		for(int j=1;j<=i;j++)
    			cout<<setw(6)<<left<<arr[i][j];
    		cout<<endl;
    	}
        return 0;
    }
    
    • 0
      @ 2024-3-16 11:14:30

      image

      • 1

      信息

      ID
      1206
      时间
      1000ms
      内存
      256MiB
      难度
      7
      标签
      (无)
      递交数
      14
      已通过
      10
      上传者