Tuesday, 3 September 2013

C++ Program For Amsrong Number


#include<conio.h>
#include<stdio.h>
  class amstrong
    {
      int n,a,b,c;
  public:
      void input();
      void output();
    };

       void amstrong::input()
        {
cout<<"Enter the no ";
cin>>n;
        }
       void amstrong::output()
        {
c=0,b=n;
  while(n>0)
  {
   a=b;
   c=c+(a*a*a);
   n=n/10;
           }
if(c==b)
{
 cout<<"the no is amstrong";
}
else
{
 cout<<"the no is not amstrong";
}
        }

 void main()

 {
  clrscr();
  amstrong a;
  a.input();
  a.output();
  getch();
 }

C++ Program for Adding Two Length


#include<conio.h>
#include<stdio.h>
  class length
    {
      int km,m,cm;
  public:
      void input();
      void display();
      length add(length,length);
    };

       void length::input()
        {
cout<<"Enter km:";
cin>>km;
cout<<"Enter meter:";
cin>>m;
cout<<"Enter cm:";
cin>>cm;    
        }
       void swap::display()
        {
cout<<km<<":"<<m<<":"<<cm;
        }
       length::add(length 1,length 2)
       {
length l;
l.cm=(l1.ss+l2.ss)%100;
l.m=((l1.m+l2.m)%1000)+((l1.cm+l2.cm)/100);
l.km=(l1.km+l2.km)+((l1.m+l2.m)/1000);
return l;
       }
 void main()
 {
  clrscr();
  length l1,l2,l3,l;
  l1.input();
  l2.input();
  l3.add(l1,l2);
  l3.display();
  getch();
 }

C++ Program for Adding Two Times


#include<conio.h>
#include<stdio.h>
  class swaping
    {
      int a,b,c;
  public:
      void input();
      void process();
      void display();
    };

     void swaping::input()
     {
cout<<"Enter the value of A=";
cin>>a;
cout<<"Enter the value of B=";
cin>>b;    
     }
     void swaping::process()  
     {
c=a;
a=b;
b=c;
     }
     void swaping::display()
     {
cout<<"A="<<a<<"B="<<b;
     }
 void main()
 {
  clrscr();
  swaping s;
  s.input();
  s.process();
  s.display();
  getch();
 }

C++ Program for Swap Two Numbers


#include<conio.h>
#include<stdio.h>
  class swaping
    {
      int a,b,c;
  public:
      void input();
      void process();
      void display();
    };

     void swaping::input()
     {
cout<<"Enter the value of A=";
cin>>a;
cout<<"Enter the value of B=";
cin>>b;    
     }
     void swaping::process()  
     {
c=a;
a=b;
b=c;
     }
     void swaping::display()
     {
cout<<"A="<<a<<"B="<<b;
     }
 void main()
 {
  clrscr();
  swaping s;
  s.input();
  s.process();
  s.display();
  getch();
 }

C++ program for fibnocci series


#include<conio.h>
#include<stdio.h>
  class fibno
    {
      int i,n,a,b,c;
  public:
      void fib();
    };

       void fibno::fib()
        {
a=0;
b=1;
c=0;
cout<<"Enter the limit ";
cin>>n;
         cout<<a;
    for(i=1;i<n;i++)
    {
      a=b;
      b=c;
      c=a+b;
             }
         }

 void main()

 {
  clrscr();
  fibnoci f;
  f.fib();
  getch();
 }