Factorial of a number using recursive function
#include
#include
using namespace std;
int recursive_function(int n)
{
static int i=1;
cout<
if(n==1)
{
return 1;
}
else
{
i++;
return n=n*recursive_function(n-1);
}
}
int main()
{
cout<<"Enter to number to find Factorial: ";
int num;
cin>>num;
num=recursive_function(num);
cout<<"\n\n\n\t\t\tFactorial of number is: "<
cout<<"\n\n\n\n\n";
return 0;
}
Bubble sort
program code in C++
#include
#include
using namespace std;
int main()
{
int array[5];
cout<<"Enter 5 numbers randomly : "<
for(int i=0; i<5 i="" nbsp="" span="">5>
{
cin>>array[i];
}
cout<
cout<<"Input array is: "<
for(int j=0; j<5 j="" nbsp="" span="">5>
{
cout<<"\t\t\tValue at "<
}
cout<
int temp;
for(int i2=0; i2<=4; i2++)
{
for(int j=0; j<4 j="" nbsp="" span="">4>
{
if(array[j]>array[j+1])
{
temp=array[j];
array[j]=array[j+1];
array[j+1]=temp;
}
}
}
cout<<" Sorted Array is: "<
for(int i3=0; i3<5 i3="" nbsp="" span="">5>
{
cout<<"\t\t\tValue at "<
}
return 0;
}
Maximum
and minimum number in array C++ code array should be initialized randomly
#include
#include
#include
#include
using namespace std;
int main()
{
const int size=50;
int array[size];
srand(time(0));
for(int i=0;i
{
array[i]=rand()%100;
cout<
}
int max=array[0];
int min=array[0];
for(int i=0;i
{
if(min>array[i])
{
max=array[i];
}
}
cout<<"Maximum Number is :"<
cout<<"Minimum Number is:"<
return 0;
}
Maximum
or largest number in array C++ Program
#include
using namespace std;
int main()
{
cout<<"Enter The Size Of Array: ";
int size;
cin>>size;
int array[size], key,i;
for(int j=0;j
{
cout<<"Enter "<
cin>>array[j];
}
for(int a=0;a
{
cout<<"array[ "<
cout<
}
int maximum=array[0];
for(int i=0;i
{
if(array[i]>maximum)
{
maximum=array[i];
}
}
cout<<"\n\nMaximum Number is in array is :
"<
return 0;
}
No comments:
Post a Comment