Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Even.py #267

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\Program Files (x86)\\mingw-w64\\i686-8.1.0-posix-dwarf-rt_v6-rev0\\mingw32\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
71 changes: 43 additions & 28 deletions C++ algos/Sorting Algos/InsertionSort.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,50 @@
#include <iostream>
// C++ program for insertion sort

#include <bits/stdc++.h>
using namespace std;

// Function to print an array
void printArray(int array[], int size) {
for (int i = 0; i < size; i++) {
cout << array[i] << " ";
}
cout << endl;
}
// Function to sort an array using
// insertion sort
void insertionSort(int arr[], int n)
{
int i, key, j;
for (i = 1; i < n; i++)
{
key = arr[i];
j = i - 1;

void insertionSort(int array[], int size) {
for (int step = 1; step < size; step++) {
int key = array[step];
int j = step - 1;
// Move elements of arr[0..i-1],
// that are greater than key, to one
// position ahead of their
// current position
while (j >= 0 && arr[j] > key)
{
arr[j + 1] = arr[j];
j = j - 1;
}
arr[j + 1] = key;
}
}

// Compare key with each element on the left until a smaller element is found
// For descending order, change key < array[j] to key > array[j].
while (key < array[j] && j >= 0) {
array[j + 1] = array[j];
--j;
}
array[j + 1] = key;
}
// A utility function to print an array
// of size n
void printArray(int arr[], int n)
{
int i;
for (i = 0; i < n; i++)
cout << arr[i] << " ";
cout << endl;
}

// Driver code
int main() {
int data[] = {9, 5, 1, 4, 3};
int size = sizeof(data) / sizeof(data[0]);
insertionSort(data, size);
cout << "Sorted array in ascending order:\n";
printArray(data, size);
return 0;
}
int main()
{
int arr[] = { 12, 11, 13, 5, 6 };
int N = sizeof(arr) / sizeof(arr[0]);

insertionSort(arr, N);
printArray(arr, N);

return 0;
}
// This is code is contributed by rathbhupendra
Binary file added C++ algos/Sorting Algos/InsertionSort.exe
Binary file not shown.
36 changes: 14 additions & 22 deletions Python/Fibonacci.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
n_steps = int(input ("How many steps wants to print? "))

# First two steps
n1 = 0
n2 = 1
count = 0

# Find spets is valid or not
if n_steps <= 0:
print ("Please enter a positive integer, the given number is not valid")
# n_steps is only one
elif n_steps == 1:
print ("The Fibonacci sequence of the numbers up to", n_steps, ": ")
print(n1)
# Generate Fibonacci sequence of number

def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
# take input from the user
nterms = int(input("How many terms? "))
# check if the number of terms is valid
if nterms <= 0:
print("Plese enter a positive integer")
else:
print ("The fibonacci sequence of the numbers is:")
while count < n_steps:
print(n1)
nth = n1 + n2
n1 = n2
n2 = nth
count += 1
print("Fibonacci sequence:")
for i in range(nterms):
print(recur_fibo(i))
9 changes: 4 additions & 5 deletions Python/check_even_number.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Check if number that user type is even or odd number
user_input = input("Enter Your Number: ")
num = int(user_input)
if (num % 2) == 0:
print(str(num) + " is EVEN NUMBER.")
x=int(input())
if(x%2==0):
print("its an even number")
else:
print(str(num) + " is ODD NUMBER.")
print("its an odd number")