diff --git a/C++ & C/10.cpp b/C++ & C/10.cpp index 41784dd6..25b133b4 100644 --- a/C++ & C/10.cpp +++ b/C++ & C/10.cpp @@ -1,15 +1,19 @@ -#include +#include using namespace std; -const double pi=3.14; -const char newline='\n'; -int main(){ - double r=5.0; - double circle; - circle=2*pi*r; - cout<> firstNumber >> secondNumber; + // sum of two numbers in stored in variable sumOfTwoNumbers + sumOfTwoNumbers = firstNumber + secondNumber; + // Prints sum + cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers; + return 0; } +// For Hacktoberfest2021 diff --git a/Python/Bubble_Sort.py b/Python/Bubble_Sort.py index 69d29848..1010fc19 100644 --- a/Python/Bubble_Sort.py +++ b/Python/Bubble_Sort.py @@ -1,20 +1,28 @@ # bubble sorting an array #//---create a random list---// +# Code is more optimal from previous version +# Added comment from understanding the meaning -import random as rand -a=[] -for _ in range(10): - x=rand.randint(0,100) - a.append(x) -print ("random : ",a) +def bubbleSort(arr): + n = len(arr) -#//---logic to swap pair of no.---// + # Traverse through all array elements + for i in range(n): -for j in range (len(a)): - temp=a.copy() - for i in range(len(a)-1): - if a[i]>a[i+1]: - a[i],a[i+1]=a[i+1], a[i] - if temp==a: - break -print("sorted : ",a) + # Last i elements are already in place + for j in range(0, n-i-1): + + # traverse the array from 0 to n-i-1 + # Swap if the element found is greater + # than the next element + if arr[j] > arr[j+1] : + arr[j], arr[j+1] = arr[j+1], arr[j] + +# Driver code to test above +arr = [64, 34, 25, 12, 22, 11, 90] + +bubbleSort(arr) + +print ("Sorted array is:") +for i in range(len(arr)): + print ("%d" %arr[i]), diff --git a/java/Patterns/pattern1.java b/java/Patterns/pattern1.java index 199bc9bc..df2595c1 100644 --- a/java/Patterns/pattern1.java +++ b/java/Patterns/pattern1.java @@ -3,13 +3,14 @@ public class pattern1 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); - int num = sc.nextInt(); - - for (int i = 1; i <= num; i++) { - for (int j = 1; j <= i; j++) { - System.out.print("*\t"); + System.out.print("Enter a row Number: "); + int x = sc.nextInt(); + for(int i=1;i<=x;i++){ + for(int j=1;j<=i;j++){ + System.out.print("*); } - System.out.println(); + System.out.println(); } + } }