Skip to content
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"
}
67 changes: 39 additions & 28 deletions C++ algos/Sorting Algos/InsertionSort.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
#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;
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))
48 changes: 28 additions & 20 deletions Python/Type_of_Triangle.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
# Given length of all sides of a triangle determine the type of triangle -
# equilateral, isosceles or scalene, using if-else condition.

# Input the length of 3 sides a, b, c of the triangle

a = int(input("a: "))
b = int(input("b: "))
c = int(input("c: "))

# Equilateral Triangle: all sides a, b, c are equal i.e. a=b=c
if a==b==c:
print("It is an Equilateral Triangle")

# Isosceles Triangle: any two sides are equal a=b or b=c or c=a
elif a==b or b==c or c==a:
print("It is an Isosceles Triangle")

# Scalene Triangle: if none of the sides are equal a!=b!=c
else:
print("It is a Scalene Triangle")
# Python3 program for the above approach

# Function to check if the triangle
# is equilateral or isosceles or scalene
def checkTriangle(x, y, z):

# _Check for equilateral triangle
if x == y == z:
print("Equilateral Triangle")

# Check for isosceles triangle
elif x == y or y == z or z == x:
print("Isosceles Triangle")

# Otherwise scalene triangle
else:
print("Scalene Triangle")


# Driver Code

# Given sides of triangle
x = 8
y = 7
z = 9

# Function Call
checkTriangle(x, y, z)
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")