Search

Blog of AsEs

Try Try && Try is The Key of Success

Category

Class

Class Study Side

Print a Number Pyramid

You have to print a Number Pyramid, like as picture below, by its Line length….

NumberPyramid

Solution Code :

#include<bits/stdc++.h>

#define pb push_back
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout)
#define rev(s) std::reverse(s.begin(), s.end());
#define up std::transform(s.begin(), s.end(), s.begin(), ::toupper);
///string sb=s.substr(1,3);
#define low std::transform(s.begin(), s.end(), s.begin(), ::tolower);
#define n2s(n) stringstream ss; ss<<n; string s=ss.str();
#define CC(x) cout<<(x)<<endl
#define srt sort(a,a+n);
#define rep(n) for(int i=0;i<n;i++)
typedef long long LL;

using namespace std;

int main()
{
    LL Line , Space , Number;
    cin>>Line;
    Space = Line-1;
    for(int i=1;i<=Line;i++)
    {
        for(int j = 0;j<Space;j++){cout<<" ";}
        Space--;
        for(int k=1;k<i*2;k++)
        {
            if(k<=i)
            {
                Number = k;
                cout<<Number;
            }
            else{Number--; cout<<Number;}
        }
        cout<<endl;
    }
    return 0;
}

Advertisements

Again Stack !!!

Problem :

Do this : (Using Sample Idea of Stack)
1. Push a value With Overflow Checking 
2. Pop a Value With Underflow Checking 
3. Top Value Showing 
4. Check Stack Empty or Not
5. Show Updated Top Value

Solution Code :

#include<bits/stdc++.h>
using namespace std;

long long a[100], i=0, flag=0;

long long Fun(long long n)
{
    if(n==1)
    {
        if(i>4){cout<<"\tIts OverFlow , Dont Get any input !!!"<<endl<<endl;}
        else
        {
            cout<<"\tInput  A value : ";
            cin>>a[i];
            i++;
        }
    }
    else if(n==2)
    {
        if(i<0){cout<<"\tStop. Thats UnderFlow "<<endl<<endl;}
        else{ i--; cout<<"\tOk. Popped Done "<<endl<<endl;}
    }
    else if(n==3)
    {
        cout<<"\t Current Top Value Is :  "<<a[i-1]<<endl<<endl;
    }
    else if(n==4)
    {
        for(int j=0;j<i;j++)
        {
            if(a[j]>0){flag=1;}
        }
        if(flag==0){cout<<"\tStack is Empty"<<endl<<endl;}
        else{cout<<"\tStack is Not Empty"<<endl<<endl;}
        flag=0;
    }
    else if(n==5)
    {
        cout<<"\tTop value is Multiplied by 5 : "<<a[i-1]*5<<endl<<endl;
    }
    else{cout<<"\tInvalid value"<<endl<<endl;}
}


int main()
{
    long long  n, a[100];
        cout<<"\t Our Stack Size is 5."<<endl;
        cout<<"1. Push A Value With Overflow Checking : "<<endl;
        cout<<"2. Pop A Value With Underflow Checking :"<<endl;
        cout<<"3. Top Value Show :"<<endl;
        cout<<"4. Check Stack Empty or Not :"<<endl;
        cout<<"5. Show Updated Top Value :"<<endl;
        cout<<"6. EXIT"<<endl;
    while(1)
    {
        cout<<endl;
        cout<<"Enter a Choice :"<<endl;
        cin>>n;
        if(n==6){return 0;}
        Fun(n);
    }
    return 0;
}

Popped a Value Using Array :)

Its My Code Which is Solved in Today's class :

Solution Code :

#include<bits/stdc++.h>
using namespace std;

long long a[1000], i=0;

long long Fun(long long n)
{
    if(n==1)
    {
        cout<<"Input value : ";
        cin>>a[i];
        i++;
        cout<<endl;
    }
    if(n==2)
    {
        i--;
        cout<<"\tPopped : "<<a[i]<<endl;
    }
    if(n==3)
    {
        cout<<"\tArray Is : ";
        for(int j=i-1;j>=0;j--)
        {
            cout<<a[j]<<" ";
        }
        cout<<endl;
    }
}

int main()
{
    long long  n;
    while(1)
    {
        cout<<"Press 1 for Push A value : "<<endl;
        cout<<"Press 2 for Pop A value :"<<endl;
        cout<<"To Show  Array Type 3"<<endl;
        cout<<"Choice : ";cin>>n;
        cout<<endl;
        Fun(n);
        cout<<endl;
    }
    return 0;
}

Create a free website or blog at WordPress.com.

Up ↑