Difficult C programs

Discussion in 'C++' started by aijaz, Apr 14, 2008.

  1. sayedbd2015

    sayedbd2015 New Member

    Joined:
    Jan 20, 2015
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Ans (2)
    Code:
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
      for(int i=1;i<=4;i++)
      {
          int k,l;
          k=l=0;
          for(int j=1;j<=i;j++)
          {
              k++;
             cout<<k;
              l++;
              if(l==i)
              {
                  while(k!=1)
                  {
                     k--;
                    cout<<k;
                  }
              }
        }
          cout<<endl;
      }
      return 0;
    }
     
  2. Pradeep Thite

    Pradeep Thite New Member

    Joined:
    Sep 3, 2016
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Code:
    int main()
    {
    
        int n,co=1;
        int i=0;
    
        cout<<"Enter the no of rows";
        cin>>n;
    
        for(int k=0;k<n;k++)
        {
                for(i=1;i<=co;i++)
               {
                     cout<<i;
               }
                 i-=1;
          
               while(--i)
               {
                      cout<<i;
               }
                 co++;
                 cout<<"\n";
        }
        return 0;
    }
    
    OUT PUT:
    if n=5

    1
    121
    12321
    1234321
    123454321
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice