forked from TheAlgorithms/C-Plus-Plus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
79 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
#include<iostream> | ||
// This function convert decimal to binary number | ||
// | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int number; | ||
cin>>number; | ||
int remainder,binary=0,var=1; | ||
|
||
do{ | ||
|
||
remainder=number%2; | ||
number=number/2; | ||
binary=binary+(remainder*var); | ||
var=var*10; | ||
cout << "Enter a number:"; | ||
cin >> number; | ||
int remainder, binary = 0, var = 1; | ||
|
||
do { | ||
remainder = number % 2; | ||
number = number / 2; | ||
binary = binary + (remainder*var); | ||
var = var * 10; | ||
|
||
} | ||
while(number>0); | ||
cout<<binary; | ||
} while (number>0); | ||
cout << "the binary is :"; | ||
cout << binary; | ||
cout << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,5 +81,5 @@ int main() | |
cout << n << " th Fibonacci is \n"; | ||
fib_Accurate(n); | ||
|
||
return 0; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,55 @@ | ||
//Bubble Sort | ||
|
||
#include<iostream> | ||
#include<vector> | ||
using namespace std; | ||
|
||
int main() | ||
{ | ||
int n; | ||
short swap_check=0; | ||
cout << "Enter the amount of numbers to sort: "; | ||
cin >> n; | ||
int Array[n]; | ||
cout<<"\nEnter any 6 Numbers for Unsorted Array : "; | ||
vector<int> numbers; | ||
cout << "Enter " << n << " numbers: "; | ||
int num; | ||
|
||
//Input | ||
//Input | ||
for(int i=0; i<n; i++) | ||
{ | ||
cin>>Array[i]; | ||
cin >> num; | ||
numbers.push_back(num); | ||
} | ||
|
||
//Bubble Sorting | ||
for(int i=0; i<n; i++) | ||
{ | ||
for(int j=0; j<n-1; j++) | ||
swap_check=0; | ||
for(int j=0; j<n-1-i; j++) | ||
{ | ||
if(Array[j]>Array[j+1]) | ||
if(numbers[j]>numbers[j+1]) | ||
{ | ||
int temp=Array[j]; | ||
Array[j]=Array[j+1]; | ||
Array[j+1]=temp; | ||
swap_check=1; | ||
swap(numbers[j], numbers[j+1]); | ||
} | ||
} | ||
if(swap_check == 0) | ||
{ | ||
break; | ||
} | ||
} | ||
|
||
//Output | ||
cout<<"\nSorted Array : "; | ||
for(int i=0; i<n; i++) | ||
for(int i=0; i<numbers.size(); i++) | ||
{ | ||
cout<<Array[i]<<"\t"; | ||
if(i != numbers.size() -1) | ||
{ | ||
cout << numbers[i] << ", "; | ||
}else | ||
{ | ||
cout << numbers[i] << endl; | ||
} | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters