0% found this document useful (0 votes)
11 views

#Include Using Namespace Void Int

The document contains code for 4 different C++ programs: 1. A program that sorts an array of integers in ascending order using bubble sort. 2. A recursive program that solves the Towers of Hanoi puzzle. 3. A recursive program that calculates Fibonacci numbers. 4. A program that prints the Fibonacci sequence.

Uploaded by

aasifaftab
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

#Include Using Namespace Void Int

The document contains code for 4 different C++ programs: 1. A program that sorts an array of integers in ascending order using bubble sort. 2. A recursive program that solves the Towers of Hanoi puzzle. 3. A recursive program that calculates Fibonacci numbers. 4. A program that prints the Fibonacci sequence.

Uploaded by

aasifaftab
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream>

using namespace std ;


void main()
{
int i, j, n, temp, arr[10];

cout<<"Enter the size of array=";

cin>>n;

cout<<"Enter the Array element =";


for(i=0; i<n; i++)
cin>>arr[i];

cout<<"Unsorted Array elements are =";


for(i=0; i<n; i++)
cout<<" "<<arr[i];

for(i = 1; i <=n; i++)


{

for (j=0; j < n-1; j++)


{
if (arr[j+1] > arr[j])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;

}}}

cout<<" \n Sorted Array elements are =";


for(i=0; i<n; i++)
cout<<" " <<arr[i];

getch();

#include<iostream>
using namespace std;

void move(int n,int A,int C,int B)


{
if(n==1)
cout<<"\t Move the upper disc from Stack-" <<A<< " to Stack-"
<<C<< "\n";

else
{
move(n-1,A,B,C);
move(1,A,C,B);
move(n-1,B,C,A);
}}
int main( )
{

cout<<"\n\t ************** TOWERS OF HANOI **************\n";


cout<<" The Mystery of Towers of Hanoi is as follows : \n";

move(3,1,3,2);

cout<<"\n\t *************************************************\n";
return 0;}

#include <iostream>
using namespace std;

int fib(int n)
{
if(1 == n || 2 == n)
{
return 1;
}
else
{
return fib(n-1) + fib(n-2);
}}
int main()
{
int k;
cout<<"enter the number of terms";
cin>>k;
for(int i=1; i<=k; i++)
{
cout << fib(i) << endl;
}
return 0;
}

#include <iostream>
using namespace std;
void main()
{
int a,b,x,y,num1,ct;
a=0;
b=1;
cout << "Enter the number of terms : " << endl;
cin>>num1;
cout << a << endl;
cout << b << endl;
for(ct=1;ct<=num1-2;ct++)
{
x=a+b;
cout << x << endl;
y=a;
a=b;
b=x;
}}

You might also like