Write a program of recursive function in C++ to fill an Integer Array of 5 Elements. After fill the array print/show all elements using recursive function. Take array and size of the array from main() body.
You may follow the below page to solve this problem:
http://c-programming-practice.blogspot.com/2013/06/c-function-to-insert-element-in-array.html
This comment has been removed by the author.
ReplyDelete#include
ReplyDeleteusing namespace std;
int fill_array(int array[], int i, int size)
{
if(i>array[i];
fill_array(array,i+1,size);
}
}
int show_array(int array[], int j, int size)
{
if (j<size)
{
cout<<array[j]<<endl;
show_array(array,j+1,size);
}
}
int main()
ReplyDelete{
int i,s;
cout<<"Insert the length of the array: "<>s;
int a[s];
cout<<"Insert the array elements: "<<endl;
fill_array(a,0,s);
cout<<"Inserted Elements are: "<<endl;
show_array(a,0,s);
}
as i cant post my full program code here...so at first i posted the 1st half code,and i posted 2nd half below..
ReplyDelete#include
ReplyDeleteusing namespace std;
void array_recursive(int array[],int n)
{
if(n-1>=0)
{
cout<<"Enter elements into the array:\n";
cin>>array[n];
n--;
array_recursive(array,n);
}
}
int main()
{
int n;
cout<<"Enter the size of an array:\n";
cin>>n;
int array[n];
array_recursive(array,n);
cout<<"Printing Recursive Data\n";
for(int i=n;i>0;i--)
{
cout<<array[i]<<"\n";
}
}
#include
ReplyDelete#include
using namespace std;
class Factorial
{
public:
void setnum(int n)
{
number = n;
}
protected: int number;
};
class findfact: public Factorial
{
public:
int fact=1;
void getfact()
{
for(int i = 1; i <= number; i++)
{
fact *= i;
}
cout<<"The Factorial value for the number is "<>n;
facts.setnum(n);
facts.getfact();
return 0;
}
Md. Zulfikar Ali
ReplyDelete45th Batch
201410524
#include
using namespace std;
// Base class
class Shape
{
public:
void setWidth(int w)
{
width = w;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;
int height;
};
// Derived class
class Rectangle: public Shape
{
public:
int getArea()
{
return (width * height);
}
};
int main(void)
{
Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
cout << "Total area: " << Rect.getArea() << endl;
return 0;
}
Md Zulfikar Ali
ReplyDeleteBatch-45th
201410524.
#include
using namespace std;
class Shape {
protected:
int width, height;
public:
Shape( int a=0, int b=0)
{
width = a;
height = b;
}
int area()
{
cout << "Parent class area :" <area();
shape = &tri;
shape->area();
return 0;
}
md.Abul kashem
ReplyDeleteroll-201410856
#include
using namespace std;
// Base class
class Shape
{
public:
void setWidth(int i)
{
width = i;
}
void setHeight(int h)
{
height = h;
}
protected:
int width;
int height;
};
// Derived class
class Rectangle: public Shape
{
public:
int getArea()
{
return (width * height);
}
};
int main(void)
{
Rectangle Rect;
Rect.setWidth(5);
Rect.setHeight(7);
// Print the area of the object.
cout << "Total area: " << Rect.getArea() << endl;
return 0;
}