1 solutions

  • 0
    @ 2025-11-5 15:54:39

    C++ :

    # include <iostream>
    using namespace std;
    char a[30] = "0123456789ABCDEFGHIJKLMN";
    int main(){
        int n;
        cin >> n;
        for (int i = 1; i <= n; i ++){
            for (int j = 1; j <= n - i; j ++){
                cout << " ";
            }
            for (int j = 1; j <= i; j ++){
                cout << a[j];
            }
            for (int j = i - 1; j >= 1; j --){
                cout << a[j];
            }
            cout << endl;
        }
        return 0;
    }
    

    Pascal :

    var
     n,i,j,b,x,m:integer;
     begin
     readln(n);
     for i:=1 to n do
       begin
       for j:=1 to i do
         begin
          if j>9 then x:=55+j else x:=48+j;
          b:=n-i+1;
          if j=1 then write(chr(x):b)
          else write(chr(x));
         end;
       for m:=i-1 downto 1 do
       begin
       if m>9 then x:=55+m else x:=48+m;
         write(chr(x));
       end;
       writeln; 
       end;
       end.
    
    
    • 1

    Information

    ID
    17316
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By