Subscribe Us

C++ Program to Display a Armstrong Number and Fibonacci Series

#include <iostream>

using namespace std;

class fun
{
    public:     //armstrong number
    int a;
    int r=0;
    int n;
    int z=0;
    void arm();
};

void fun :: arm()
{
    cin>>a;           // armstrong number
    n=a;
     while(a>0)
     {
        r=a%10;
        z+=(r*r*r);
        a=a/10;
      }
  if(n==z)
    {
    cout<<z<<"is a Armstrong number";
    }
}

class fun1
{
    public:             //fabonacci series
    int x,y=0,z=1,w,c=2;
    void fab();
};

void fun1 :: fab()
{
 cout<<"\nEnter the number to find fabonacci series:";
 cin>>x;
 cout<<"The series is:";
 cout<<y<<"\n"<<z<<"\n";
 while(c<x)
 {
  w=y+z;
  y=z;
  z=w;
  cout<<w<<"\n";
  c++;
 }
}

int main()
{
  fun num;
  fun1 fab10;
  num.arm();
  fab10.fab();
  return 0;
}

Post a Comment

0 Comments