Topics

6/recent/ticker-posts

Some important programs part 1

Some Important programs 

1. Arithmetic program using switch case 

Note: iostream.h will be used and using namespace std is removed when using this program in turbo c++

 #include<iostream>

using namespace std;

int main()

{

    float a,b,res;

    int ch;

    cout<<"Arithmetic Operations"<<endl;

    cout<<"1. Addition"<<endl;

    cout<<"2. Subtraction "<<endl;

    cout<<"3. Multiplication"<<endl;

    cout<<"4. Division"<<endl;

    cout<<"Enter your Choice"<<endl;

    cin>>ch;

    switch(ch)

    {

        case 1:

        {

            cout<<"Enter two variables:"<<endl;

            cin>>a>>b;

            res = a+b;

            cout<<"The Addition Result is"<<res<<endl; 

        }

        break;

         case 2:

        {

            cout<<"Enter two variables:"<<endl;

            cin>>a>>b;

            res = a-b;

            cout<<"The Subtraction Result is"<<res<<endl; 

        }

        break;

         case 3:

        {

            cout<<"Enter two variables:"<<endl;

            cin>>a>>b;

            res = a*b;

            cout<<"The Multiplication Result is"<<res<<endl; 

        }

        break;

         case 4:

        {

            cout<<"Enter two variables:"<<endl;

            cin>>a>>b;

            res = a/b;

            cout<<"The Division Result is"<<res<<endl; 

        }

        break;

        default:

            cout<<"\n NO choice "<<endl;

        break;

    }

    return 0;

}

2. Armstrong Number

Note: iostream.h will be used and using namespace std is removed when using this program in turbo c++

#include<iostream>

using namespace std;

class arms

{

    int a,b,n,m,arm;

public:

    arms(int x)

    {

        a=x;

        b=x;

        arm=0;

        while(a!=0)

        {

            n=a%10;

            n=n*n*n;

            arm = arm +n;

            a=a/10;

        }

    }

    void printdata()

    {

        if(arm==b)

        {

            cout<<"The Given number is armstrong"<<endl;

        }

        else{

            cout<<"The Given number is not Armstrong"<<endl;

        }

    }

    ~arms()

    {

        cout<<"Destructing"<<endl;

    }

};


int main()

{

    int p;

    cout<<"Enter the Number to check"<<endl;

    cin>>p;

    arms h(p);

    h.printdata();

    return 0;

}

3. Factorial of n_numbers:

Note: iostream.h will be used and using namespace std is removed when using this program in turbo c++

#include<iostream>

using namespace std;

class fact 

{

private:

    int n,i;

    long int f;

public:

    void factorial()

    {

        f=1;

        cout<<"Enter the number"<<endl;

        cin>>n;

        for(i=1;i<=n;i++)

        {

            f=f*i;

        }

        cout<<"Factrial="<<f<<endl;

    }

};

int main()

{

    fact f;

    f.factorial();

    return 0;

}

4. Fibonacci series using copy constructor:

Note: iostream.h will be used and using namespace std is removed when using this program in turbo c++

#include<iostream>

using namespace std;

class series

{

private:

    int a,b,c,i,n,no;

public:

    series(int no)

    {

        n=no;

    }

    series(series &p)

    {

        n=p.n;

        a=-1;

        b=1;

    for(int i=0;i<n;i++)

    {

        c=a+b;

        a=b;

        b=c;

        cout<<c<<endl;

    }

    }

};


int main()

{

    series s1(5);

    

    cout<<"Fibonaci  Series of Given Number"<<endl;

    series s2(s1);

    return 0;

}

 Note: iostream.h will be used and using namespace std is removed when using this program in turbo c++

Note: And remaining programs will be uploaded in next parts

Post a Comment

2 Comments