Tuesday, 10 February 2015

C++ code for 1st practical (intoduction to c++)

         SEMESTER 4: Object oriented programming with C++.



.check that given number is palindron or not :c++ code
 #include<iostream>
using namespace std;
int main()
{
  int number,temp;
  int sum=0,reminder;
  cout<<"give the number what you want"<<endl;
  cin>>number;
  temp=number;
  while(number !=0)
  {
      reminder=number%10;
      sum=sum+reminder*reminder*reminder;
      number=number/10;

  }
    if(sum == temp)
        cout<<"armstrong number"<<endl;
    else
         cout<<"not armstrong number"<<endl;


   return(0);

}

  • find the maximum among the three number
#include<iostream>
using namespace std;
int main()
{
     int a,b,c;
     cout<<"give your three numbers"<<endl;
     cout<<"value of a"<<endl;
     cin>>a;
     cout<<"value of b"<<endl;
     cin>>b;
     cout<<"value of c"<<endl;
     cin>>c;

     if(a>b)
     {
         if(a>c)
            cout<<a <<'\t'<<" is maximum among all three"<<endl;
         else
            cout<<c <<'\t'<<" is maximum among all three"<<endl;
     }

     if (b>a)
     {
         if(b>c)
            cout<<b <<'\t'<<"  is maximum among all three"<<endl;
         else
            cout<<c <<'\t'<<"  is maximum among all three"<<endl;
     }

         cout<<"*******"<<endl;
  
  return(0);

}

  • write a code for Fibonacci series up to 100.
#include<iostream>
using namespace std;
int main()
{
    int a=0,b=1,c=0;
    int i;
    cout<<"fibbo series of 1 to 100"<<endl;
    for(i=0;i<30;i++)
        {

             if(i<=1)
              c=i;
              else
               {
                   c=a+b;
                    a=b;
                    b=c;
                }

            if(c<=100)
            {
                cout<<c<<endl;
            }

         }
    return(0);
}
  • write a program to exchange the information of two variable using pass by reference.

    #include<iostream>
    using namespace std;
    int  swap(float &a,float &b);
    int main()
    {
        float a,b;
        cout<<"give the value of two variable"<<endl;
        cout<<"value of a is "<<endl;
        cin>>a;
        cout<<"value of b is "<<endl;
        cin>>b;
        swap(a,b);
         cout<<" 1.value of a is"<<a<<endl;
          cout<<" 1.value of b is"<<b<<endl;
    }
    int swap(float &a,float &b)
    {
        float t;
          t=a;
          a=b;
          b=t;
         return(0);

    }

No comments:

Post a Comment