2 solutions

  • 1
    @ 2026-2-22 16:43:34
    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n;
        cin>>n;
        int c=0;
        for(int i=0;i<n;i++)
        {
            cout<<"+";
            for(int j=0;j<c-1;j++)
            {
                cout<<"-";
            }
            if(i!=n-1&&i!=0)cout<<"+";
            //else cout<<"-";
            for(int j=0;j<n-2-c;j++)
            {
                cout<<"-";
            }
            c++;
            cout<<"+\n";
        }
    }
    
    • -1
      @ 2025-11-27 11:55:05

      C++ :

      #include<bits/stdc++.h>
      using namespace std;
      int main(){
      int n;
      cin>>n;
      for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
      if(j==1||j==n)cout<<"+";
      else{
      if(i==j)cout<<"+";
      else cout<<"-";
      }
      }
      cout<<"\n";
      }
      }
      
      • 1

      Information

      ID
      33
      Time
      1000ms
      Memory
      128MiB
      Difficulty
      6
      Tags
      # Submissions
      20
      Accepted
      10
      Uploaded By