├── area.exe ├── menu.exe ├── sizeof.exe ├── function1.exe ├── sam ├── Random ├── Main.class ├── Random.class ├── Main.java └── Random.java ├── Complex ├── complex.class └── complex.java ├── Linked_List ├── Node.class ├── llist.class └── llist.java ├── Interest Calculator.jar ├── Square_Wave ├── square.class └── square.java ├── Image Resizer ├── resize.class └── resize.java ├── Snake_Water_Gun ├── Snake_Water_gun.exe └── Snake_Water_gun.c ├── hactoberfestfirstpr ├── PythonPattern ├── Hactoberfestpr1 ├── Hello_ World.cpp ├── Digit_Counter.py ├── sum ├── Samiksha ├── float ├── Reversing Number ├── Hactober 2022 c++ ├── Creating a Do while Loop ├── Python code ├── Hactoberfestpr5 ├── loops ├── Hactoberfestpr3 ├── Multiplication ├── Neon Number ├── 4.cpp ├── 5.cpp ├── Half Pyramid of Numbers.c ├── swap.java ├── 2.cpp ├── Hactoberfestpr4 ├── new code ├── Check for Armstrong Number ├── first.cpp ├── Temperature conversion.py ├── digits.c ├── sumOf_n_NaturalNumbersAndReversePR.c ├── Bubble Sorting ├── arithmetic.c ├── logical.c ├── Sub ├── Reverse_Number.cpp ├── sizeof.c ├── Fibonacci Number ├── CoprimeOrNot ├── fibonacciRec.c ├── Fibonnaci.py ├── pyramid.cpp ├── Palindrome Number.c ├── cpp.cpp ├── Hacktoberfest.cpp ├── README.md ├── Hacktoberfest 1st PR ├── DecimalToBinaryPR.java ├── age.c ├── ifelse.c ├── reversing_string.cpp ├── Hollow_Diamond_Pattern.py ├── Hacktoberfest 2nd PR ├── Krishnamurthy Number.c ├── Program to convert temperature from Celsius to Fahrenheit.c ├── Prime and Composite.cpp ├── ArmstrongNumber ├── Hacktoberfest 3rd PR ├── hacktoberfest1pr.cpp ├── Turtle Python 2 code.py ├── Stack code 1.py ├── password_generator.py ├── max_among_3_number.cpp ├── leap_year.cpp ├── sort.c ├── prime.java ├── buublesort.c ├── palindrome.java ├── leader.java ├── function1.c ├── area.c ├── play.c ├── TowerOfHanoiPR.java ├── ReversingAnArray ├── Hacktoberfest'22_PR5 ├── max_difference.java ├── checkSort.java ├── primeplay.py ├── Turtle python code PR1.py ├── MaxAndMin ├── Hacktoberfest'22_PR4 ├── LeftRotateByD.java ├── mergearray.java pr2 ├── rearrange_array ├── calculator.cpp ├── rock_paper_scissor.py ├── Searching_Element.py ├── DeletingElement.java ├── Consecutive XOR.java.txt ├── calculator.c ├── HcfLcm.java ├── Leetcode ├── 695. Max Area of Island.java ├── 37. Sudoku Solver │ └── Solution.java └── 300. LIS │ └── LongestIncreasingSubsequence.java ├── InsertElement.java ├── menu.c ├── gmt.java ├── Number of days finder 1st PR ├── uniquenumber.java ├── LL.java ├── Turtle Python code PR2.py ├── Evaluate POSTFIX Expression Using Stack.c ├── random_password_creator.py ├── guessthenum.py ├── Hacktoberfest'22_PR2 ├── Matrix Addition.cpp ├── Knapsack problem.c ├── Hacktoberfest 4th PR ├── Hacktoberfest'22_PR1 ├── goldbach.java ├── Python turtle code 3.py ├── Hacktoberfest'22_PR3 ├── pangram.java pr1 ├── infixtopostfix.cpp ├── number_guessing_game.py ├── MatrixReversal.java ├── mandelbrot.java ├── matrix.java ├── calculator.py ├── alarm.py ├── ping pong game.py ├── Number_guessing_game.cpp ├── infixtoprefix.cpp └── Hacktoberfest'22_PR6 /area.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/area.exe -------------------------------------------------------------------------------- /menu.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/menu.exe -------------------------------------------------------------------------------- /sizeof.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/sizeof.exe -------------------------------------------------------------------------------- /function1.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/function1.exe -------------------------------------------------------------------------------- /sam: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | printf("Hello World"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /Random/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Random/Main.class -------------------------------------------------------------------------------- /Random/Random.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Random/Random.class -------------------------------------------------------------------------------- /Complex/complex.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Complex/complex.class -------------------------------------------------------------------------------- /Linked_List/Node.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Linked_List/Node.class -------------------------------------------------------------------------------- /Interest Calculator.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Interest Calculator.jar -------------------------------------------------------------------------------- /Linked_List/llist.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Linked_List/llist.class -------------------------------------------------------------------------------- /Square_Wave/square.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Square_Wave/square.class -------------------------------------------------------------------------------- /Image Resizer/resize.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Image Resizer/resize.class -------------------------------------------------------------------------------- /Snake_Water_Gun/Snake_Water_gun.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Cybernix-Phoenix-NSEC/octo-fiesta/HEAD/Snake_Water_Gun/Snake_Water_gun.exe -------------------------------------------------------------------------------- /hactoberfestfirstpr: -------------------------------------------------------------------------------- 1 | class Test{ 2 | public static void main(String args[]) 3 | { 4 | System.out.println("Happy hacking.."); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /PythonPattern: -------------------------------------------------------------------------------- 1 | n=int(input("Enter number of lines")) 2 | for i in range(1,n+1,1): 3 | for j in range (1,i+1,1): 4 | print("*",end="") 5 | print("\n") 6 | -------------------------------------------------------------------------------- /Hactoberfestpr1: -------------------------------------------------------------------------------- 1 | class Fest{ 2 | public static void main(String args[]){ 3 | System.out.println("I am really happy to participate in Hactoberfest2022"); 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /Hello_ World.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | // printf() displays the string inside quotation 4 | printf("Hello, World!"); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /Digit_Counter.py: -------------------------------------------------------------------------------- 1 | num=int(input("Enter a number: ")) 2 | c = 0 3 | 4 | while num != 0: 5 | num //= 10 6 | c += 1 7 | 8 | print("Number of digits: " + str(c)) 9 | -------------------------------------------------------------------------------- /sum: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a, b, sum; 5 | printf("enter any two numbers\n"); 6 | scanf("%d%d",&a,&b); 7 | sum=a+b; 8 | printf("sum=%d\n",sum); 9 | } 10 | -------------------------------------------------------------------------------- /Samiksha: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a, b, sum; 5 | printf("enter any two numbers\n"); 6 | scanf("%d%d",&a,&b); 7 | sum=a+b; 8 | printf("sum=%d\n",sum); 9 | } 10 | -------------------------------------------------------------------------------- /float: -------------------------------------------------------------------------------- 1 | #include 2 | #define PI 3.14 3 | int main() 4 | { 5 | int a = 8; 6 | const float b = 7.333; 7 | printf("%d", PI); 8 | 9 | 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Reversing Number: -------------------------------------------------------------------------------- 1 | i=int(input("Enter the number you want to reverse: ")) 2 | rev=0 3 | while i>0: 4 | rev=rev*10+i%10 5 | i=i//10 6 | print("Reverse of the given number is: ",rev) 7 | 8 | 9 | -------------------------------------------------------------------------------- /Hactober 2022 c++: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int sum=0; 6 | for(int current=1;current<=7;current=current+1){ 7 | sum=sum+current; 8 | } 9 | return0; 10 | } 11 | -------------------------------------------------------------------------------- /Creating a Do while Loop: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main () { 5 | int initial=1; 6 | do{ 7 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | 6 | int n; 7 | cin>>n; 8 | 9 | while(n>0){ 10 | cout<>n; 12 | } 13 | 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Hactoberfestpr3: -------------------------------------------------------------------------------- 1 | class Fest3{ 2 | public static void main(String args[]){ 3 | int n = 5; 4 | System.out.println("The multiplication table of the given numer is :"); 5 | for(int i = 1; i<=10;i++){ 6 | System.out.println( n*i); 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Multiplication: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a, b, mul; 5 | printf("enter the value of two numbers"); 6 | scanf("%d %d",&a, &b); 7 | mul=a*b; 8 | printf("multiplication = %d",mul); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Neon Number: -------------------------------------------------------------------------------- 1 | x=int(input("Enter a number to check it is a neon number or not")) 2 | t=x*x 3 | s=0 4 | while t!=0: 5 | d=t%10 6 | t=t//10 7 | s=s+d 8 | if s%x==0: 9 | print("It is a neon number") 10 | else : 11 | print("It is not a neon number") 12 | -------------------------------------------------------------------------------- /4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | for(int i=0;i<=3;i++){ 6 | if(i%5==0){ 7 | cout<<"%"< 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | for(int i=n;i>=1;i--){ 7 | for(int j=1;j<=i;j++){ 8 | cout<<"*"; 9 | } 10 | cout< 2 | int main(){ 3 | int i,j,rows; 4 | printf("Enter the number of rows: "); 5 | scanf("%d",&rows); 6 | for(i=1;i<=rows;i++){ 7 | for(j=1;j<=i;j++){ 8 | printf("%d ",j); 9 | } 10 | printf("\n"); 11 | } 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /swap.java: -------------------------------------------------------------------------------- 1 | public class swap{ 2 | public static void main(String[] args){ 3 | int a=5; 4 | int b=7; 5 | int c=a; 6 | a=b; 7 | b=c; 8 | System.out.println("Swapped numbers are: "); 9 | System.out.println("a="+a+" and b="+b); 10 | } 11 | } -------------------------------------------------------------------------------- /2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | int i; 7 | 8 | for(int i=2;i 2 | 3 | int main() 4 | { 5 | /* code */ 6 | int a, b; 7 | a = 2; 8 | b = 3; 9 | 10 | printf("a + b = %d", a&b); 11 | printf("a * b = %d", a*b); 12 | printf("a / b = %d", a/b); 13 | printf("a - b = %d", a-b); 14 | 15 | 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Check for Armstrong Number: -------------------------------------------------------------------------------- 1 | num = int(input("Enter a number to check: ")) 2 | sum = 0 3 | y = num 4 | 5 | while y > 0: 6 | digit = y % 10 7 | sum += digit ** 3 8 | y //= 10 9 | 10 | if num == sum: 11 | print(num,"is an Armstrong number.") 12 | else: 13 | print(num,"is not an Armstrong number.") 14 | -------------------------------------------------------------------------------- /first.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | int i; 7 | 8 | for(int i=2;i 2 | int main() 3 | { 4 | int n, d, c = 0; 5 | printf("Enter a number: "); 6 | scanf("%d", &n); 7 | while (n != 0) 8 | { 9 | d = n % 10; 10 | c++; 11 | n /= 10; 12 | } 13 | printf("The number of digits = %d", c); 14 | 15 | return 0; 16 | } -------------------------------------------------------------------------------- /sumOf_n_NaturalNumbersAndReversePR.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("Enter the value of n : "); 5 | int n,sum=0; 6 | scanf("%d",&n); 7 | for(int i=1,j=n; i<=n,j>=1;i++,j--){ 8 | sum+=i; 9 | printf("%d ",j); 10 | } 11 | printf("\nSum is %d",sum); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /Bubble Sorting: -------------------------------------------------------------------------------- 1 | L=[] 2 | n=int(input("How many numbers you want to input in the array")) 3 | for i in range(0,n): 4 | x=int(input("Enter the numbers")) 5 | L.append(x) 6 | for i in range(0,n): 7 | for j in range(0,n-1): 8 | if L[j]>L[j+1]: 9 | L[j],L[j+1]=L[j+1],L[j] 10 | print("The array after sorting in ascending order is:",L) 11 | -------------------------------------------------------------------------------- /arithmetic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int x; 6 | x=34.0/6.0; 7 | printf("%d",x); 8 | } 9 | // in c integer divided by integer gives integer value 10 | // to get real value either one or both value should be real 11 | // 3/4 0 12 | // 3.0/4 0.75 13 | // 3/4.0 0.75 14 | // 3.0/4.0 0.75 -------------------------------------------------------------------------------- /logical.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int y,x=6; //NOT ! Highest priority unary operator 6 | y= x>3||x<4; // AND && binary operator 7 | printf("%d",y); // OR || Lowest priority binary operator 8 | return 0;} -------------------------------------------------------------------------------- /Sub: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num1, num2, difference; 5 | 6 | //Asking for input 7 | printf("Enter first number: "); 8 | scanf("%d", &num1); 9 | printf("Enter second number: "); 10 | scanf("%d", &num2); 11 | 12 | difference = num1 - num2; 13 | printf("Difference of %d and %d is: %d", num1, num2, difference); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /Reverse_Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n, reverse = 0, remainder; 6 | 7 | printf("Enter an integer: "); 8 | scanf("%d", &n); 9 | 10 | while (n != 0) { 11 | remainder = n % 10; 12 | reverse = reverse * 10 + remainder; 13 | n /= 10; 14 | } 15 | 16 | printf("Reversed number = %d", reverse); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /sizeof.c: -------------------------------------------------------------------------------- 1 | // sizeof() tells the size of data type,variable or constant in bits 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int x,y,z; 8 | x=sizeof(34); 9 | y=sizeof(4.35); // real constant = double data type 10 | z=sizeof('a'); // ASCII a = 97 each character has a value from 0 to 255 11 | printf("%d %d %d",x,y,z); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /Fibonacci Number: -------------------------------------------------------------------------------- 1 | n=int(input("Enter a number to check it is from fibonacci series or not")) 2 | a,b=0,1 3 | ans="No" 4 | for i in range(1,n+1): 5 | if i==1: 6 | print a 7 | if a==n: 8 | ans="Yes" 9 | elif i==2: 10 | print b 11 | if b==n: 12 | ans="Yes" 13 | else: 14 | c=a+b 15 | print c 16 | if c==n: 17 | ans="Yes" 18 | a=b 19 | b=c 20 | print ans 21 | -------------------------------------------------------------------------------- /CoprimeOrNot: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n; 7 | cin >> n; 8 | 9 | int i = 2; 10 | 11 | while(i 2 | 3 | int fibo(int n); 4 | int main() { 5 | printf("Enter the number : "); 6 | int n; 7 | scanf("%d",&n); 8 | printf("%d",fibo(n)); 9 | return 0; 10 | } 11 | int fibo(int n) { 12 | if(n == 1) 13 | return 0; 14 | else if(n == 2) 15 | return 1; 16 | else{ 17 | return fibo(n-2)+fibo(n-1); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Fibonnaci.py: -------------------------------------------------------------------------------- 1 | def recur_fibo(n): 2 | if n <= 1: 3 | return n 4 | else: 5 | return(recur_fibo(n-1) + recur_fibo(n-2)) 6 | 7 | nterms = 10 8 | 9 | # check if the number of terms is valid 10 | if nterms <= 0: 11 | print("Plese enter a positive integer") 12 | else: 13 | print("Fibonacci sequence:") 14 | for i in range(nterms): 15 | print(recur_fibo(i)) -------------------------------------------------------------------------------- /pyramid.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int rows; 7 | 8 | cout << "Enter number of rows: "; 9 | cin >> rows; 10 | 11 | for(int i = 1; i <= rows; ++i) 12 | { 13 | for(int j = 1; j <= i; ++j) 14 | { 15 | cout << "* "; 16 | } 17 | cout << "\n"; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Palindrome Number.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int num,rem,sum=0,temp; 4 | printf("Enter a number:"); 5 | scanf("%d",&num); 6 | temp=num; 7 | while(num>0){ 8 | rem=num%10; 9 | sum=(sum*10)+rem; 10 | num=num/10; 11 | } 12 | if(temp==sum){ 13 | printf("%d is a palindrome number.",temp); 14 | }else{ 15 | printf("%d is not a palindrome number.",temp); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /cpp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Driver code 5 | int main() 6 | { 7 | int a; 8 | int b; 9 | cin>>a>>b; 10 | 11 | cout<< "Before swaping a = "<>m; 17 | int a; 18 | cin>>a; 19 | int b; 20 | cin>>b; 21 | int arr[m] = {a,b}; 22 | 23 | printArray(arr, m); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # octo-fiesta 2 | 3 | ## Git and Github session 2022 4 | - This is a repo created to welcome all budding coders and enthusiats to contribute to open source development.🌱 5 | - Submit any code in any coding language.✨ 6 | - Happy coding!!😄 7 | 8 |

9 | 10 |

11 | -------------------------------------------------------------------------------- /Hacktoberfest 1st PR: -------------------------------------------------------------------------------- 1 | sum=count=0 2 | for i in range(5): 3 | print("Enter",i+1,"of 5 numbers:") 4 | number=int(input()) 5 | lowestdigit=number%10 6 | t=number 7 | while t!=0: 8 | d=t%10 9 | t=t//10 10 | if d==lowestdigit: 11 | flag=1 12 | print('sorry') 13 | break 14 | if sum==0: 15 | print('No Such Entry') 16 | else: 17 | print('Sum:',sum,'Average:',sum/count) 18 | -------------------------------------------------------------------------------- /DecimalToBinaryPR.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class DecimalToBinaryPR { 3 | static int convert(int n) { 4 | if(n == 0) 5 | return 0; 6 | else 7 | return convert(n/2)*10+ n%2; 8 | } 9 | public static void main(String args[]) 10 | { 11 | Scanner in = new Scanner(System.in); 12 | System.out.print("Enter The Decimal number : ); 13 | int n = in.nextInt(); 14 | System.out.println(convert(n)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /age.c: -------------------------------------------------------------------------------- 1 | // Write a program in C to display the category of a citizen based on his/her age 2 | 3 | #include 4 | int main() 5 | { 6 | int age; 7 | printf("Enter the age: "); 8 | scanf("%d", &age); 9 | printf("\nCategory: "); 10 | if (age < 18) 11 | printf("Minor"); 12 | else if (age >= 18 && age < 60) 13 | printf("Adult"); 14 | else 15 | printf("Senior"); 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /ifelse.c: -------------------------------------------------------------------------------- 1 | // Program to check wether a number is positive or not 2 | #include 3 | 4 | int main() 5 | { 6 | int x; 7 | printf("Enter the number= "); 8 | scanf("%d",&x); 9 | if(x>0) 10 | { 11 | printf("positive"); 12 | } 13 | 14 | else 15 | { 16 | printf("non-positive"); 17 | } 18 | 19 | getch(); 20 | } -------------------------------------------------------------------------------- /reversing_string.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | void reverseStr(string& str) 6 | { 7 | int n = str.length(); 8 | 9 | 10 | for (int i = 0; i < n / 2; i++) 11 | swap(str[i], str[n - i - 1]); 12 | } 13 | 14 | 15 | int main() 16 | { 17 | string str; 18 | cout<<"enter the string:"; 19 | cin>>str; 20 | reverseStr(str); 21 | cout << str; 22 | return 0; 23 | } -------------------------------------------------------------------------------- /Hollow_Diamond_Pattern.py: -------------------------------------------------------------------------------- 1 | n=int(input("Enter the ODD numbers of layers : ")) 2 | m=(n+1)//2 3 | for i in range(1, n + 1): 4 | if i==1 or i==n: 5 | print(" " * (m-1) + "*") 6 | elif (i<=m): 7 | o = (m-i) 8 | i = (2*(i - 1) - 1) 9 | print (" " * o + "*" + " " * i + "*") 10 | else: 11 | o = (i - m) 12 | i = (2*(n-i)-1) 13 | print (" " * o + "*" + " " * i + "*") 14 | print ("End of the pattern...") 15 | -------------------------------------------------------------------------------- /Hacktoberfest 2nd PR: -------------------------------------------------------------------------------- 1 | list=[] 2 | range=int(input('Enter Range:')) 3 | for i in range: 4 | num=int(input('Enter Number:')) 5 | list.append(num) 6 | print(list) 7 | list2=[] 8 | for i in list: 9 | bk=i 10 | digitcount=0 11 | while bk!=0: 12 | bk//=10 13 | digitcount+=1 14 | square=i*i 15 | lp=sq%(10**digitcount) 16 | if lp==i: 17 | list2.append(i) 18 | max=max(list2) 19 | print('Maximum Automorphic Number:',max) 20 | -------------------------------------------------------------------------------- /Krishnamurthy Number.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int num,i,rem,temp,fact,sum=0; 4 | printf("Enter a number: "); 5 | scanf("%d",&num); 6 | for(temp=num;temp>0;temp/=10){ 7 | fact=1; 8 | rem=temp%10; 9 | for(i=1;i<=rem;i++){ 10 | fact=fact*i; 11 | } 12 | sum=sum+fact; 13 | } 14 | if(num==sum){ 15 | printf("%d is a krishnamurthy number.",num); 16 | }else{ 17 | printf("%d is not a krishnamurthy number.",num); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Program to convert temperature from Celsius to Fahrenheit.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | float celsius, fahrenheit; 6 | 7 | /* Input temperature in celsius */ 8 | printf("Enter temperature in Celsius: "); 9 | scanf("%f", &celsius); 10 | 11 | /* celsius to fahrenheit conversion formula */ 12 | fahrenheit = (celsius * 9 / 5) + 32; 13 | 14 | printf("%.2f Celsius = %.2f Fahrenheit", celsius, fahrenheit); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Prime and Composite.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | 5 | int n, i, flag = 0; 6 | printf("Enter a positive integer: "); 7 | scanf("%d", &n); 8 | 9 | if (n == 0 || n == 1) 10 | flag = 1; 11 | 12 | for (i = 2; i <= n / 2; ++i) { 13 | if (n % i == 0) { 14 | flag = 1; 15 | break; 16 | } 17 | } 18 | if (flag == 0) 19 | printf("%d is a prime number.", n); 20 | else 21 | printf("%d is composite number.", n); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /ArmstrongNumber: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int num,originalNum,remainder,result=0; 4 | printf("Enter a three-digit integer: "); 5 | scanf("%d",&num); 6 | originalNum=num; 7 | while(originalNum!=0){ 8 | remainder=originalNum % 10; 9 | result+= remainder * remainder * remainder; 10 | originalNum/=10; 11 | } 12 | if(result==num){ 13 | printf("%d is an Armstrong number.",num); 14 | }else{ 15 | printf("%d is not an Armstrong number.",num); 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /Hacktoberfest 3rd PR: -------------------------------------------------------------------------------- 1 | def prime(num): 2 | for d in range(2,num): 3 | if num%d==0: 4 | return False 5 | return True 6 | def reverse(num): 7 | r=0 8 | while num!=0: 9 | d=num%10 10 | r=r*10+d 11 | num=num//10 12 | return r 13 | def palprime(): 14 | x=int(input('Enter No:')) 15 | if prime(x)==True and x==reverse(x): 16 | print('The number is a Palindrome Prime') 17 | else: 18 | print('Not a Palindrome Prime') 19 | palprime() 20 | -------------------------------------------------------------------------------- /hacktoberfest1pr.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | const char alphanum[] = "0123456789!@#$%^&*abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 6 | int string_length = sizeof(alphanum)-1; 7 | int main() 8 | { 9 | int n; 10 | cout<<"Enter the length of password:"; 11 | cin>>n; 12 | srand(time(0)); 13 | cout<<"Generated password:"; 14 | for(int i = 0; i < n; i++) 15 | cout << alphanum[rand() % string_length]; 16 | return 0; 17 | } -------------------------------------------------------------------------------- /Turtle Python 2 code.py: -------------------------------------------------------------------------------- 1 | import turtle as t 2 | 3 | t.bgcolor("black") 4 | t.speed(0) 5 | t.pensize(2) 6 | 7 | colors = ['red', 'orange', 'green', 'indigo', 'blue', 'yellow'] 8 | 9 | a=0 10 | 11 | for i in range(36): 12 | t.color(colors[i%6]) 13 | for i in range(6): 14 | t.circle(10,90) 15 | t.left(180) 16 | t.circle(10,-90) 17 | t.left(180) 18 | t.penup() 19 | t.setpos(0,0) 20 | t.pendown() 21 | a+=10 22 | t.seth(a) 23 | t.done() 24 | 25 | #multicoloured central pattern created 26 | -------------------------------------------------------------------------------- /Stack code 1.py: -------------------------------------------------------------------------------- 1 | #to push all the numbers divisible by 5 from a list and then pop them out and display the numbers 2 | 3 | 4 | L=[10,19,36,55,20,73,92,45,105,33] 5 | def push(s,n): 6 | s.append(n) 7 | def pop(s): 8 | if s==[]: 9 | print("underflow...") 10 | else: 11 | p=s.pop() 12 | return p 13 | 14 | sm=[] 15 | for x in L: 16 | if x%5==0: 17 | push(sm,x) 18 | for f in range(len(sm)-1,-1,-1): 19 | print (sm[f]) 20 | for i in range(len(sm)): 21 | print(pop(sm),end=" ") 22 | 23 | 24 | -------------------------------------------------------------------------------- /password_generator.py: -------------------------------------------------------------------------------- 1 | from random_password_creator import Password 2 | import argparse 3 | 4 | args = argparse.ArgumentParser("Usage: python password_generator.py -c CHARSET -l LENGTH") 5 | args.add_argument('charset') 6 | args.add_argument('-l','--length',default=8) 7 | options = args.parse_args() 8 | print(options.charset) 9 | print(options.length) 10 | 11 | password = Password(options.charset,int(options.length)) 12 | password.set_the_charset() 13 | password.generate_password() 14 | print("The random password is:",password.get_password()) -------------------------------------------------------------------------------- /Random/Main.java: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | *The driver Code 4 | */ 5 | 6 | import java.util.*; 7 | 8 | class Main 9 | { 10 | public static void main(String args[]) 11 | { 12 | Scanner sc=new Scanner(System.in); 13 | int x=1; 14 | 15 | while(x==1) 16 | { 17 | int n=10000; 18 | 19 | Random rn=new Random(45.3440015669); 20 | 21 | 22 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main(){ 5 | int a,b,c; 6 | cin>>a>>b>>c; 7 | if(a>b){ 8 | if(a>c){ 9 | cout<c){ 15 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int year; 6 | cout << "Enter a year: "; 7 | cin >> year; 8 | 9 | 10 | if (year % 400 == 0) { 11 | cout << year << " is a leap year."; 12 | } 13 | 14 | else if (year % 100 == 0) { 15 | cout << year << " is not a leap year."; 16 | } 17 | 18 | else if (year % 4 == 0) { 19 | cout << year << " is a leap year."; 20 | } 21 | 22 | else { 23 | cout << year << " is not a leap year."; 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a[20],i,j,num,temp; 5 | printf("enter the size of array:"); 6 | scanf("%d",&num); 7 | for(i=0;ia[j+1]) 16 | { 17 | temp=a[j]; 18 | a[j]=a[j+1]; 19 | a[j+1]=temp; 20 | } 21 | } 22 | } 23 | printf("\n sorted array:"); 24 | for(i=0;i 2 | 3 | void main() 4 | { 5 | int a[10],i,j,temp; 6 | printf("enter array elements\n"); 7 | for(i=0;i<10;i++) 8 | { 9 | scanf("%d",&a[i]); 10 | } 11 | for(i=0;i<9;i++) 12 | { 13 | for(j=0;j<9;j++) 14 | { 15 | if(a[j]=0;i--){ 15 | if(arr[i]>arr[g]) { 16 | g = i; 17 | System.out.print(arr[g]+ " "); 18 | } 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /function1.c: -------------------------------------------------------------------------------- 1 | // TAKES NOTHING RETURNS NOTHING 2 | 3 | #include 4 | #include // console input output 5 | 6 | void main() 7 | { 8 | void add(void); // FUNCTION DECLARATION 9 | add(); // FUNCTION CALL 10 | getch(); 11 | } 12 | 13 | void add() // FUNCTION DEFINITION 14 | { 15 | int a,b,c; 16 | printf("Enter two numbers "); 17 | scanf("%d%d",&a,&b); 18 | c=a+b; 19 | printf("Sum is %d",c); 20 | 21 | } 22 | // Declaration statement execution k time nahi, chalte compilation k time kaam k hote hai 23 | 24 | 25 | -------------------------------------------------------------------------------- /area.c: -------------------------------------------------------------------------------- 1 | // Takes something returns nothing 2 | #include 3 | #include 4 | void main() 5 | { 6 | int x,y; 7 | void mul(int,int); // in declaration statement return(data type) type is written first 8 | printf("Enter length and breadth "); 9 | scanf("%d%d",&x,&y); 10 | mul(x,y); // x and y values passes in mul function which gets copied in a and b also called call by value 11 | // and actual arguments 12 | getch(); 13 | 14 | } 15 | void mul(int a,int b) // in function definition each variable has to be declared separately formal arguments 16 | { 17 | int c; 18 | c=a*b; 19 | printf("Area = %d ",c); 20 | } -------------------------------------------------------------------------------- /play.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(){ 6 | int number, guess, nguesses=1; 7 | srand(time(0)); 8 | number = rand()%100 + 1; 9 | do{ 10 | printf("Guess the number between 1 to 100\n"); 11 | scanf("%d", &guess); 12 | if(guess>number){ 13 | printf("Lower number please!\n"); 14 | } 15 | else if(guess 2 | using namespace std; 3 | void reverse(int arr[], int n){ 4 | int start = 0; 5 | int end = n-1; 6 | 7 | while(start<=end){ 8 | swap(arr[start], arr[end]); 9 | start++; 10 | end--; 11 | } 12 | } 13 | 14 | void printArray(int arr[], int n){ 15 | 16 | for(int initial=0; initial 2 | 3 | void towers(int, char, char, char); 4 | 5 | int main() 6 | { 7 | int num; 8 | 9 | printf("Enter the number of disks : "); 10 | scanf("%d", &num); 11 | printf("The sequence of moves involved in the Tower of Hanoi are :\n"); 12 | towers(num, 'A', 'C', 'B'); 13 | return 0; 14 | } 15 | void towers(int num, char frompeg, char topeg, char auxpeg) 16 | { 17 | if (num == 1) 18 | { 19 | printf("\n Move disk 1 from peg %c to peg %c", frompeg, topeg); 20 | return; 21 | } 22 | towers(num - 1, frompeg, auxpeg, topeg); 23 | printf("\n Move disk %d from peg %c to peg %c", num, frompeg, topeg); 24 | towers(num - 1, auxpeg, topeg, frompeg); 25 | } 26 | -------------------------------------------------------------------------------- /max_difference.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class max_difference { 3 | public static void main(String[] args) { 4 | Scanner sc=new Scanner(System.in); 5 | System.out.println("Enter Size Of Array"); 6 | int n=sc.nextInt(); 7 | int arr[]=new int[n]; 8 | System.out.println("Enter The Elements of Array"); 9 | for(int i=0;iarr[i+1]) 17 | { 18 | b=false; 19 | break; 20 | } 21 | b=true; 22 | } 23 | 24 | System.out.println("The Array Is sorted= "+b); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /primeplay.py: -------------------------------------------------------------------------------- 1 | import random 2 | from math import sqrt 3 | 4 | def primecheck(n): 5 | if n<1: 6 | return False 7 | check=True 8 | for i in range(2,int(sqrt(n))+1): 9 | if n%i==0: 10 | check=False 11 | break 12 | return check 13 | 14 | score=0 15 | greets=["GG!","Good Going!","Superb!","Is that all?"] 16 | life=3 17 | print("Try to enter as many prime numbers as many possible, else you loose.. Good Luck :)") 18 | while life: 19 | a=int(input("Enter a integer: ")) 20 | if primecheck(a): 21 | score+=1 22 | print(greets[random.randint(0,len(greets))]) 23 | else: 24 | life-=1 25 | print("Oops! Remaining life :", life) 26 | 27 | print("Well played! You score was :",score) -------------------------------------------------------------------------------- /Turtle python code PR1.py: -------------------------------------------------------------------------------- 1 | #Deadshot Quintus 2 | import turtle 3 | col=('lime' , 'red' , 'yellow' , 'blue' , 'magenta' , 'orange') 4 | t=turtle.Turtle() 5 | screen=turtle.Screen() 6 | screen.bgcolor('black') 7 | t.speed(40) 8 | for i in range(300): 9 | t.color(col[i%6]) 10 | t.forward(i*1.5) 11 | t.left(59) 12 | t.width(3) 13 | if i<26: 14 | if i%3==0: 15 | screen.bgcolor('white') 16 | else: 17 | screen.bgcolor('black') 18 | elif i>=26 and i<74: 19 | if i%2 ==0: 20 | screen.bgcolor('white') 21 | else: 22 | screen.bgcolor('black') 23 | else: 24 | if i%3==0: 25 | screen.bgcolor('white') 26 | else: 27 | screen.bgcolor('black') 28 | 29 | #spiral created 30 | -------------------------------------------------------------------------------- /MaxAndMin: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int getMax(int num[], int n){ 4 | 5 | int max = INT_MIN; 6 | for(int i = 0; i max ){ 8 | max = num[i]; 9 | } 10 | } 11 | return max; 12 | } 13 | 14 | int getMin(int num[], int n){ 15 | 16 | int min = INT_MAX; 17 | for(int i = 0; i> size; 29 | 30 | int num[100]; 31 | 32 | //taking input in array 33 | 34 | for(int i = 0; i> num[i]; 36 | } 37 | cout << "Maximum value is: " << getMax(num, size) << endl; 38 | cout << "Minimum value is: " << getMin(num, size) << endl; 39 | } 40 | -------------------------------------------------------------------------------- /Hacktoberfest'22_PR4: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n, i, j, temp; 5 | int arr[10]; 6 | 7 | printf("How many elements do you wish to enter?\n"); 8 | scanf("%d", &n); 9 | 10 | printf("\nWhat are your %d elements of choice?\n", n); 11 | for (i = 0; i < n; i++) 12 | { 13 | scanf("%d", &arr[i]); 14 | } 15 | for (i = 1 ; i <= n - 1; i++) 16 | { 17 | j = i; 18 | while ( j > 0 && arr[j-1] > arr[j]) 19 | { 20 | temp = arr[j]; 21 | arr[j] = arr[j-1]; 22 | arr[j-1] = temp; 23 | j--; 24 | } 25 | } 26 | printf("\nThe list after insertion sorting: \n"); 27 | for (i = 0; i <= n - 1; i++) 28 | { 29 | printf("%d\n", arr[i]); 30 | } 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /LeftRotateByD.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class LeftRotateByD { 3 | public static void main(String[] args) { 4 | Scanner sc=new Scanner(System.in); 5 | System.out.println("Enter Size Of Array"); 6 | int n=sc.nextInt(); 7 | int arr[]=new int[n]; 8 | System.out.println("Enter Array Element"); 9 | for(int i=0;i 3 | using namespace std; 4 | 5 | void rearrange(int arr[], int n) 6 | { 7 | 8 | int max_idx = n - 1, min_idx = 0; 9 | 10 | int max_elem = arr[n - 1] + 1; 11 | 12 | for (int i = 0; i < n; i++) { 13 | if (i % 2 == 0) { 14 | arr[i] += (arr[max_idx] % max_elem) * max_elem; 15 | max_idx--; 16 | } 17 | 18 | else { 19 | arr[i] += (arr[min_idx] % max_elem) * max_elem; 20 | min_idx++; 21 | } 22 | } 23 | 24 | for (int i = 0; i < n; i++) 25 | arr[i] = arr[i] / max_elem; 26 | } 27 | 28 | int main() 29 | { 30 | int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; 31 | int n = sizeof(arr) / sizeof(arr[0]); 32 | 33 | cout << "Original Arrayn"; 34 | for (int i = 0; i < n; i++) 35 | cout << arr[i] << " "; 36 | 37 | rearrange(arr, n); 38 | 39 | cout << "\nModified Array\n"; 40 | for (int i = 0; i < n; i++) 41 | cout << arr[i] << " "; 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /calculator.cpp: -------------------------------------------------------------------------------- 1 | # include 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | char a; 7 | float num1, num2; 8 | 9 | 10 | cout << "Enter two numbers: "; 11 | cin >> num1 >> num2; 12 | 13 | cout << "Enter operator: +, -, *, /: "; 14 | cin >> a; 15 | 16 | 17 | switch(op) { 18 | 19 | case '+': 20 | cout << num1 << " + " << num2 << " = " << num1 + num2; 21 | break; 22 | 23 | case '-': 24 | cout << num1 << " - " << num2 << " = " << num1 - num2; 25 | break; 26 | 27 | case '*': 28 | cout << num1 << " * " << num2 << " = " << num1 * num2; 29 | break; 30 | 31 | case '/': 32 | cout << num1 << " / " << num2 << " = " << num1 / num2; 33 | break; 34 | 35 | default: 36 | // If the operator is other than +, -, * or /, error message is shown 37 | cout << "Error! operator is not correct"; 38 | break; 39 | } 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /rock_paper_scissor.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | 4 | def main(): 5 | while True: 6 | print("\nEnter 'r' for rock, 'p' for paper, or 's' for scissors.") 7 | player = input("Enter your choice: ") 8 | computer = random.choice(['r', 'p', 's']) 9 | if player == computer: 10 | print("It's a tie!") 11 | elif player == 'r' and computer == 's': 12 | print("You win!") 13 | elif player == 'r' and computer == 'p': 14 | print("You lose!") 15 | elif player == 'p' and computer == 'r': 16 | print("You win!") 17 | elif player == 'p' and computer == 's': 18 | print("You lose!") 19 | elif player == 's' and computer == 'r': 20 | print("You lose!") 21 | elif player == 's' and computer == 'p': 22 | print("You win!") 23 | else: 24 | print("Invalid input.") 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | -------------------------------------------------------------------------------- /Searching_Element.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def search(self, list1: List[int], target: int) -> int: 3 | l, r = 0, len(list1) - 1 4 | 5 | while l<=r: 6 | mid = (l + r) // 2 7 | if target == list1[mid]: 8 | return mid 9 | if list1[l] <= list1[mid]: 10 | if target > list1[mid] or target < list1[l]: 11 | l = mid + 1 12 | else: 13 | r = mid - 1 14 | else: 15 | 16 | if target < list1[mid] or target > list1[r]: 17 | r = mid - 1 18 | else: 19 | l = mid + 1 20 | 21 | return -1 22 | list1 = eval(input("Enter the elements of list within '[]' :")) 23 | target = int(input("Enter element to search for :")) 24 | obj = Solution() 25 | print("The element is at the", obj.search(list1, target), "index") 26 | -------------------------------------------------------------------------------- /DeletingElement.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class DeletingElement { 3 | public static void main(String[] args) { 4 | Scanner sc=new Scanner(System.in); 5 | int n,cap,pos; 6 | System.out.println("Enter Capacity Of Array"); 7 | cap=sc.nextInt(); 8 | System.out.println("Enter Element present "); 9 | n=sc.nextInt(); 10 | System.out.println("Enter pos of element to be removed"); 11 | pos=sc.nextInt(); 12 | int arr[]=new int[cap]; 13 | 14 | //Entering Array Element 15 | System.out.println("Enter Elements Of Array"); 16 | for (int i = 0; i < n; i++) { 17 | arr[i] = sc.nextInt(); 18 | } 19 | if(n==0) 20 | return; 21 | // Removing element 22 | for (int i=pos-1;i 2 | #define ll long long int 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | ll t; 8 | cin>>t; 9 | while(t-->0) 10 | { 11 | ll n; 12 | cin>>n; 13 | string a,b; 14 | cin>>a>>b; 15 | size_t found=a.find("1"); 16 | if(n==2 && a=="00" && b=="11") 17 | cout<<"NO"; 18 | else 19 | { 20 | bool x=false; 21 | for(int i=1;i 4 | #include 5 | 6 | int main() 7 | { 8 | char ch; 9 | double a, b; 10 | while (1) { 11 | printf("Enter an operator (+, -, *, /), if want to exit press x: "); 12 | scanf(" %c", &ch); 13 | // to exit 14 | if (ch == 'x') 15 | exit(0); 16 | printf("Enter two first and second operand: "); 17 | scanf("%lf %lf",&a,&b); 18 | // Using switch case we will differentiate 19 | // operations based on different operator 20 | switch (ch) { 21 | // For Addition 22 | case '+': 23 | printf("%.1lf + %.1lf = %.1lf\n", a, b, a + b); 24 | break; 25 | // For Subtraction 26 | case '-': 27 | printf("%.1lf - %.1lf = %.1lf\n", a, b, a - b); 28 | break; 29 | // For Multiplication 30 | case '*': 31 | printf("%.1lf * %.1lf = %.1lf\n", a, b, a * b); 32 | break; 33 | // For Division 34 | case '/': 35 | printf("%.1lf / %.1lf = %.1lf\n", a, b, a / b); 36 | break; 37 | // If operator doesn't match any case constant 38 | default: 39 | printf("Error! please write a valid operator\n"); 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /HcfLcm.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class HcfLcm 3 | { 4 | int a,b,hcf,lcm; 5 | HcfLcm() 6 | { 7 | a=0; 8 | b=0; 9 | hcf=1; 10 | lcm=0; 11 | } 12 | void getdata() 13 | { 14 | Scanner sc=new Scanner(System.in); 15 | System.out.println("Enter the first number"); 16 | a=sc.nextInt(); 17 | System.out.println("Enter the second number"); 18 | b=sc.nextInt(); 19 | } 20 | void change() 21 | { 22 | if(a>b) 23 | { 24 | a=b; 25 | b=a; 26 | } 27 | } 28 | int rechcf(int p, int q) 29 | { 30 | if(p==0) 31 | return q; 32 | else 33 | return rechcf(q%p,p); 34 | } 35 | int fn_lcm(int a, int b,int c) 36 | { 37 | return (a*b)/c; 38 | } 39 | void result() 40 | { 41 | hcf= rechcf(a,b); 42 | lcm=fn_lcm(a,b,hcf); 43 | System.out.println("HCF of these numbers "+hcf); 44 | System.out.println("LCM of these mumbers "+lcm); 45 | } 46 | } 47 | /*OUTPUT 48 | * Enter the first number 49 | 4 50 | Enter the second number 51 | 6 52 | HCF of these numbers 2 53 | LCM of these mumbers 12 54 | */ -------------------------------------------------------------------------------- /Leetcode/695. Max Area of Island.java: -------------------------------------------------------------------------------- 1 | Question 2 | 3 | You are given an m x n binary matrix grid. An island is a group of 1's (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. 4 | 5 | The area of an island is the number of cells with a value 1 in the island. 6 | 7 | Return the maximum area of an island in grid. If there is no island, return 0. 8 | 9 | Link - https://leetcode.com/problems/max-area-of-island/ 10 | 11 | 'SOLUTION :' 12 | 13 | class Solution { 14 | 15 | public int dfs(int[][] grid, int i, int j){ 16 | if(i<0 || i>=grid.length || j<0 || j>=grid[0].length || grid[i][j]==0) return 0; 17 | grid[i][j]=0; 18 | return 1+ dfs(grid, i-1, j)+ dfs(grid, i+1, j)+ dfs(grid, i, j-1)+ dfs(grid, i, j+1); 19 | } 20 | 21 | public int maxAreaOfIsland(int[][] grid) { 22 | int area=0; 23 | for(int i=0;i< grid.length; i++){ 24 | for(int j=0; j 2 | 3 | int main() 4 | { 5 | int choice,a,b,s; 6 | while(1) 7 | {printf("\n 1.Addition"); 8 | printf("\n 2.Odd-Even"); 9 | printf("\n 3.Printing N numbers"); 10 | printf("\n 4.Exit"); 11 | printf("\n\nEnter your choice"); 12 | scanf("%d",&choice); 13 | switch(choice) 14 | { 15 | case 1: 16 | printf("Enter two numbers"); 17 | scanf("%d%d",&a,&b); 18 | s=a+b; 19 | printf("\n sum is %d",a); 20 | break; 21 | case 2 : 22 | printf("Enter any number"); 23 | scanf("%d",a); 24 | if(a/2==0) 25 | {printf("Even");} 26 | else 27 | {printf("Odd");} 28 | break; 29 | case 3 : 30 | printf("Enter any number"); 31 | scanf("%d",&a); 32 | for(b=1;b<=a;b++) 33 | {printf("%d\n",b);} 34 | case 4 : 35 | exit(0); 36 | default : 37 | printf("Invalid choice"); 38 | 39 | 40 | 41 | }} 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /Snake_Water_Gun/Snake_Water_gun.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int SnakeWaterGun(char you,char comp){ 6 | //return 0 for draw,-1 for lose,1 for win 7 | if(you==comp){ 8 | return 0; 9 | } 10 | if(you=='s' && comp=='g'){ 11 | return -1; 12 | } 13 | else if(you=='g' && comp=='s'){ 14 | return 1; 15 | } 16 | if(you=='w' && comp=='s'){ 17 | return -1; 18 | } 19 | else if(you=='s' && comp=='w'){ 20 | return 1; 21 | } 22 | if(you=='g' && comp=='w'){ 23 | return -1; 24 | } 25 | else if(you=='w' && comp=='g'){ 26 | return 1; 27 | } 28 | } 29 | 30 | 31 | int main() 32 | { 33 | char you,comp,num; 34 | srand(time(0)); 35 | num = rand()%100 +1; 36 | if(num<33){ 37 | comp='s'; 38 | } 39 | else if(num>=33 && num<66){ 40 | comp='w'; 41 | } 42 | else{ 43 | comp='g'; 44 | } 45 | printf("Enter 's' for snake,'w' for water and 'g' ' for gun: "); 46 | scanf("%c",&you); 47 | int result = SnakeWaterGun(you,comp); 48 | printf("You chose %c and computer chose %c.\n",you,comp); 49 | if(result==0){ 50 | printf("It's a draw!\n"); 51 | } 52 | else if(result==1){ 53 | printf("You win!\n"); 54 | } 55 | else { 56 | printf("You lose!\n"); 57 | } 58 | return 0; 59 | } -------------------------------------------------------------------------------- /gmt.java: -------------------------------------------------------------------------------- 1 | // Java Program to convert local time to GMT 2 | 3 | // Importing libraries 4 | // 1. input output libraries 5 | import java.io.*; 6 | // 3. Text class 7 | import java.text.DateFormat; 8 | import java.text.SimpleDateFormat; 9 | // 2. Utility libraries for 10 | // Date and TimeZone class 11 | import java.util.Date; 12 | import java.util.TimeZone; 13 | 14 | // Class 15 | class GFG { 16 | 17 | // Main driver method 18 | public static void main(String[] args) 19 | { 20 | 21 | // Creating a Date class object 22 | // to take local time from the user 23 | Date localTime = new Date(); 24 | 25 | // Creating a DateFormat class object to 26 | // convert the localtime to GMT 27 | DateFormat s = new SimpleDateFormat("dd/MM/yyyy" 28 | + " " 29 | + " HH:mm:ss"); 30 | 31 | // function will helps to get the GMT Timezone 32 | // using the getTimeZOne() method 33 | s.setTimeZone(TimeZone.getTimeZone("GMT")); 34 | 35 | // One can get any other time zone also 36 | // by passing some other argument to it 37 | 38 | // Printing the local time 39 | System.out.println("local Time:" + localTime); 40 | 41 | // Printing the GMT time to 42 | // illustrate changes in GMT time 43 | System.out.println("Time IN Gmt : " 44 | + s.format(localTime)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Number of days finder 1st PR: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int month; 6 | 7 | 8 | printf("Enter month number (1-12): "); 9 | scanf("%d", &month); 10 | 11 | 12 | if(month == 1) 13 | { 14 | printf("31 days"); 15 | } 16 | else if(month == 2) 17 | { 18 | printf("28 or 29 days"); 19 | } 20 | else if(month == 3) 21 | { 22 | printf("31 days"); 23 | } 24 | else if(month == 4) 25 | { 26 | printf("30 days"); 27 | } 28 | else if(month == 5) 29 | { 30 | printf("31 days"); 31 | } 32 | else if(month == 6) 33 | { 34 | printf("30 days"); 35 | } 36 | else if(month == 7) 37 | { 38 | printf("31 days"); 39 | } 40 | else if(month == 8) 41 | { 42 | printf("31 days"); 43 | } 44 | else if(month == 9) 45 | { 46 | printf("30 days"); 47 | } 48 | else if(month == 10) 49 | { 50 | printf("31 days"); 51 | } 52 | else if(month == 11) 53 | { 54 | printf("30 days"); 55 | } 56 | else if(month == 12) 57 | { 58 | printf("31 days"); 59 | } 60 | else 61 | { 62 | printf("Invalid input! Please enter month number between (1-12)."); 63 | } 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /uniquenumber.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class uniquenumber 3 | { 4 | void main() 5 | { 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("Enter the number"); 8 | int num=sc.nextInt(); 9 | String str= Integer.toString(num); 10 | int l=str.length(); 11 | int flag=0, i, j; 12 | if(num<0) 13 | System.out.println("Invalid Input "); 14 | else 15 | { 16 | for(i=0;i 2 | int stack[20]; 3 | int top = -1; 4 | 5 | void push(int x) 6 | { 7 | stack[++top] = x; 8 | } 9 | 10 | int pop() 11 | { 12 | return stack[top--]; 13 | } 14 | 15 | int main() 16 | { 17 | char exp[20]; 18 | char *e; 19 | int n1,n2,n3,num; 20 | printf("Enter the expression :: "); 21 | scanf("%s",exp); 22 | e = exp; 23 | while(*e != '\0') 24 | { 25 | if(isdigit(*e)) 26 | { 27 | num = *e - 48; 28 | push(num); 29 | } 30 | else 31 | { 32 | n1 = pop(); 33 | n2 = pop(); 34 | switch(*e) 35 | { 36 | case '+': 37 | { 38 | n3 = n1 + n2; 39 | break; 40 | } 41 | case '-': 42 | { 43 | n3 = n2 - n1; 44 | break; 45 | } 46 | case '*': 47 | { 48 | n3 = n1 * n2; 49 | break; 50 | } 51 | case '/': 52 | { 53 | n3 = n2 / n1; 54 | break; 55 | } 56 | } 57 | push(n3); 58 | } 59 | e++; 60 | } 61 | printf("\nThe result of expression %s = %d\n\n",exp,pop()); 62 | return 0; 63 | } 64 | 65 | -------------------------------------------------------------------------------- /random_password_creator.py: -------------------------------------------------------------------------------- 1 | import string 2 | import random 3 | 4 | class Password: 5 | 6 | def __init__(self,charset,length): 7 | 8 | self.charset = charset 9 | self.length =length 10 | self.char_array = [] 11 | self.password = [] 12 | 13 | def set_the_charset(self): 14 | 15 | if('l' in self.charset): 16 | self.char_array.append(string.ascii_lowercase) 17 | 18 | if ('u' in self.charset): 19 | self.char_array.append(string.ascii_uppercase) 20 | 21 | if ('d' in self.charset): 22 | self.char_array.append(string.digits) 23 | 24 | if ('s' in self.charset): 25 | self.char_array.append(string.punctuation) 26 | 27 | def get_char_array(self): 28 | 29 | return self.char_array 30 | 31 | def generate_password(self): 32 | 33 | #print(self.char_array) 34 | 35 | for i in range(self.length): 36 | 37 | outer_index = random.randrange(0,len(self.char_array)) 38 | inner_index = random.randrange(0,len(self.char_array[outer_index])) 39 | self.password.append(self.char_array[outer_index][inner_index]) 40 | 41 | def get_password(self): 42 | 43 | return ''.join(self.password) 44 | 45 | 46 | 47 | 48 | 49 | # l - lowercase 50 | # u -uppercase 51 | # d - digit 52 | # s- special character 53 | #ldu 54 | #ls 55 | #l 56 | #u -------------------------------------------------------------------------------- /guessthenum.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | going=1 4 | you,system=0,0 5 | greets=["You guessed it correct smartass!","Bingo, you got that right!","That was a superb guess!","Bullseye!"] 6 | while going: 7 | a=random.randint(1,20) 8 | chances=4 9 | print("The system has choosen a number in between 1 and 20") 10 | print("Guess the number choosen by the system. You have a total of 4 chances for it. Good luck!") 11 | # print("\n") 12 | 13 | while chances: 14 | b=int(input()) 15 | if b==a: 16 | print(greets[random.randit(0,len(greets))]) 17 | you+=1 18 | break 19 | else: 20 | if chances==1: 21 | print("Oops, you ran out of attempts!") 22 | print("The number guessed by the system was:", a) 23 | system+=1 24 | # print("\n") 25 | break 26 | elif b>a: 27 | print("Incorrect") 28 | print("HINT: Your last guess was too high") 29 | elif b 2 | 3 | void quicksort (int [], int, int); 4 | 5 | int main() 6 | { 7 | int list[10]; 8 | int size, i; 9 | 10 | printf("Enter the number of elements: \n"); 11 | scanf("%d", &size); 12 | printf("\nEnter the elements to be sorted:\n"); 13 | for (i = 0; i < size; i++) 14 | { 15 | scanf("%d", &list[i]); 16 | } 17 | quicksort(list, 0, size - 1); 18 | printf("\nArray after Quick Sort\n"); 19 | for (i = 0; i < size; i++) 20 | { 21 | printf("%d ", list[i]); 22 | } 23 | printf("\n"); 24 | 25 | return 0; 26 | } 27 | void quicksort(int list[], int low, int high) 28 | { 29 | int pivot, i, j, temp; 30 | if (low < high) 31 | { 32 | pivot = low; 33 | i = low; 34 | j = high; 35 | while (i < j) 36 | { 37 | while (list[i] <= list[pivot] && i <= high) 38 | { 39 | i++; 40 | } 41 | while (list[j] > list[pivot] && j >= low) 42 | { 43 | j--; 44 | } 45 | if (i < j) 46 | { 47 | temp = list[i]; 48 | list[i] = list[j]; 49 | list[j] = temp; 50 | } 51 | } 52 | temp = list[j]; 53 | list[j] = list[pivot]; 54 | list[pivot] = temp; 55 | quicksort(list, low, j - 1); 56 | quicksort(list, j + 1, high); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Matrix Addition.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int r, c, a[100][100], b[100][100], sum[100][100], i, j; 7 | 8 | cout << "Enter number of rows (between 1 and 100): "; 9 | cin >> r; 10 | 11 | cout << "Enter number of columns (between 1 and 100): "; 12 | cin >> c; 13 | 14 | cout << endl << "Enter elements of 1st matrix: " << endl; 15 | 16 | // Storing elements of first matrix entered by user. 17 | for(i = 0; i < r; ++i) 18 | for(j = 0; j < c; ++j) 19 | { 20 | cout << "Enter element a" << i + 1 << j + 1 << " : "; 21 | cin >> a[i][j]; 22 | } 23 | 24 | // Storing elements of second matrix entered by user. 25 | cout << endl << "Enter elements of 2nd matrix: " << endl; 26 | for(i = 0; i < r; ++i) 27 | for(j = 0; j < c; ++j) 28 | { 29 | cout << "Enter element b" << i + 1 << j + 1 << " : "; 30 | cin >> b[i][j]; 31 | } 32 | 33 | // Adding Two matrices 34 | for(i = 0; i < r; ++i) 35 | for(j = 0; j < c; ++j) 36 | sum[i][j] = a[i][j] + b[i][j]; 37 | 38 | // Displaying the resultant sum matrix. 39 | cout << endl << "Sum of two matrix is: " << endl; 40 | for(i = 0; i < r; ++i) 41 | for(j = 0; j < c; ++j) 42 | { 43 | cout << sum[i][j] << " "; 44 | if(j == c - 1) 45 | cout << endl; 46 | } 47 | 48 | return 0; 49 | } -------------------------------------------------------------------------------- /Knapsack problem.c: -------------------------------------------------------------------------------- 1 | #include 2 | typedef struct{ 3 | int weight,value; 4 | float ratio; 5 | }Items; 6 | 7 | void knapsack(Items item[], int n) 8 | { 9 | int i=n-1,m; 10 | printf("Enter the capacity of knapsack: "); 11 | scanf("%d",&m); 12 | float max_profit = 0.0; 13 | while(m!=0) 14 | { 15 | if(m >= item[i].weight){ 16 | max_profit += (float)item[i].value; 17 | m -= item[i].weight; 18 | } 19 | else{ 20 | max_profit += ((float)m / (float)item[i].weight) * (float)item[i].value; 21 | m = 0; 22 | } 23 | i--; 24 | } 25 | printf("Maximum profit: %.2f", max_profit); 26 | } 27 | 28 | void sort(Items item[], int n) 29 | { 30 | int i,j; 31 | Items temp; 32 | for(i=0;i 0 && item[j-1].ratio > item[j].ratio){ 37 | temp = item[j]; 38 | item[j] = item[j-1]; 39 | item[j-1] = temp; 40 | j--; 41 | } 42 | } 43 | knapsack(item,n); 44 | } 45 | 46 | void main() 47 | { 48 | int i,n; 49 | Items item[100]; 50 | printf("Enter the no. of items: "); 51 | scanf("%d",&n); 52 | printf("Enter the weight and value of %d items:\n",n); 53 | for(i = 0; i < n; i++) 54 | { 55 | printf("Weight[%d]: ", i); 56 | scanf("%d", &item[i].weight); 57 | printf("Value[%d]: ", i); 58 | scanf("%d", &item[i].value); 59 | } 60 | sort(item,n); 61 | } -------------------------------------------------------------------------------- /Hacktoberfest 4th PR: -------------------------------------------------------------------------------- 1 | #Queues 2 | #Functions 3 | 4 | front=rear=0 5 | def empty(q): 6 | if q==[]: 7 | return True 8 | else: 9 | return False 10 | def push(q,value): 11 | global front,rear 12 | print('Add:') 13 | q.append(value) 14 | if len(q)==1: 15 | front=rear=0 16 | else: 17 | rear+=1 18 | def pop(q): 19 | global front,rear 20 | print('Delete:') 21 | if empty(q)==True: 22 | print('Underflow!') 23 | elif front==rear: 24 | returnvalue=q[front] 25 | front=rear=0 26 | q.clear() 27 | else: 28 | returnvalue=q[front] 29 | front+=1 30 | return returnvalue 31 | def show(q): 32 | global front,rear 33 | for i in range(front,rear+1): 34 | print(q[i],end=' ') 35 | 36 | #main 37 | 38 | ch=0 39 | q=[] 40 | while True: 41 | print('\n \t \t QUEUE MENU\n Press 0 to Exit\n Press 1 to Add\n Press 2 to Delete\n Press 3 to Show\n Enter Your Choice:') 42 | ch=int(input()) 43 | if ch==0: 44 | break 45 | elif ch==1: 46 | if len(q)==0: 47 | n=int(input('Enter First Value:')) 48 | else: 49 | n=int(input('Enter Next Value:')) 50 | push(q,n) 51 | elif ch==2: 52 | if len(q)==0: 53 | print('No Value-Underflow!') 54 | else: 55 | delvalue=pop(q) 56 | print('Deleted value:',delvalue) 57 | elif ch==3: 58 | show(q) 59 | else: 60 | print('Wrong Choice!') 61 | 62 | 63 | -------------------------------------------------------------------------------- /Hacktoberfest'22_PR1: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void merge_sort(int i, int j, int a[], int aux[]) 4 | { 5 | if (j <= i) 6 | { 7 | return; 8 | } 9 | int mid = (i + j) / 2; 10 | 11 | merge_sort(i, mid, a, aux); 12 | merge_sort(mid + 1, j, a, aux); 13 | 14 | int pointer_left = i; 15 | int pointer_right = mid + 1; 16 | int k; 17 | 18 | for (k = i; k <= j; k++) 19 | { 20 | if (pointer_left == mid + 1) 21 | { 22 | aux[k] = a[pointer_right]; 23 | pointer_right++; 24 | } 25 | else if (pointer_right == j + 1) 26 | { 27 | aux[k] = a[pointer_left]; 28 | pointer_left++; 29 | } 30 | else if (a[pointer_left] < a[pointer_right]) 31 | { 32 | aux[k] = a[pointer_left]; 33 | pointer_left++; 34 | } 35 | else 36 | { 37 | aux[k] = a[pointer_right]; 38 | pointer_right++; 39 | } 40 | } 41 | 42 | for (k = i; k <= j; k++) 43 | { 44 | a[k] = aux[k]; 45 | } 46 | } 47 | 48 | 49 | int main() 50 | { 51 | int a[10], aux[10], n, i, d, swap; 52 | 53 | printf("Enter number of elements in the array:\n"); 54 | scanf("%d", &n); 55 | 56 | printf("\nEnter %d integers\n", n); 57 | 58 | for (i = 0; i < n; i++) 59 | { 60 | scanf("%d", &a[i]); 61 | } 62 | merge_sort(0, n - 1, a, aux); 63 | 64 | printf("\nArray after Merge Sort:\n"); 65 | for (i = 0; i < n; i++) 66 | printf("%d\n", a[i]); 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /goldbach.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class goldbach 3 | { 4 | Scanner ob=new Scanner(System.in); 5 | int n=0; 6 | void input()//input a number from user 7 | { 8 | System.out.println("Enter a number"); 9 | n=ob.nextInt(); 10 | } 11 | boolean isPrime(int n)//check whether it is prime or not 12 | { 13 | int c=0; 14 | for(int i=2;i9&&n<50) 31 | { 32 | while(a=26 and i<74: 46 | if i%2 ==0: 47 | s.bgcolor('white') 48 | else: 49 | s.bgcolor('black') 50 | else: 51 | if i%3==0: 52 | s.bgcolor('white') 53 | else: 54 | s.bgcolor('black') 55 | 56 | k.pen(pencolor="cyan",pensize=7,speed=7) 57 | k.penup() 58 | k.goto(240,-200) 59 | k.pendown() 60 | k.goto(240,-300) 61 | k.goto(300,-250) 62 | k.goto(240,-200) 63 | k.penup() 64 | k.goto(360,-200) 65 | k.pendown() 66 | k.goto(320,-250) 67 | k.goto(360,-300) 68 | k.goto(400,-250) 69 | k.goto(360,-200) 70 | k.penup() 71 | k.goto(360,-250) 72 | k.pendown() 73 | k.goto(400,-300) 74 | t.done() 75 | 76 | 77 | 78 | 79 | angle = 120 80 | side = 0 81 | lim = 800 82 | shape(angle,side,lim) 83 | -------------------------------------------------------------------------------- /Hacktoberfest'22_PR3: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node 5 | { 6 | int num; 7 | struct node* nextptr; 8 | }*stnode; 9 | 10 | void createnode(int ); 11 | void display(); 12 | 13 | 14 | int main() 15 | { 16 | int n; 17 | printf("enter no of nodes\n"); 18 | scanf("%d",&n); 19 | 20 | createnode(n); 21 | display(); 22 | 23 | return 0; 24 | } 25 | 26 | void createnode(int x) 27 | { 28 | if(x==0) 29 | return; 30 | 31 | struct node*fn,*temp; 32 | 33 | int num,i; 34 | 35 | stnode=(struct node*)malloc(sizeof(struct node)); 36 | 37 | if(stnode==NULL) 38 | { 39 | printf("memory cannot be allocated\n"); 40 | } 41 | else 42 | { 43 | printf("enter data for node\n"); 44 | scanf("%d",&num); 45 | 46 | stnode->num=num; 47 | stnode->nextptr=NULL; 48 | 49 | temp=stnode; 50 | for(int i=2;i<=x;i++) 51 | { 52 | fn=(struct node*)malloc(sizeof(struct node)); 53 | 54 | if(fn==NULL) 55 | { 56 | printf("memory cannot be allocated\n"); 57 | break; 58 | } 59 | else 60 | { 61 | printf("enter data for node\n"); 62 | scanf("%d",&num); 63 | 64 | fn->num=num; 65 | fn->nextptr=NULL; 66 | 67 | temp->nextptr=fn; 68 | temp=temp->nextptr; 69 | } 70 | } 71 | } 72 | 73 | 74 | } 75 | 76 | void display() 77 | { 78 | struct node *tmp; 79 | if(stnode==NULL) 80 | { 81 | printf("list is empty"); 82 | } 83 | else 84 | { 85 | printf("Data entered in the list\n"); 86 | 87 | tmp=stnode; 88 | 89 | while(tmp!=NULL){ 90 | printf("Data -> %d\n",tmp->num); 91 | tmp=tmp->nextptr; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /pangram.java pr1: -------------------------------------------------------------------------------- 1 | class GFG { 2 | 3 | static int size = 26; 4 | 5 | // Function to check if ch is a letter 6 | static boolean isLetter(char ch) 7 | { 8 | if (!Character.isLetter(ch)) 9 | return false; 10 | 11 | return true; 12 | } 13 | 14 | // Function to check if a string 15 | // contains all the letters from 16 | // a to z 17 | static boolean allLetter(String str, 18 | int len) 19 | { 20 | // Convert the given string 21 | // into lowercase 22 | str = str.toLowerCase(); 23 | 24 | // Create a frequency array to 25 | // mark the present letters 26 | boolean[] present = new boolean[size]; 27 | 28 | // Traverse for each character 29 | // of the string 30 | for (int i = 0; i < len; i++) { 31 | 32 | // If the current character 33 | // is a letter 34 | if (isLetter(str.charAt(i))) { 35 | 36 | // Mark current letter as present 37 | int letter = str.charAt(i) - 'a'; 38 | present[letter] = true; 39 | } 40 | } 41 | 42 | // Traverse for every letter 43 | // from a to z 44 | for (int i = 0; i < size; i++) { 45 | 46 | // If the current character 47 | // is not present in string 48 | // then return false, 49 | // otherwise return true 50 | if (!present[i]) 51 | return false; 52 | } 53 | return true; 54 | } 55 | 56 | // Driver Code 57 | public static void main(String args[]) 58 | { 59 | 60 | // Given string str 61 | String str = "Abcdefghijklmnopqrstuvwxyz"; 62 | int len = str.length(); 63 | 64 | // Function Call 65 | if (allLetter(str, len)) 66 | System.out.println("Yes"); 67 | else 68 | System.out.println("No"); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Linked_List/llist.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | class Node { 5 | int data; 6 | Node next; 7 | 8 | Node(int d) 9 | { 10 | data =d; 11 | next=null; 12 | } 13 | 14 | } 15 | 16 | 17 | class llist { 18 | 19 | static Node head=null; 20 | 21 | public static void main(String args[]) 22 | { 23 | add(7); 24 | add(10); 25 | add(0); 26 | add(78); 27 | 28 | 29 | 30 | display(); 31 | System.out.println(count()); 32 | delete(3); 33 | add(9,3); 34 | add(950,0); 35 | display(); 36 | } 37 | 38 | 39 | static void display() 40 | { 41 | 42 | Node temp=head; 43 | 44 | while(temp!=null) 45 | { 46 | System.out.print(temp.data+" "); 47 | temp=temp.next; 48 | } 49 | System.out.println(); 50 | } 51 | 52 | 53 | static void add(int d) 54 | { 55 | 56 | if(head==null) 57 | { 58 | head=new Node(d); 59 | return; 60 | } 61 | 62 | Node temp=head; 63 | 64 | while(temp.next!=null) 65 | { 66 | temp = temp.next; 67 | } 68 | 69 | temp.next=new Node(d); 70 | } 71 | 72 | 73 | static void add(int d, int pos) 74 | { 75 | 76 | if(pos==0) 77 | { 78 | Node temp=new Node(d); 79 | temp.next=head; 80 | head=temp; 81 | return; 82 | } 83 | 84 | Node temp=head; 85 | 86 | int c=1; 87 | 88 | while(c 2 | #include 3 | using namespace std; 4 | 5 | int priority (char alpha){ 6 | if(alpha == '+' || alpha =='-') 7 | return 1; 8 | 9 | if(alpha == '*' || alpha =='/') 10 | return 2; 11 | 12 | if(alpha == '^') 13 | return 3; 14 | 15 | 16 | return 0; 17 | } 18 | string convert(string infix) 19 | { 20 | int i = 0; 21 | string postfix = ""; 22 | // using inbuilt stack< > from C++ stack library 23 | stack s; 24 | 25 | while(infix[i]!='\0') 26 | { 27 | // if operand add to the postfix expression 28 | if(infix[i]>='a' && infix[i]<='z'|| infix[i]>='A'&& infix[i]<='Z') 29 | { 30 | postfix += infix[i]; 31 | i++; 32 | } 33 | // if opening bracket then push the stack 34 | else if(infix[i]=='(') 35 | { 36 | s.push(infix[i]); 37 | i++; 38 | } 39 | // if closing bracket encounted then keep popping from stack until 40 | // closing a pair opening bracket is not encountered 41 | else if(infix[i]==')') 42 | { 43 | while(s.top()!='('){ 44 | postfix += s.top(); 45 | s.pop(); 46 | } 47 | s.pop(); 48 | i++; 49 | } 50 | else 51 | { 52 | while (!s.empty() && priority(infix[i]) <= priority(s.top())){ 53 | postfix += s.top(); 54 | s.pop(); 55 | } 56 | s.push(infix[i]); 57 | i++; 58 | } 59 | } 60 | while(!s.empty()){ 61 | postfix += s.top(); 62 | s.pop(); 63 | } 64 | 65 | 66 | cout << "Postfix is : " << postfix; //it will print postfix conversion 67 | return postfix; 68 | } 69 | 70 | int main() 71 | { 72 | string infix = "((a+(b*c))-d)"; 73 | string postfix; 74 | postfix = convert(infix); 75 | 76 | return 0; 77 | } -------------------------------------------------------------------------------- /number_guessing_game.py: -------------------------------------------------------------------------------- 1 | from random import randint 2 | logo = """ 3 | / _ \_ _ ___ ___ ___ /__ \ |__ ___ /\ \ \_ _ _ __ ___ | |__ ___ _ __ 4 | / /_\/ | | |/ _ \/ __/ __| / /\/ '_ \ / _ \ / \/ / | | | '_ ` _ \| '_ \ / _ \ '__| 5 | / /_\\| |_| | __/\__ \__ \ / / | | | | __/ / /\ /| |_| | | | | | | |_) | __/ | 6 | \____/ \__,_|\___||___/___/ \/ |_| |_|\___| \_\ \/ \__,_|_| |_| |_|_.__/ \___|_| 7 | """ 8 | 9 | EASY_LEVEL_TURNS = 10 10 | HARD_LEVEL_TURNS = 5 11 | 12 | #Function to check user's guess against actual answer. 13 | def check_answer(guess, answer, turns): 14 | """checks answer against guess. Returns the number of turns remaining.""" 15 | if guess > answer: 16 | print("Too high.") 17 | return turns - 1 18 | elif guess < answer: 19 | print("Too low.") 20 | return turns - 1 21 | else: 22 | print(f"You got it! The answer was {answer}.") 23 | 24 | #Make function to set difficulty. 25 | def set_difficulty(): 26 | level = input("Choose a difficulty. Type 'easy' or 'hard': ") 27 | if level == "easy": 28 | return EASY_LEVEL_TURNS 29 | else: 30 | return HARD_LEVEL_TURNS 31 | 32 | def game(): 33 | print(logo) 34 | #Choosing a random number between 1 and 100. 35 | print("Welcome to the Number Guessing Game!") 36 | print("I'm thinking of a number between 1 and 100.") 37 | answer = randint(1, 100) 38 | #print(f"Pssst, the correct answer is {answer}") 39 | 40 | turns = set_difficulty() 41 | #Repeat the guessing functionality if they get it wrong. 42 | guess = 0 43 | while guess != answer: 44 | print(f"You have {turns} attempts remaining to guess the number.") 45 | 46 | #Let the user guess a number. 47 | guess = int(input("Make a guess: ")) 48 | 49 | #Track the number of turns and reduce by 1 if they get it wrong. 50 | turns = check_answer(guess, answer, turns) 51 | if turns == 0: 52 | print("You've run out of guesses, you lose.") 53 | return 54 | elif guess != answer: 55 | print("Guess again.") 56 | 57 | 58 | game() 59 | 60 | -------------------------------------------------------------------------------- /Leetcode/300. LIS/LongestIncreasingSubsequence.java: -------------------------------------------------------------------------------- 1 | This can be solved by 2 | RECURSION : T.C = O(2^n) S.C = O(N) with aux stack space 3 | MEMOIZATION: T.C = O(N*N) S.C = O(N) 4 | TABULATION 5 | 6 | BINARY SEARCH: TC - O(N*logN) 7 | 8 | "Binary search solution" 9 | 10 | class Solution { 11 | public int search(ArrayList list, int key ){ 12 | 13 | int l = 0, r= list.size()-1; 14 | while(l<=r){ 15 | int m = l + (r-l)/2; 16 | if(list.get(m)==key){ 17 | return m; 18 | } 19 | else if(list.get(m)>key){ 20 | r = m-1; 21 | } 22 | else{ 23 | l = m+1; 24 | } 25 | } 26 | //If control comes over here it means the key is not present in the list 27 | return l; 28 | 29 | } 30 | 31 | public int lengthOfLIS(int[] nums) { 32 | //MAKE AN ARRAYLIST FOR FAKE LONGEST INCREASING SUBSEQ 33 | ArrayList list = new ArrayList<>(); 34 | 35 | for(int i =0;i 1 && (Math.pow(x, 2) + c) > x) 33 | return -1; 34 | } 35 | } 36 | 37 | public static void main(String args[]) { 38 | Scanner sc = new Scanner(System.in); 39 | System.out.println("Enter the constant. 0<=(provided constant)<=0.25"); 40 | double c = sc.nextDouble(); 41 | System.out.println("Start from 0?(y/n). Enter y if you are using for the first time."); 42 | String b = sc.next(); 43 | double x = 0; 44 | if (b.equalsIgnoreCase("n")) { 45 | System.out.println("enter x"); 46 | x = sc.nextDouble(); 47 | } 48 | mandelbrot ob = new mandelbrot(x, c); 49 | int steps = ob.converge(); 50 | if (steps == -1) 51 | System.out.println("It does not converge"); 52 | else { 53 | double soln = ob.solve(); 54 | System.out.println("It converges after " + steps + " steps at x=" + soln + "."); 55 | } 56 | sc.close(); 57 | } 58 | } -------------------------------------------------------------------------------- /matrix.java: -------------------------------------------------------------------------------- 1 | // Java Program to Rotate Matrix Elements 2 | 3 | // Importing classes from java.lang package 4 | import java.lang.*; 5 | // Importing classes from java.util package 6 | import java.util.*; 7 | 8 | // main Class 9 | class GFG { 10 | static int r = 4; 11 | static int c = 4; 12 | 13 | // Method 14 | // To rotate a matrix of 15 | // dimension r x c. And initially, 16 | // p = r and q = c 17 | static void rotate_matrix(int p, int q, int matrix[][]) 18 | { 19 | int rw = 0, cl = 0; 20 | int previous, current; 21 | 22 | // rw is the Starting row index 23 | // p is the ending row index 24 | // cl is the starting column index 25 | // q is the ending column index and 26 | // x is the iterator 27 | while (rw < p && cl < q) { 28 | 29 | if (rw + 1 == p || cl + 1 == q) 30 | break; 31 | 32 | // After storing the first element of the 33 | // next row, this element will substitute 34 | // the first element of the current row 35 | previous = matrix[rw + 1][cl]; 36 | 37 | // Moving the elements of the first row 38 | // from rest of the rows 39 | for (int x = cl; x < q; x++) { 40 | current = matrix[rw][x]; 41 | matrix[rw][x] = previous; 42 | previous = current; 43 | } 44 | rw++; 45 | 46 | // Moving the elements of the last column 47 | // from rest of the columns 48 | for (int x = rw; x < p; x++) { 49 | current = matrix[x][q - 1]; 50 | matrix[x][q - 1] = previous; 51 | previous = current; 52 | } 53 | q--; 54 | 55 | // Moving the elements of the last row 56 | // from rest of the rows 57 | if (rw < p) { 58 | for (int x = q - 1; x >= cl; x--) { 59 | current = matrix[p - 1][x]; 60 | matrix[p - 1][x] = previous; 61 | previous = current; 62 | } 63 | } 64 | p--; 65 | 66 | // Moving elements of the first column 67 | // from rest of the rows 68 | if (cl < q) { 69 | for (int x = p - 1; x >= rw; x--) { 70 | current = matrix[x][cl]; 71 | matrix[x][cl] = previous; 72 | previous = current; 73 | } 74 | } 75 | cl++; 76 | } 77 | 78 | // Prints the rotated matrix 79 | for (int x = 0; x < r; x++) { 80 | for (int y = 0; y < c; y++) 81 | System.out.print(matrix[x][y] + " "); 82 | System.out.print("\n"); 83 | } 84 | } 85 | 86 | // Method 2 87 | // Main driver method 88 | public static void main(String[] args) 89 | { 90 | 91 | // Custom input array 92 | int b[][] = { { 5, 6, 7, 8 }, 93 | { 1, 2, 3, 4 }, 94 | { 0, 15, 6, 5 }, 95 | { 3, 1, 2, 12 } }; 96 | 97 | // Calling function(Method1) to rotate matrix 98 | rotate_matrix(r, c, b); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /calculator.py: -------------------------------------------------------------------------------- 1 | from replit import clear 2 | #For Clearing outputs 3 | logo = """ 4 | _____________________ 5 | | _________________ | 6 | | | Pythonista 0. | | .----------------. .----------------. .----------------. .----------------. 7 | | |_________________| | | .--------------. || .--------------. || .--------------. || .--------------. | 8 | | ___ ___ ___ ___ | | | ______ | || | __ | || | _____ | || | ______ | | 9 | | | 7 | 8 | 9 | | + | | | | .' ___ | | || | / \ | || | |_ _| | || | .' ___ | | | 10 | | |___|___|___| |___| | | | / .' \_| | || | / /\ \ | || | | | | || | / .' \_| | | 11 | | | 4 | 5 | 6 | | - | | | | | | | || | / ____ \ | || | | | _ | || | | | | | 12 | | |___|___|___| |___| | | | \ `.___.'\ | || | _/ / \ \_ | || | _| |__/ | | || | \ `.___.'\ | | 13 | | | 1 | 2 | 3 | | x | | | | `._____.' | || ||____| |____|| || | |________| | || | `._____.' | | 14 | | |___|___|___| |___| | | | | || | | || | | || | | | 15 | | | . | 0 | = | | / | | | '--------------' || '--------------' || '--------------' || '--------------' | 16 | | |___|___|___| |___| | '----------------' '----------------' '----------------' '----------------' 17 | |_____________________| 18 | """ 19 | 20 | print(logo) 21 | 22 | # Calculation part 23 | def calc(a, b, op): 24 | if (op == "+"): 25 | return (a + b) 26 | elif (op == "-"): 27 | return (a - b) 28 | elif (op == "*"): 29 | return (a * b) 30 | elif (op == "/"): 31 | return (a / b) 32 | 33 | # Main Program 34 | flag = 0 35 | should_continue = True 36 | # While loop for Repeating Calculation 37 | while (should_continue): 38 | if (flag == 0): 39 | number_1 = float(input("What's the first number : ")) 40 | flag=0 #almost like backtracking but just to omit re-input 41 | print("+\n-\n*\n/\n") #operators print 42 | op = input("Pick an operator from above : ") 43 | number_2 = float(input("What's the next number : ")) 44 | print(f"{number_1} {op} {number_2} : {calc(number_1,number_2,op)}") 45 | result = input( 46 | f"type 'y' to continue calculating with {calc(number_1,number_2,op)}, or type 'n' to start a new calculation, or type 'exit' for exit calculator " 47 | ) 48 | if (result == "exit"): #For exit from the Program 49 | should_continue = False 50 | print("Goodbye") 51 | break 52 | elif (result == "y"): #For calculating with same Inputs 53 | flag = 1 54 | number_1 = int(calc(number_1, number_2, op)) 55 | else: #For starting the program from first step 56 | clear() 57 | -------------------------------------------------------------------------------- /Image Resizer/resize.java: -------------------------------------------------------------------------------- 1 | import javax.imageio.ImageIO; 2 | import java.awt.*; 3 | import java.awt.image.BufferedImage; 4 | import java.io.FileInputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.nio.file.Path; 8 | import java.nio.file.Paths; 9 | import java.util.*; 10 | 11 | public class resize { 12 | 13 | private static final int IMG_WIDTH = 128; 14 | private static final int IMG_HEIGHT = 64; 15 | 16 | public static void main(String[] args) throws IOException { 17 | 18 | Path source = Paths.get(args[0]); 19 | Path target = Paths.get(args[1]); 20 | 21 | try (InputStream is = new FileInputStream(source.toFile())) { 22 | resize(is, target, IMG_WIDTH, IMG_HEIGHT); 23 | } 24 | 25 | } 26 | 27 | private static void resize(InputStream input, Path target, 28 | int width, int height) throws IOException { 29 | 30 | // read an image to BufferedImage for processing 31 | BufferedImage originalImage = ImageIO.read(input); 32 | 33 | // create a new BufferedImage for drawing 34 | BufferedImage newResizedImage 35 | = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); 36 | Graphics2D g = newResizedImage.createGraphics(); 37 | 38 | // background transparent 39 | g.setComposite(AlphaComposite.Src); 40 | g.fillRect(0, 0, width, height); 41 | 42 | g.setRenderingHint(RenderingHints.KEY_RENDERING, 43 | RenderingHints.VALUE_RENDER_QUALITY); 44 | 45 | // controls how image pixels are filtered or resampled 46 | g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, 47 | RenderingHints.VALUE_INTERPOLATION_BILINEAR); 48 | 49 | // antialiasing, on 50 | g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 51 | RenderingHints.VALUE_ANTIALIAS_ON); 52 | 53 | Map hints = new HashMap<>(); 54 | hints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); 55 | hints.put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); 56 | hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); 57 | g.addRenderingHints(hints); 58 | 59 | // puts the original image into the newResizedImage 60 | g.drawImage(originalImage, 0, 0, IMG_WIDTH, IMG_HEIGHT, null); 61 | g.dispose(); 62 | 63 | // get file extension 64 | String s = target.getFileName().toString(); 65 | String fileExtension = s.substring(s.lastIndexOf(".") + 1); 66 | 67 | // we want image in png format 68 | ImageIO.write(newResizedImage, fileExtension, target.toFile()); 69 | 70 | } 71 | 72 | } -------------------------------------------------------------------------------- /alarm.py: -------------------------------------------------------------------------------- 1 | 2 | """ Alarm Clock 3 | ---------------------------------------- 4 | """ 5 | import datetime 6 | import os 7 | import time 8 | import random 9 | import webbrowser 10 | // If video URL file does not exist, create one 11 | if not os.path.isfile("youtube_alarm_videos.txt"): 12 | print('Creating "youtube_alarm_videos.txt"...') 13 | with open("youtube_alarm_videos.txt", "w") as alarm_file: 14 | alarm_file.write("https://www.youtube.com/watch?v=anM6uIZvx74") 15 | def check_alarm_input(alarm_time): 16 | """Checks to see if the user has entered in a valid alarm time""" 17 | if len(alarm_time) == 1: // [Hour] Format 18 | if alarm_time[0] < 24 and alarm_time[0] >= 0: 19 | return True 20 | if len(alarm_time) == 2: // [Hour:Minute] Format 21 | if alarm_time[0] < 24 and alarm_time[0] >= 0 and \ 22 | alarm_time[1] < 60 and alarm_time[1] >= 0: 23 | return True 24 | elif len(alarm_time) == 3: // [Hour:Minute:Second] Format 25 | if alarm_time[0] < 24 and alarm_time[0] >= 0 and \ 26 | alarm_time[1] < 60 and alarm_time[1] >= 0 and \ 27 | alarm_time[2] < 60 and alarm_time[2] >= 0: 28 | return True 29 | return False 30 | // Get user input for the alarm time 31 | print("Set a time for the alarm (Ex. 06:30 or 18:30:00)") 32 | while True: 33 | alarm_input = input(">> ") 34 | try: 35 | alarm_time = [int(n) for n in alarm_input.split(":")] 36 | if check_alarm_input(alarm_time): 37 | break 38 | else: 39 | raise ValueError 40 | except ValueError: 41 | print("ERROR: Enter time in HH:MM or HH:MM:SS format") 42 | // Convert the alarm time from [H:M] or [H:M:S] to seconds 43 | seconds_hms = [3600, 60, 1] // Number of seconds in an Hour, Minute, and Second 44 | alarm_seconds = sum([a*b for a,b in zip(seconds_hms[:len(alarm_time)], alarm_time)]) 45 | // Get the current time of day in seconds 46 | now = datetime.datetime.now() 47 | current_time_seconds = sum([a*b for a,b in zip(seconds_hms, [now.hour, now.minute, now.second])]) 48 | // Calculate the number of seconds until alarm goes off 49 | time_diff_seconds = alarm_seconds - current_time_seconds 50 | // If time difference is negative, set alarm for next day 51 | if time_diff_seconds < 0: 52 | time_diff_seconds += 86400 // number of seconds in a day 53 | // Display the amount of time until the alarm goes off 54 | print("Alarm set to go off in %s" % datetime.timedelta(seconds=time_diff_seconds)) 55 | // Sleep until the alarm goes off 56 | time.sleep(time_diff_seconds) 57 | // Time for the alarm to go off 58 | print("Wake Up!") 59 | // Load list of possible video URLs 60 | with open("youtube_alarm_videos.txt", "r") as alarm_file: 61 | videos = alarm_file.readlines() 62 | // Open a random video from the list 63 | webbrowser.open(random.choice(videos)) -------------------------------------------------------------------------------- /Square_Wave/square.java: -------------------------------------------------------------------------------- 1 | import java.awt.*; 2 | import java.applet.*; 3 | import java.awt.event.*; 4 | 5 | /* 6 | 7 | 8 | */ 9 | 10 | 11 | public class square extends Applet implements Runnable,ActionListener 12 | { 13 | int sp=10; 14 | int z=0,ofs=160; 15 | Thread t; 16 | Button p; 17 | Graphics g; 18 | Image img; 19 | Label coff; 20 | String msg="4/PI"; 21 | int n=0; 22 | 23 | Color c[]=new Color[10]; 24 | int xa[]=new int[10]; 25 | int ya[]=new int[10]; 26 | double ra[]=new double[10]; 27 | 28 | public void init() 29 | { 30 | coff=new Label("Fourier Coefficients : "); 31 | 32 | 33 | coff.setBackground(Color.BLACK); 34 | 35 | add(coff); 36 | System.out.println(msg); 37 | p=new Button("ADD HARMONICS"); 38 | 39 | p.setBackground(Color.RED); 40 | add(p); 41 | 42 | p.addActionListener(this); 43 | 44 | c[0]=new Color(208,205,145); 45 | c[1]=new Color(197,249,254); 46 | c[2]=new Color(57,182,230); 47 | c[3]=new Color(237,112,184); 48 | c[4]=new Color(137,211,139); 49 | c[5]=new Color(129,200,220); 50 | c[6]=new Color(211,152,224); 51 | c[7]=new Color(156,213,243); 52 | c[8]=new Color(156,213,243); 53 | c[9]=new Color(221,255,196); 54 | 55 | 56 | 57 | coff.setForeground(c[0]); 58 | 59 | setBackground(Color.BLACK); 60 | 61 | t = new Thread(this); 62 | t.start(); 63 | 64 | for(int i=0;i=0;theta-=1.5) 104 | { 105 | 106 | for(int j=0;j 280: 93 | hit_ball.sety(280) 94 | hit_ball.dy *= -1 95 | 96 | if hit_ball.ycor() < -280: 97 | hit_ball.sety(-280) 98 | hit_ball.dy *= -1 99 | 100 | if hit_ball.xcor() > 500: 101 | hit_ball.goto(0, 0) 102 | hit_ball.dy *= -1 103 | left_player += 1 104 | sketch_1.clear() 105 | sketch_1.write("Left_player : {} Right_player: {}".format( 106 | left_player, right_player), align="center", 107 | font=("Courier", 24, "normal")) 108 | 109 | if hit_ball.xcor() < -500: 110 | hit_ball.goto(0, 0) 111 | hit_ball.dy *= -1 112 | right_player += 1 113 | sketch_1.clear() 114 | sketch_1.write("Left_player : {} Right_player: {}".format( 115 | left_player, right_player), align="center", 116 | font=("Courier", 24, "normal")) 117 | 118 | # Collision of ball and paddles 119 | if (hit_ball.xcor() > 360 and 120 | hit_ball.xcor() < 370) and (hit_ball.ycor() < right_paddle.ycor() + 40 and 121 | hit_ball.ycor() > right_paddle.ycor() - 40): 122 | hit_ball.setx(360) 123 | hit_ball.dx *= -1 124 | 125 | if (hit_ball.xcor() < -360 and 126 | hit_ball.xcor() > -370) and (hit_ball.ycor() < left_paddle.ycor() + 40 and 127 | hit_ball.ycor() > left_paddle.ycor() - 40): 128 | hit_ball.setx(-360) 129 | hit_ball.dx *= -1 130 | -------------------------------------------------------------------------------- /Number_guessing_game.cpp: -------------------------------------------------------------------------------- 1 | // Create game c++ 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int main(){ 9 | srand(time(0)); 10 | int number = rand() % 100 + 1; 11 | int guess; 12 | int tries = 10; 13 | bool win = false; 14 | cout << "Guess My Number Game" << endl; 15 | while (win == false){ 16 | cout << "Enter a guess between 1 and 100: "; 17 | cin >> guess; 18 | tries --; 19 | if (guess == number){ 20 | win = true; 21 | break; 22 | } 23 | else{ 24 | if (number % 2 == 0 && guess % 2 == 0){ 25 | cout << "You are on the right track, the number is even!" << endl; 26 | } 27 | else if (number % 2 == 0 && guess % 2 != 0){ 28 | cout << "The number is even. Try guessing even numbers!" << endl; 29 | } 30 | else if (number % 2 != 0 && guess % 2 == 0){ 31 | cout << "The number is odd. Try guessing odd numbers!" << endl; 32 | } 33 | else if (number % 2 != 0 && guess % 2 != 0){ 34 | cout << "You are on the right track, the number is odd!" << endl; 35 | } 36 | cout << "You have " << tries << " tries left!" << endl << endl; 37 | } 38 | 39 | cout << "Enter a guess between 1 and 100: "; 40 | cin >> guess; 41 | tries --; 42 | if (guess == number){ 43 | win = true; 44 | break; 45 | } 46 | else{ 47 | if (number % 3 == 0 && guess % 3 == 0){ 48 | cout << "You are on the right track, the number is a multiple of 3!" << endl; 49 | } 50 | else if (number % 3 == 0 && guess % 3 != 0){ 51 | cout << "The number is a multiple of 3. Try guessing such numbers!" << endl; 52 | } 53 | else if (number % 5 == 0 && guess % 5 == 0){ 54 | cout << "You are on the right track, the number is a multiple of 5!" << endl; 55 | } 56 | else if (number % 5 == 0 && guess % 5 != 0){ 57 | cout << "The number is a multiple of 5. Try guessing such numbers!" << endl; 58 | } 59 | else if (number % 7 == 0 && guess % 7 == 0){ 60 | cout << "You are on the right track, the number is a multiple of 7!" << endl; 61 | } 62 | else if (number % 7 == 0 && guess % 7 != 0){ 63 | cout << "The number is a multiple of 7. Try guessing such numbers!" << endl; 64 | } 65 | else{ 66 | cout << "The number is not a multiple of 3, 5 and 7! Try guessing such numbers!" << endl; 67 | } 68 | cout << "You have " << tries << " tries left!" << endl << endl; 69 | } 70 | 71 | while (tries > 0){ 72 | cout << "Enter a guess between 1 and 100: "; 73 | cin >> guess; 74 | tries --; 75 | if (guess > number) { 76 | cout << "Too high!" << endl; 77 | cout << "You have " << tries << " tries left!" << endl << endl; 78 | } 79 | else if (guess < number) { 80 | cout << "Too low!" << endl; 81 | cout << "You have " << tries << " tries left!" << endl << endl; 82 | } 83 | else { 84 | win = true; 85 | break; 86 | } 87 | } 88 | } 89 | 90 | if (win == true){ 91 | if (10 - tries == 1){ 92 | cout << "Correct! You guessed the number " << number << " in " << 10 - tries << " guess!" << endl << endl; 93 | } 94 | else{ 95 | cout << "Correct! You guessed the number " << number << " in " << 10 - tries << " guesses!" << endl << endl; 96 | } 97 | } 98 | else{ 99 | cout << "You were not able to guess the number!" << endl << "The number was " << number << "!" << endl; 100 | } 101 | return 0; 102 | } -------------------------------------------------------------------------------- /infixtoprefix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | //definition of functions 4 | struct Stack *create (int max); 5 | int stackFull (struct Stack *stack); 6 | int stackEmpty (struct Stack *stack); 7 | void pushElement (struct Stack *stack, int item); 8 | int popElement (struct Stack *stack); 9 | int peekElement (struct Stack *stack); 10 | int checkOperand (char ch); 11 | int precedence (char ch); 12 | int postfix (char *expression); 13 | void reverse (char *exp); 14 | void brackets (char *exp); 15 | void conversionInfixToPrefix (char *exp); 16 | // A structure to represent a stack 17 | struct Stack 18 | { 19 | int top; 20 | int maxSize; 21 | int *array; 22 | }; 23 | int main () 24 | { 25 | int n = 10; 26 | cout << "The infix expression is: \n"; 27 | char expression[] = "(P+(Q*R)/(S-T))"; 28 | cout << expression << "\n"; 29 | conversionInfixToPrefix (expression); 30 | cout << "The prefix expression is: \n"; 31 | cout << expression; 32 | return 0; 33 | } 34 | //stack implementation 35 | struct Stack * create (int max) 36 | { 37 | struct Stack *stack = (struct Stack *) malloc (sizeof (struct Stack)); 38 | stack->maxSize = max; 39 | stack->top = -1; 40 | stack->array = (int *) malloc (stack->maxSize * sizeof (int)); 41 | return stack; 42 | } 43 | 44 | // Checking with this function is stack is full or not 45 | int stackFull (struct Stack *stack) 46 | { 47 | if (stack->top == stack->maxSize - 1) 48 | { 49 | cout << "Will not be able to push maxSize reached\n"; 50 | } 51 | // We know array index from 0 and maxSize starts from 1 52 | return stack->top == stack->maxSize - 1; 53 | } 54 | 55 | // if Stack is empty when top is equal to -1 and return true 56 | int stackEmpty (struct Stack *stack) 57 | { 58 | return stack->top == -1; 59 | } 60 | 61 | // Push function it inserts value in stack and increments stack top by 1 62 | void pushElement (struct Stack *stack, int item) 63 | { 64 | if (stackFull (stack)) 65 | return; 66 | stack->array[++stack->top] = item; 67 | } 68 | 69 | // pop Function it remove an item from stack and decreases top by 1 70 | int popElement (struct Stack *stack) 71 | { 72 | if (stackEmpty (stack)) 73 | return INT_MIN; 74 | return stack->array[stack->top--]; 75 | } 76 | 77 | // Function to return the top from stack without removing it 78 | int peekElement (struct Stack *stack) 79 | { 80 | if (stackEmpty (stack)) 81 | return INT_MIN; 82 | return stack->array[stack->top]; 83 | } 84 | 85 | // A function check the given character is operand 86 | int checkOperand (char ch) 87 | { 88 | return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'); 89 | } 90 | 91 | // Fucntion to compare precedence if return larger value means higher precedence 92 | int precedence (char ch) 93 | { 94 | switch (ch) 95 | { 96 | case '+': 97 | case '-': 98 | return 1; 99 | 100 | case '*': 101 | case '/': 102 | return 2; 103 | 104 | case '^': 105 | return 3; 106 | } 107 | return -1; 108 | } 109 | 110 | // The function for infix to postfix conversion 111 | int postfix (char *expression) 112 | { 113 | int i, j; 114 | struct Stack *stack = create (strlen (expression)); 115 | if (!stack) 116 | return -1; 117 | 118 | for (i = 0, j = -1; expression[i]; ++i) 119 | { 120 | // checking the character we scanned is operand or not 121 | if (checkOperand (expression[i])) 122 | expression[++j] = expression[i]; 123 | 124 | // if we scan character push it to the stack 125 | else if (expression[i] == '(') 126 | pushElement (stack, expression[i]); 127 | 128 | //if we scan character we need to pop and print from the stack 129 | else if (expression[i] == ')') 130 | { 131 | while (!stackEmpty (stack) && peekElement (stack) != '(') 132 | expression[++j] = popElement (stack); 133 | if (!stackEmpty (stack) && peekElement (stack) != '(') 134 | return -1; // invalid expression 135 | else 136 | popElement (stack); 137 | } 138 | else // if an operator 139 | { 140 | while (!stackEmpty (stack) 141 | && precedence (expression[i]) <= 142 | precedence (peekElement (stack))) 143 | expression[++j] = popElement (stack); 144 | pushElement (stack, expression[i]); 145 | } 146 | 147 | } 148 | 149 | // if all first expression characters are scanned 150 | // adding all left elements from stack to expression 151 | while (!stackEmpty (stack)) 152 | expression[++j] = popElement (stack); 153 | expression[++j] = '\0'; 154 | 155 | return 0; 156 | } 157 | 158 | void reverse (char *exp) 159 | { //reverse function for expression 160 | 161 | int size = strlen (exp); 162 | int j = size, i = 0; 163 | char temp[size]; 164 | 165 | temp[j--] = '\0'; 166 | while (exp[i] != '\0') 167 | { 168 | temp[j] = exp[i]; 169 | j--; 170 | i++; 171 | } 172 | strcpy (exp, temp); 173 | } 174 | 175 | void brackets (char *exp) 176 | { 177 | int i = 0; 178 | while (exp[i] != '\0') 179 | { 180 | if (exp[i] == '(') 181 | exp[i] = ')'; 182 | else if (exp[i] == ')') 183 | exp[i] = '('; 184 | i++; 185 | } 186 | } 187 | 188 | void conversionInfixToPrefix (char *exp) 189 | { 190 | int size = strlen (exp); 191 | reverse (exp); 192 | brackets (exp); 193 | postfix (exp); 194 | reverse (exp); 195 | } -------------------------------------------------------------------------------- /Hacktoberfest'22_PR6: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define D4 6 5 | #define D5 7 6 | #define D6 8 7 | #define D7 9 8 | #define RS 12 9 | #define EN 11 10 | 11 | #define Player_1_moveUpButton 5 12 | #define Player_1_moveDownButton 10 13 | #define Player_2_moveUpButton 3 14 | #define Player_2_moveDownButton 2 15 | 16 | #define Player_1 1 17 | #define Player_2 2 18 | 19 | #define DiagonalballUpdateTime 21 20 | #define HorizontalballUpdateTime 15 21 | 22 | #define Start_X 35 23 | #define Start_Y 7 24 | 25 | #define Button_Pressed (p1_UpButState | p1_DownButState | p2_UpButState | p2_DownButState) 26 | 27 | void(* resetFunc) (void) = 0; 28 | 29 | volatile boolean x_Up = true; 30 | volatile boolean x_Down = true; 31 | 32 | LiquidCrystal lcd(RS, EN, D4, D5, D6, D7); 33 | 34 | class Paddle 35 | { 36 | public: 37 | uint8_t PaddleColArray[16] = {0,0,0,0,0,4,4,4,0,0,0,0,0,0,0,0}; 38 | 39 | uint8_t PaddlePos = 6; 40 | uint8_t Score = 0; 41 | void MovePaddleUp() 42 | { 43 | if(PaddlePos != 1) 44 | { 45 | PaddlePos--; 46 | PaddleColArray[PaddlePos+2]=0; 47 | PaddleColArray[PaddlePos-1]=4; 48 | } 49 | } 50 | 51 | void MovePaddleDown() 52 | { 53 | if(PaddlePos != 14) 54 | { 55 | PaddlePos++; 56 | PaddleColArray[PaddlePos-2]=0; 57 | PaddleColArray[PaddlePos+1]=4; 58 | } 59 | } 60 | 61 | void PrintPaddles(uint8_t Player_Num) 62 | { 63 | if(Player_Num == 2) 64 | { 65 | lcd.createChar(0, PaddleColArray); 66 | lcd.createChar(1, PaddleColArray+8); 67 | 68 | lcd.setCursor(14, 0); 69 | lcd.write(byte(0)); 70 | 71 | lcd.setCursor(14, 1); 72 | lcd.write(byte(1)); 73 | } 74 | 75 | else 76 | { 77 | lcd.createChar(2, PaddleColArray); 78 | lcd.createChar(3, PaddleColArray+8); 79 | 80 | lcd.setCursor(1, 0); 81 | lcd.write(byte(2)); 82 | 83 | lcd.setCursor(1, 1); 84 | lcd.write(byte(3)); 85 | } 86 | } 87 | }; 88 | 89 | Paddle p1, p2; 90 | 91 | 92 | class Print_Game 93 | { 94 | public: 95 | 96 | void Start_Game() 97 | { 98 | lcd.print(F(" FUN PONG ")); 99 | 100 | lcd.setCursor(0, 1); 101 | lcd.print(F(" PRESS A BUTTON ")); 102 | 103 | uint8_t p1_UpButState = 0; 104 | uint8_t p1_DownButState = 0; 105 | uint8_t p2_UpButState = 0; 106 | uint8_t p2_DownButState = 0; 107 | 108 | while(!(Button_Pressed)) 109 | { 110 | p1_UpButState = ((PIND & (1 << Player_1_moveUpButton)) ); 111 | p1_DownButState = ((PINB & (1 << (Player_1_moveDownButton-8))) ); 112 | p2_UpButState = ((PIND & (1 << Player_2_moveUpButton)) ); 113 | p2_DownButState = ((PIND & (1 << Player_2_moveDownButton)) ); 114 | } 115 | lcd.clear(); 116 | } 117 | 118 | void Print_Score() 119 | { 120 | lcd.clear(); 121 | lcd.print(F("PLAYER1 PLAYER2")); 122 | lcd.setCursor(3 ,1); 123 | lcd.print(p1.Score); 124 | lcd.setCursor(12 ,1); 125 | lcd.print(p2.Score); 126 | 127 | delay(2000); 128 | 129 | lcd.clear(); 130 | } 131 | 132 | void Print_Winner(int Player_Num) 133 | { 134 | lcd.setCursor(0 ,0); 135 | lcd.print(F(" GAME OVER ")); 136 | lcd.setCursor(1, 1); 137 | lcd.print(F("PLAYER ")); 138 | lcd.print(Player_Num); 139 | lcd.setCursor(11 ,1); 140 | lcd.print(F("WINS")); 141 | 142 | delay(5000); 143 | 144 | resetFunc(); 145 | } 146 | }; 147 | 148 | Print_Game g; 149 | 150 | class Ball 151 | { 152 | private: 153 | 154 | uint8_t Point_Scored = 0; 155 | 156 | uint8_t ballYDir = 0; 157 | uint8_t ballXDir = -1; 158 | uint8_t ballY = Start_Y; 159 | uint8_t ballX = Start_X; 160 | 161 | uint8_t ballCharArray[8] = {0, 0, 0, 0, 0, 0, 0, 16}; 162 | 163 | public: 164 | 165 | void GenerateBallArray(); 166 | 167 | void PrintBall(); 168 | 169 | void UpdateBall(uint8_t , uint8_t); 170 | 171 | void AwardAPoint(); 172 | }; 173 | 174 | void Ball :: GenerateBallArray() 175 | { 176 | for(uint8_t i=0; i<8; i++) 177 | { 178 | if(i == (ballY % 8)) 179 | { 180 | ballCharArray[i] = 2 << (4 - (ballX % 5)); 181 | } 182 | else 183 | { 184 | ballCharArray[i] = 0; 185 | } 186 | } 187 | } 188 | 189 | void Ball :: PrintBall() 190 | { 191 | uint8_t LCDCol = ballX / 5; 192 | 193 | uint8_t LCDRow = (ballY <= 7) ? 0 : 1; 194 | 195 | lcd.createChar(4, ballCharArray); 196 | 197 | lcd.setCursor(LCDCol,LCDRow); 198 | 199 | lcd.write(byte(4)); 200 | } 201 | 202 | void Ball :: UpdateBall(uint8_t P1_PaddlePos, uint8_t P2_PaddlePos) 203 | { 204 | if(ballYDir) 205 | { 206 | delay(DiagonalballUpdateTime); 207 | } 208 | else 209 | { 210 | delay(HorizontalballUpdateTime); 211 | } 212 | 213 | if((ballX <= 6) || (ballX >= 73)) 214 | { 215 | AwardAPoint(); 216 | } 217 | 218 | else if(ballX == 72) 219 | { 220 | if(ballY == P2_PaddlePos) 221 | { 222 | ballXDir = -1; 223 | } 224 | 225 | else if(ballY == (P2_PaddlePos + 1)) 226 | { 227 | ballXDir = -1; 228 | if(ballY == 15) 229 | { 230 | ballYDir = -1; 231 | } 232 | else 233 | { 234 | ballYDir = 1; 235 | } 236 | } 237 | 238 | else if(ballY == (P2_PaddlePos - 1)){ 239 | ballXDir = -1; 240 | if(ballY == 0) 241 | { 242 | ballYDir = 1; 243 | } 244 | else 245 | { 246 | ballYDir = -1; 247 | } 248 | } 249 | } 250 | 251 | else if(ballX == 7) 252 | { 253 | if(ballY == P1_PaddlePos) 254 | { 255 | ballXDir = 1; 256 | } 257 | 258 | else if(ballY == (P1_PaddlePos + 1)){ 259 | ballXDir = 1; 260 | if(ballY == 15) 261 | { 262 | ballYDir = -1; 263 | } 264 | else 265 | { 266 | ballYDir = 1; 267 | } 268 | } 269 | 270 | else if(ballY == (P1_PaddlePos - 1)) 271 | { 272 | ballXDir = 1; 273 | if(ballY == 0) 274 | { 275 | ballYDir = 1; 276 | } 277 | else 278 | { 279 | ballYDir = -1; 280 | } 281 | } 282 | } 283 | 284 | else if((ballY == 0) || (ballY == 15)) 285 | { 286 | ballYDir *= -1; 287 | } 288 | 289 | if(Point_Scored == 1) 290 | { 291 | ballX = Start_X; 292 | ballY = Start_Y; 293 | ballXDir *= -1; 294 | ballYDir = 0; 295 | 296 | p1.PaddlePos = 6; 297 | p2.PaddlePos = 6; 298 | 299 | for(uint8_t i=0; i<16; i++) 300 | { 301 | if((i==5) || (i==6) || (i==7)) 302 | { 303 | p1.PaddleColArray[i] = 4; 304 | p2.PaddleColArray[i] = 4; 305 | } 306 | else 307 | { 308 | p1.PaddleColArray[i] = 0; 309 | p2.PaddleColArray[i] = 0; 310 | } 311 | } 312 | 313 | Point_Scored = 0; 314 | } 315 | 316 | uint8_t LCDCol = ballX / 5; 317 | uint8_t LCDRow = (ballY <= 7) ? 0 : 1; 318 | lcd.setCursor(LCDCol, LCDRow); 319 | lcd.print(" "); 320 | 321 | ballX += ballXDir; 322 | ballY += ballYDir; 323 | 324 | GenerateBallArray(); 325 | 326 | PrintBall(); 327 | } 328 | 329 | void Ball :: AwardAPoint() 330 | { 331 | if(ballX <= 8) 332 | { 333 | p2.Score++; 334 | } 335 | 336 | else 337 | { 338 | p1.Score++; 339 | } 340 | 341 | 342 | if(p1.Score == 5) 343 | { 344 | g.Print_Winner(Player_1); 345 | } 346 | 347 | else if(p2.Score == 5) 348 | { 349 | g.Print_Winner(Player_2); 350 | } 351 | 352 | g.Print_Score(); 353 | 354 | Point_Scored = 1; 355 | } 356 | 357 | Ball b; 358 | 359 | 360 | void setup() 361 | { 362 | lcd.begin(16, 2); 363 | 364 | DDRD &= ~(1<