├── C codes ├── pattern7.c ├── palindrome.c ├── prachi.cpp ├── pattern5.c ├── pattern1.c ├── pattern2.c ├── pattern6.c ├── Factorial.c ├── factorial.c ├── pattern3.c ├── SumAve.c ├── pattern.c ├── pattern4.c ├── Hello_name ├── pi-rate14_multiplication_table.cpp ├── SumOfDigits.c ├── Factors.c ├── EvenorOddNo.c ├── swap_without_third_var.c ├── AbsoluteNumber.c ├── BinaryToDecimal.c ├── Armstrong.c ├── MultiplyTwoNo.c ├── FibonacciSeriesUptoNTerms.c ├── tower of hanoi.c ├── DecimalToBinary.c ├── prime_number.c ├── SizeofVariables.c ├── linked list ├── FibonacciRecursion.c ├── alphabet-triangle.c ├── fibonacciTriangle.c ├── Reverse-array.c ├── Reverse.c ├── Tower_Of_Hanoi.c ├── CapitalorSmall.c ├── Armstrong Number.c ├── Dynamic Memory Allocation of Array.c ├── LargestNoAmong3No.c ├── selectionSort.c ├── SparseMatrix.c ├── LCM.c ├── ArrayReversal.c ├── intToRoman.c ├── romanToInt.c ├── HCF.c ├── RepeatedDigit.c ├── vector_comparator.c ├── binary search ├── Linked List in C.c ├── sudoku .c ├── delete_nodes.c ├── Stackoperations.c ├── SquareMatrix.c ├── file_writing with structures.c ├── message_encrypter.c ├── Mean_Mode_Median.c ├── substitution.c ├── linked_list_sum .c └── manojbank.c ├── hello.world_SmarthGuy.py ├── hello_world_abhishekdey4444.py ├── Reverse_a_number.py ├── infinite-loop.c ├── Lucky.md ├── CONTRIBUTORS.md ├── n_dice.py ├── StackSTL.cpp ├── factors.py ├── Geometric_Progresion.py ├── pascal_triangle.py ├── String.cpp ├── Flatten.cpp ├── hello_world_cla.py ├── random_alphanumeric.c ├── fibo.cpp ├── Fibonacci.c ├── Call by value and call by reference.c ├── decimaltobinary.c ├── inheritance.cpp ├── kth symbol in grammar.cpp ├── SwappingNodes.cpp ├── First_Duplicate_In_Array.cpp ├── SortString.cpp ├── Sorting ├── C++ │ ├── AnandSort.cpp │ ├── Insertion_sort.cpp │ ├── README.md │ ├── binarySearch.cpp │ ├── BubbleSort.cpp │ ├── ShellSort.cpp │ ├── CombSort.cpp │ ├── MergeSort.cpp │ ├── QuickSort.cpp │ ├── BucketSort.cpp │ ├── HeapSort.cpp │ ├── RadixSort.cpp │ ├── DoublyLinkedList.cpp │ └── Timsort.cpp ├── Python │ ├── InsertionSort.py │ ├── README.md │ ├── BubbleSort.py │ ├── SelectionSort.py │ └── HeapSort.py ├── C │ ├── README.md │ ├── ShellSort.c │ ├── BubbleSort.c │ ├── RadixSort.c │ ├── SelectionSort.c │ ├── CycleSort.c │ └── QuickSort.c └── Java │ ├── README.md │ ├── BubbleSort.md │ └── HeapSort.java ├── rearrange_array.cpp ├── Reverse-array.c ├── bubbleSort.c ├── TemperatureConverter.cpp ├── Swap2No.c ├── prime_factorisation.cpp ├── Searching └── C++ │ ├── Linear_search.cpp │ ├── Binary_search.cpp │ └── heap_sort.cpp ├── sieve_of_erantosthenes.cpp ├── main.cpp ├── Bubble_Sort.cpp ├── binary_search.c ├── game.c ├── Form ├── guess_number.cpp ├── prim.py ├── remove nth node from end of linked list.cpp ├── README.md ├── Swap nodes in Linked List.cpp ├── longestIncreasingSubsequence.cpp ├── encryption.cbp ├── InsertionSort.c ├── telegrambot.py ├── binary_search.java ├── main.js ├── jumbled_word.py ├── BellmanFord.py ├── Longest Increasing Subsequence Size (N log N).cpp ├── nth_node_deletion.cpp ├── krushkal.py ├── convert.cpp ├── decimal to hexa.c ├── QuickSort.java ├── form ├── MergeSort.java ├── bank_system1.cpp ├── .c ├── input_in_beginning.c ├── bfs.java ├── Reverse a Linked List in groups.java ├── Reversing,Palindrome,Armstrong and Strong number.CPP ├── kruskal.py ├── prim.c ├── paint.cpp ├── rps.cpp ├── Holly.CPP ├── Genetic Algorithm for Reinforcement Learning.py ├── Real time currency convertor using Tkinter.py ├── Add two numbers represented by linked lists.java └── Style.css /C codes/pattern7.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /hello.world_SmarthGuy.py: -------------------------------------------------------------------------------- 1 | print("hello world!") -------------------------------------------------------------------------------- /hello_world_abhishekdey4444.py: -------------------------------------------------------------------------------- 1 | print("hello world!") -------------------------------------------------------------------------------- /Reverse_a_number.py: -------------------------------------------------------------------------------- 1 | print("Reversed Number is",int(input("Enter number to be reversed")[::-1])) 2 | -------------------------------------------------------------------------------- /C codes/palindrome.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a; 5 | printf("Enter a number"); 6 | scanf("%d",&a); 7 | printf("The given number%d",a); 8 | } 9 | -------------------------------------------------------------------------------- /infinite-loop.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | 5 | for( ; ; ) { 6 | printf("This loop will run forever.\n"); 7 | } 8 | 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /Lucky.md: -------------------------------------------------------------------------------- 1 | Photo: https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQJLycr63PJOI8HRsGElo0QwUYVcEI7wkOz1w&usqp=CAU 2 | 3 | Location: India 4 | 5 | I will create this file for hacktoberfest, I hope you don't mind :) 6 | -------------------------------------------------------------------------------- /C codes/prachi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | float r,v; 6 | cin>>r; 7 | v= 4/3*3.14*r*r*r; 8 | cout<<"Voloume of Sphere"< 2 | int main() 3 | { 4 | int n; 5 | printf("Enter the limits : "); 6 | scanf("%d",&n); 7 | for(int i = n; i >= 1; i--) 8 | { 9 | for(int j = 1; j <= i; j++) 10 | { 11 | printf("*"); 12 | } 13 | printf("\n"); 14 | } 15 | } -------------------------------------------------------------------------------- /C codes/pattern1.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int n; 5 | printf("Enter the limits :"); 6 | scanf("%d",&n); 7 | for(int i = 1;i<=n;i++) 8 | { 9 | for(int j = 1;j<=i;j++) 10 | { 11 | printf("%d",j); 12 | } 13 | printf("\n"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /C codes/pattern2.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int n; 5 | printf("Enter the limits : "); 6 | scanf("%d",&n); 7 | for(int i = 1; i <= n;i++) 8 | { 9 | for(int j = 1; j <= i;j++) 10 | { 11 | printf("%d",i); 12 | } 13 | printf("\n"); 14 | } 15 | } -------------------------------------------------------------------------------- /C codes/pattern6.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n; 5 | printf("Enter the limits : "); 6 | scanf("%d",&n); 7 | for(int i = n ; i >= 1; i--) 8 | { 9 | for(int j = 1; j <= i; j++) 10 | { 11 | printf("*"); 12 | } 13 | printf("\n"); 14 | } 15 | } -------------------------------------------------------------------------------- /C codes/Factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char const *argv[]) 3 | { 4 | int n,f = 1; 5 | printf("Enter a number : "); 6 | scanf("%d",&n); 7 | for(int i = 1; i <= n; i++) 8 | { 9 | f = f*i; 10 | } 11 | printf("Factorial is : %d",f); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C codes/factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char const *argv[]) 3 | { 4 | int n,f = 1; 5 | printf("Enter a number : "); 6 | scanf("%d",&n); 7 | for(int i = 1; i <= n; i++) 8 | { 9 | f = f*i; 10 | } 11 | printf("Factorial is : %d",f); 12 | return 0; 13 | } -------------------------------------------------------------------------------- /C codes/pattern3.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int n; 5 | printf("Enter the limits : "); 6 | scanf("%d",&n); 7 | 8 | for(int i = 1; i<=n;i++) 9 | { 10 | for(int j = 1; j<=i;j++) 11 | { 12 | printf("%d",j%2); 13 | } 14 | printf("\n"); 15 | } 16 | } -------------------------------------------------------------------------------- /C codes/SumAve.c: -------------------------------------------------------------------------------- 1 | #include 2 | void main() 3 | { 4 | int a,b,s; 5 | double av; 6 | printf("Enter two numbers: "); 7 | scanf("%d%d",&a,&b); 8 | s = a+b; 9 | printf("\nThe Summation is : %d",s); 10 | av = s/2.0; 11 | printf("\nThe Average is : %f",av); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /C codes/pattern.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int n,i,j; 5 | printf("\nEnter the limits : "); 6 | scanf("%d",&n); 7 | for(i = 1;i<=n;i++) 8 | { 9 | for(j = 1;j<=i;j++) 10 | { 11 | printf("*"); 12 | } 13 | printf("\n"); 14 | } 15 | //printf("\n"); 16 | } -------------------------------------------------------------------------------- /C codes/pattern4.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int n; 5 | printf("Enter the limits :"); 6 | scanf("%d",&n); 7 | for(int i = 1; i <= n; i++) 8 | { 9 | for(int j = 1; j <= i; j++) 10 | { 11 | printf("%c",(j+64)); 12 | } 13 | printf("\n"); 14 | } 15 | } -------------------------------------------------------------------------------- /C codes/Hello_name: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main () { 4 | char str[30]="Hello "; 5 | char name[20]; 6 | int j=0, i=0; 7 | 8 | printf("What's your name?\n"); 9 | scanf("%s", name); 10 | while (name[j]!='\0'){ 11 | str[j+6]=name[j++]; 12 | } 13 | printf("%s\n", str); 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /C codes/pi-rate14_multiplication_table.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace :: std; 3 | int main() 4 | { 5 | int n; 6 | cout<<"enter number: "; 7 | cin >>n; 8 | for(int i=1;i<=10;i++) 9 | { 10 | cout< 2 | int main() { 3 | int num, i; 4 | printf("Enter a positive integer: "); 5 | scanf("%d", &num); 6 | printf("Factors of %d are: ", num); 7 | for (i = 1; i <= num; ++i) { 8 | if (num % i == 0) { 9 | printf("%d ", i); 10 | } 11 | } 12 | return 0; 13 | } -------------------------------------------------------------------------------- /factors.py: -------------------------------------------------------------------------------- 1 | # Python Program to find the factors of a number 2 | 3 | # This function computes the factor of the argument passed 4 | def print_factors(x): 5 | print("The factors of",x,"are:") 6 | for i in range(1, x + 1): 7 | if x % i == 0: 8 | print(i) 9 | 10 | num = int(input("Enter a Number")) 11 | 12 | print_factors(num) 13 | -------------------------------------------------------------------------------- /C codes/EvenorOddNo.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int num; 4 | printf("Enter an integer: "); 5 | scanf("%d", &num); 6 | 7 | // True if num is perfectly divisible by 2 8 | if(num % 2 == 0) 9 | printf("%d is even.", num); 10 | else 11 | printf("%d is odd.", num); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /C codes/swap_without_third_var.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int a=10, b=20; 5 | printf("Before swap a=%d b=%d",a,b); 6 | a=a+b;//a=30 (10+20) 7 | b=a-b;//b=10 (30-20) 8 | a=a-b;//a=20 (30-10) 9 | printf("\nAfter swap a=%d b=%d",a,b); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /Geometric_Progresion.py: -------------------------------------------------------------------------------- 1 | #program to print GP. 2 | 3 | def GP(a, r, n): 4 | for i in range(0, n): 5 | current_term = a * pow(r, i) 6 | print(current_term, end =" ") 7 | 8 | 9 | # Driver code 10 | 11 | a = 2 # starting number 12 | r = 3 # Common ratio 13 | n = 5 # N th term to be find 14 | 15 | GP(a, r, n) 16 | -------------------------------------------------------------------------------- /C codes/AbsoluteNumber.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char const *argv[]) 3 | { 4 | int num; 5 | printf("Enter a number : "); 6 | scanf("%d",&num); 7 | if(num>=0) 8 | { 9 | printf("The absolute number is %d",num); 10 | } 11 | else 12 | { 13 | num = num *(-1); 14 | printf("The absolute number is %d",num); 15 | } 16 | 17 | return 0; 18 | } -------------------------------------------------------------------------------- /C codes/BinaryToDecimal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | long int i,n,x=0,a; 6 | printf("Enter any binary number: "); 7 | scanf("%ld",&n); 8 | printf("\nThe decimal conversion of %ld is ",n); 9 | for(i=0;n!=0;++i) 10 | { 11 | a=n%10; 12 | x=(a)*(pow(2,i))+x; 13 | n=n/10; 14 | } 15 | printf("%ld",x); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /pascal_triangle.py: -------------------------------------------------------------------------------- 1 | row=int(input("Enter number of rows to print")) 2 | a=[1] 3 | p=[] 4 | for i in range (row+1): 5 | 6 | a.extend(p) 7 | print(" ".join([str(i) for i in a])) 8 | del (p) 9 | p=[1] 10 | for b in range (i): 11 | if b<=(len(a)-1): 12 | p.extend([a[b]+a[b+1]]) 13 | p.append(1) 14 | del (a) 15 | a=[] 16 | -------------------------------------------------------------------------------- /String.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string str; 7 | 8 | // Get the string 9 | getline(cin, str); 10 | 11 | // Print the words 12 | istringstream ss(str); 13 | do { 14 | string word; 15 | ss >> word; 16 | cout << word << endl; 17 | } while (ss); 18 | } 19 | -------------------------------------------------------------------------------- /Flatten.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | TreeNode* prev=NULL; 4 | void flatten(TreeNode* root) { 5 | if(root==NULL){ 6 | return; 7 | } 8 | // bottom up approach 9 | flatten(root->right); 10 | flatten(root->left); 11 | root->right=prev; 12 | root->left=NULL; 13 | prev=root; 14 | } 15 | }; 16 | -------------------------------------------------------------------------------- /C codes/Armstrong.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int n,s,k,rem; 5 | printf("Enter a Number : \n"); 6 | scanf("%d",&n); 7 | k = n; 8 | while(n!=0) 9 | { 10 | rem = n%10; 11 | s = s + (rem*rem*rem); 12 | n/=10; 13 | } 14 | if(s==k) 15 | { 16 | printf("Armstrong Number"); 17 | } 18 | else 19 | { 20 | printf("Not Armstrong Number"); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /C codes/MultiplyTwoNo.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | double a, b, product; 4 | printf("Enter two numbers: "); 5 | scanf("%lf %lf", &a, &b); 6 | 7 | // Calculating product 8 | product = a * b; 9 | 10 | // Result up to 2 decimal point is displayed using %.2lf 11 | printf("Product = %.2lf", product); 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /hello_world_cla.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | 5 | if len(sys.argv) > 1: 6 | name = sys.argv[1] 7 | else: 8 | name = "" 9 | if len(name) < 1: 10 | print "Hello you! You supplied no name! Try starting this script with your name as a command line argument!" 11 | exit(0) 12 | else: 13 | print 'You did it! Hello', str(sys.argv[1]) 14 | exit(0) 15 | 16 | -------------------------------------------------------------------------------- /random_alphanumeric.c: -------------------------------------------------------------------------------- 1 | // This C program is used to generate random alphanumeric character 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | int main() 8 | { 9 | char a[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; 10 | int l = strlen(a); 11 | srand(time(NULL)); 12 | printf("%c\n", a[rand() % l]); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /C codes/FibonacciSeriesUptoNTerms.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int i, n, t1 = 0, t2 = 1, nextTerm; 4 | printf("Enter the number of terms: "); 5 | scanf("%d", &n); 6 | printf("Fibonacci Series: "); 7 | 8 | for (i = 1; i <= n; ++i) { 9 | printf("%d, ", t1); 10 | nextTerm = t1 + t2; 11 | t1 = t2; 12 | t2 = nextTerm; 13 | } 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /fibo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n1 = 0, n2 = 1, n3, i, number; 6 | cout << "Enter the number of elements: "; 7 | cin >> number; 8 | cout << n1 << " " << n2 << " "; 9 | for (i = 2; i < number; ++i) 10 | { 11 | n3 = n1 + n2; 12 | cout << n3 << " "; 13 | n1 = n2; 14 | n2 = n3; 15 | } 16 | return 0; 17 | } -------------------------------------------------------------------------------- /C codes/tower of hanoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void t(int t,char beg,char aux,char end); 4 | int main(){ 5 | printf("moves\n"); 6 | t(3,'a','b','c'); 7 | return 0; //n=3(no of disks) 8 | 9 | } 10 | void t(int n,char beg,char aux,char end){ 11 | if(n==1){ 12 | printf("%c-->%c\n",beg,end); 13 | 14 | } 15 | else{ 16 | t(n-1,beg,end,aux); 17 | t(1,beg,aux,end); 18 | t(n-1,aux,beg,end); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n1=0,n2=1,n3,i,number; 5 | printf("Enter the number of elements:"); 6 | scanf("%d",&number); 7 | printf("\n%d %d",n1,n2);//printing 0 and 1 8 | for(i=2;i 2 | int main() 3 | { 4 | int number,cnt,i; 5 | int bin[32]; 6 | printf("Enter decimal number: "); 7 | scanf("%d",&number); 8 | cnt=0; 9 | while(number>0) 10 | { 11 | bin[cnt]=number%2; 12 | number=number/2; 13 | cnt++; 14 | } 15 | printf("Binary value is: "); 16 | for(i=(cnt-1); i>=0;i--) 17 | printf("%d",bin[i]); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /C codes/prime_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n, i, m = 0, flag = 0; 5 | printf("Enter the number to check prime:"); 6 | scanf("%d", &n); 7 | m = n / 2; 8 | for (i = 2; i <= m; i++) 9 | { 10 | if (n % i == 0) 11 | { 12 | printf("Number is not prime"); 13 | flag = 1; 14 | break; 15 | } 16 | } 17 | if (flag == 0) 18 | printf("Number is prime"); 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Call by value and call by reference.c: -------------------------------------------------------------------------------- 1 | #include 2 | void change(int num) { 3 | printf("Before adding value inside function num=%d \n",num); 4 | num=num+10; 5 | printf("After adding value inside function num=%d \n", num); 6 | } 7 | int main() { 8 | int x=10; 9 | printf("Before function call x=%d \n", x); 10 | change(x);//passing value in function 11 | printf("After function call x=%d \n", x); 12 | return 0; 13 | } 14 | -------------------------------------------------------------------------------- /decimaltobinary.c: -------------------------------------------------------------------------------- 1 | //Program to convert given decimal number to binary number 2 | #include 3 | int main() 4 | { 5 | int a, b, c[100]; 6 | printf("Enter the number to convert into binary:\n"); 7 | scanf("%d", &a); 8 | for (b = 0; a > 0; b++) 9 | { 10 | c[b] = a % 2; 11 | a = a / 2; 12 | } 13 | 14 | printf("The binary number is:\n"); 15 | for (b = b - 1; b >= 0; b--) 16 | { 17 | printf("%d", c[b]); 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /inheritance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Mammal { 5 | public: 6 | Mammal() 7 | { 8 | cout << "Mammals can give direct birth." << endl; 9 | } 10 | }; 11 | 12 | class WingedAnimal { 13 | public: 14 | WingedAnimal() 15 | { 16 | cout << "Winged animal can flap." << endl; 17 | } 18 | }; 19 | 20 | class Bat: public Mammal, public WingedAnimal { 21 | 22 | }; 23 | 24 | int main() 25 | { 26 | Bat b1; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /kth symbol in grammar.cpp: -------------------------------------------------------------------------------- 1 | // Question Link: https://leetcode.com/problems/k-th-symbol-in-grammar/ 2 | 3 | class Solution { 4 | public: 5 | int kthGrammar(int n, int k) { 6 | 7 | if(n == 1 && k == 1) 8 | return 0; 9 | 10 | int length = pow(2, n-1); 11 | int mid = length / 2; 12 | 13 | if( k <= mid) 14 | return kthGrammar(n-1, k); 15 | else 16 | return !kthGrammar(n-1, k-mid); 17 | } 18 | }; 19 | -------------------------------------------------------------------------------- /C codes/SizeofVariables.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int intType; 4 | float floatType; 5 | double doubleType; 6 | char charType; 7 | 8 | // sizeof evaluates the size of a variable 9 | printf("Size of int: %zu bytes\n", sizeof(intType)); 10 | printf("Size of float: %zu bytes\n", sizeof(floatType)); 11 | printf("Size of double: %zu bytes\n", sizeof(doubleType)); 12 | printf("Size of char: %zu byte\n", sizeof(charType)); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /SwappingNodes.cpp: -------------------------------------------------------------------------------- 1 | 2 | class Solution { 3 | public: 4 | ListNode* swapNodes(ListNode* head, int k) { 5 | ListNode* temp=head; 6 | int i=1; 7 | while(inext; 9 | i++; 10 | } 11 | ListNode* t1=temp; 12 | ListNode* t2=head; 13 | while(temp->next!=NULL){ 14 | temp=temp->next; 15 | t2=t2->next; 16 | } 17 | swap(t2->val, t1->val); 18 | return head; 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /First_Duplicate_In_Array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int firstDuplicate(vector a) { 4 | unordered_set b; 5 | int res; 6 | bool present=false; 7 | 8 | for(int i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cin>>n; 10 | string s[100]; 11 | cin.get(); // to consume the next line char 12 | for(int i=0; i 2 | using namespace std; 3 | int main(){ 4 | int i,j,n,A[100]={0}; 5 | cout<<"Enter Size Of the Array: "; 6 | cin>>n; 7 | int B[n]; 8 | cout<<"Enter elements: "; 9 | for(i=0;i>B[i]; } 11 | for(i=0;i 2 | using namespace std; 3 | void reArrange(int Arr[],int n){ 4 | int j=0; 5 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | struct no{ 7 | int valor; 8 | struct *prox; 9 | }; 10 | typedef struct no no; 11 | 12 | no *criar(int x){ 13 | no *a; 14 | a = (no*) malloc(sizeof(no)); 15 | a->prox=NULL; 16 | a->valor=x; 17 | return a; 18 | } 19 | 20 | no *inserir(no *a,int x){ 21 | if(a==NULL){ 22 | return criar(x); 23 | } 24 | else{ 25 | a->prox = inserir(a->prox,x); 26 | } 27 | return a; 28 | } 29 | -------------------------------------------------------------------------------- /C codes/FibonacciRecursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fibonacci(int n){ 3 | if(n == 0){ 4 | return 0; 5 | } 6 | if(n == 1){ 7 | return 1; 8 | } 9 | return fibonacci(n-2) + fibonacci(n-1); 10 | } 11 | int main(){ 12 | printf("Please enter the number of fibonacci numbers you would like to see: "); 13 | int num;scanf("%d", &num); 14 | int f = fibonacci(num); 15 | printf("The fibonacci sequence is:\n"); 16 | for(int i = 0;i 2 | #include 3 | int main(){ 4 | int ch=65; 5 | int i,j,k,m; 6 | system("cls"); 7 | for(i=1;i<=5;i++) 8 | { 9 | for(j=5;j>=i;j--) 10 | printf(" "); 11 | for(k=1;k<=i;k++) 12 | printf("%c",ch++); 13 | ch--; 14 | for(m=1;m 2 | #include 3 | int main() 4 | { 5 | int a = 0, b = 1, i, c, n, j; 6 | system("cls"); 7 | printf("Enter the limit:"); 8 | scanf("%d", &n); 9 | for (i = 1; i <= n; i++) 10 | { 11 | a = 0; 12 | b = 1; 13 | printf("%d\t", b); 14 | for (j = 1; j < i; j++) 15 | { 16 | c = a + b; 17 | printf("%d\t", c); 18 | a = b; 19 | b = c; 20 | } 21 | printf("\n"); 22 | } 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Reverse-array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int c, d, n, a[100], b[100]; 6 | printf("\n\nEnter number of elements in array :"); 7 | scanf("%d", &n); 8 | printf("\n\nEnter %d elements\n", n); 9 | 10 | for(c = 0; c < n; c++) 11 | scanf("%d", &a[c]); 12 | 13 | for(c = n-1, d = 0; c >= 0; c--, d++) 14 | b[d] = a[c]; 15 | 16 | for(c = 0; c < n; c++) 17 | a[c] = b[c]; 18 | 19 | printf("\n\n Resultant array is: "); 20 | for(c = 0; c < n; c++) 21 | printf("%d", a[c]); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C codes/Reverse-array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int c, d, n, a[100], b[100]; 6 | printf("\n\nEnter number of elements in array :"); 7 | scanf("%d", &n); 8 | printf("\n\nEnter %d elements\n", n); 9 | 10 | for(c = 0; c < n; c++) 11 | scanf("%d", &a[c]); 12 | 13 | for(c = n-1, d = 0; c >= 0; c--, d++) 14 | b[d] = a[c]; 15 | 16 | for(c = 0; c < n; c++) 17 | a[c] = b[c]; 18 | 19 | printf("\n\n Resultant array is: "); 20 | for(c = 0; c < n; c++) 21 | printf("%d", a[c]); 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /C codes/Reverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(void) 3 | { 4 | int n,n1,q,r = 0; 5 | printf("Enter the number : "); 6 | scanf("%d",&n); 7 | //n1 = n%10; 8 | r = ((r*10)+n1); 9 | n/=10; 10 | printf("\nReverse of the number :%d",r); 11 | } 12 | /*#include 13 | int main() { 14 | int n, rev = 0, remainder; 15 | printf("Enter an integer: "); 16 | scanf("%d", &n); 17 | while (n != 0) { 18 | remainder = n % 10; 19 | rev = rev * 10 + remainder; 20 | n /= 10; 21 | } 22 | printf("Reversed number = %d", rev); 23 | return 0; 24 | }*/ 25 | -------------------------------------------------------------------------------- /C codes/Tower_Of_Hanoi.c: -------------------------------------------------------------------------------- 1 | // Tower Of Hanoi 2 | 3 | #include 4 | #include 5 | 6 | 7 | void TOH(int,char,char,char); 8 | 9 | 10 | int main() 11 | { 12 | int N; 13 | system("cls"); 14 | printf("Enter The Number of Disks\n"); 15 | scanf("%d",&N); 16 | TOH(N,'A','B','C'); 17 | return 0; 18 | } 19 | 20 | void TOH(int Disk,char First,char Mid,char Last) 21 | { 22 | if (Disk>0) 23 | { 24 | TOH(Disk-1,First,Last,Mid); 25 | printf("\t\n\t%c -> %c",First,Last); 26 | TOH(Disk-1,Mid,First,Last); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /C codes/CapitalorSmall.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(int argc, char const *argv[]) 3 | { 4 | char ch; 5 | //int z; 6 | printf("Enter a character : "); 7 | scanf("%c",&ch); 8 | //z = (int)ch; 9 | if(ch >= 65 && ch <= 90)// range will start from 65 not 67 10 | { 11 | printf("\n %c is a Capital Letter",ch); 12 | } 13 | else if(ch >= 97 && ch <= 122) 14 | { 15 | printf("\n %c is a Small Letter",ch); 16 | } 17 | else if(ch >= 48 && ch <= 57) 18 | { 19 | printf("\n %c is a Digit",ch); 20 | } 21 | else 22 | { 23 | printf("\n %c is a special character",ch); 24 | } 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /C codes/Armstrong Number.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int num, originalNum, remainder, result = 0; 5 | printf("Enter a three-digit integer: "); 6 | scanf("%d", &num); 7 | originalNum = num; 8 | 9 | while (originalNum != 0) 10 | { 11 | remainder = originalNum % 10; 12 | result += remainder * remainder * remainder; 13 | originalNum /= 10; 14 | } 15 | 16 | if (result == num) 17 | printf("%d is an Armstrong number.", num); 18 | else 19 | printf("%d is not an Armstrong number.", num); 20 | 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /C codes/Dynamic Memory Allocation of Array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include//Library required for malloc. 3 | int * fun(int n) //Function returns pointer pointing to the newly alocated array. 4 | { 5 | int *A; 6 | A=(int *)malloc(n*sizeof(int)); //In C we use malloc for dynamic memory allocation.Which allocates memory in heap(Free Store). 7 | int i; 8 | for( i=0;i 2 | #include 3 | 4 | void bubbleSort(int arr[], int n) 5 | { 6 | int i, j, tmp; 7 | for(i = 0; i < n - 1; i++) { 8 | for(j = 0; j < n - 1 - i; j++) { 9 | if (arr[j] > arr[j+1]) { 10 | tmp = arr[j]; 11 | arr[j] = arr[j+1]; 12 | arr[j+1] = tmp; 13 | } 14 | } 15 | } 16 | } 17 | 18 | int main() 19 | { 20 | int arr[] = {-5, 6, 87, 99, 50, -54, 0, 123, 4}; 21 | bubbleSort(arr, 9); 22 | 23 | for(int i = 0;i < 9;i++) { 24 | printf("%d ", arr[i]); 25 | } 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Sorting/C++/Insertion_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | main() 4 | { int s,i,j,temp; 5 | cout<<"enter Array Size"; 6 | cin>>s; 7 | int A[s]; 8 | cout<<"enter Array Elements"; 9 | for(i=0;i>A[i]; 12 | } 13 | for(i=1;i=0 && A[j]>temp) // by changing > sign to < sign we will get in decending order 17 | { 18 | A[j+1]=A[j]; 19 | j--; 20 | } 21 | A[j+1]=temp; 22 | } 23 | cout<<"sorted element are"; 24 | for(i=0;i 10 | 11 | using namespace std; 12 | 13 | int main() 14 | { 15 | int f{0},c; 16 | while(f<=300) 17 | { 18 | c=(5*(f-32))/9; 19 | cout<= 0 and key < arr[j]: 10 | arr[j + 1] = arr[j] 11 | j = j - 1 12 | arr[j + 1] = key 13 | 14 | # Driver function 15 | if __name__ == '__main__': 16 | 17 | nums=list(map(int,input().split())) 18 | insertion_sort(nums) # Calling the insertion_sort function by passing the 'nums' list 19 | 20 | # Printing the sorted list 21 | print(nums) 22 | -------------------------------------------------------------------------------- /Swap2No.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | int first, second, temp; 4 | printf("Enter first number: "); 5 | scanf("%d", &first); 6 | printf("Enter second number: "); 7 | scanf("%d", &second); 8 | 9 | // Value of first is assigned to temp 10 | temp = first; 11 | 12 | // Value of second is assigned to first 13 | first = second; 14 | 15 | // Value of temp (initial value of first) is assigned to second 16 | second = temp; 17 | 18 | printf("\nAfter swapping, firstNumber = %d\n", first); 19 | printf("After swapping, secondNumber = %d", second); 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Sorting/Python/README.md: -------------------------------------------------------------------------------- 1 | # Sorting Algos in _Python_ 2 | - Give proper file names. (_PascalCasing_ is required) 3 | - ``` 4 | XyzSort.py 5 | ``` 6 | 7 | - Functional programming is must. 8 | - ``` 9 | func(a, b) 10 | 11 | def func(a, b) 12 | ``` 13 | 14 | - Proper commenting is recommended. 15 | - ``` 16 | // a function to specify the swapping of variables 17 | 18 | or 19 | 20 | /* a function to specify the swapping of variables */ 21 | ``` 22 | 23 | - Try to be as legit as you can. Learn, understand and then code. 🙏 24 | 25 | ### P.S.: Please adhere to the above mentioned criterias for successfull contribution and PR acceptance. -------------------------------------------------------------------------------- /Sorting/C/README.md: -------------------------------------------------------------------------------- 1 | # Sorting Algos in _C_ 2 | - Give proper file names. (_PascalCasing_ is required) 3 | - ``` 4 | XyzSort.c 5 | ``` 6 | 7 | - Functional programming is must. 8 | - ``` 9 | int main() { ... func(); } 10 | void func() { ... } 11 | ``` 12 | 13 | - Proper commenting is recommended. 14 | - ``` 15 | // a function to specify the swapping of variables 16 | 17 | or 18 | 19 | /* a function to specify the swapping of variables */ 20 | ``` 21 | 22 | - Try to be as legit as you can. Learn, understand and then code. 🙏 23 | 24 | ### P.S.: Please adhere to the above mentioned criterias for successfull contribution and PR acceptance. -------------------------------------------------------------------------------- /Sorting/Python/BubbleSort.py: -------------------------------------------------------------------------------- 1 | # Creating a bubble sort function 2 | def bubble_sort(local): 3 | # Outer loop for traverse the entire list 4 | for i in range(0, len(local) - 1): 5 | for j in range(len(local) - 1): 6 | if (local[j] > local[j + 1]): 7 | temp = local[j] 8 | local[j] = local[j + 1] 9 | local[j + 1] = temp 10 | return local 11 | 12 | 13 | array = [5, 3, 8, 6, 7, 2] 14 | print("The unsorted list is: ", array) 15 | # Calling the bubble sort function 16 | print("The sorted list is: ", bubble_sort(array)) 17 | 18 | #Output 19 | #The unsorted list is: [5, 3, 8, 6, 7, 2] 20 | #The sorted list is: [2, 3, 5, 6, 7, 8] 21 | 22 | -------------------------------------------------------------------------------- /C codes/LargestNoAmong3No.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() { 3 | double n1, n2, n3; 4 | printf("Enter three different numbers: "); 5 | scanf("%lf %lf %lf", &n1, &n2, &n3); 6 | 7 | // if n1 is greater than both n2 and n3, n1 is the largest 8 | if (n1 >= n2 && n1 >= n3) 9 | printf("%.2f is the largest number.", n1); 10 | 11 | // if n2 is greater than both n1 and n3, n2 is the largest 12 | if (n2 >= n1 && n2 >= n3) 13 | printf("%.2f is the largest number.", n2); 14 | 15 | // if n3 is greater than both n1 and n2, n3 is the largest 16 | if (n3 >= n1 && n3 >= n2) 17 | printf("%.2f is the largest number.", n3); 18 | 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Sorting/C++/README.md: -------------------------------------------------------------------------------- 1 | # Sorting Algos in _C++_ 2 | - Give proper file names. (_PascalCasing_ is required) 3 | - ``` 4 | XyzSort.cpp 5 | ``` 6 | 7 | - Functional programming is must. 8 | - ``` 9 | int main() { ... func(); } 10 | void func() { ... } 11 | ``` 12 | 13 | - Proper commenting is recommended. 14 | - ``` 15 | // a function to specify the swapping of variables 16 | 17 | or 18 | 19 | /* a function to specify the swapping of variables */ 20 | ``` 21 | 22 | - Try to be as legit as you can. Learn, understand and then code. 🙏 23 | 24 | ### P.S.: Please adhere to the above mentioned criterias for successfull contribution and PR acceptance. -------------------------------------------------------------------------------- /C codes/selectionSort.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void swap(int *a, int *b) 5 | { 6 | int tmp = *a; 7 | *a = *b; 8 | *b = tmp; 9 | } 10 | 11 | void bubbleSort(int arr[], int n) 12 | { 13 | int i, j, tmp; 14 | for(i = 0; i < n - 1; i++) { 15 | int min = i; 16 | for(j = i + 1; j < n; j++) { 17 | if (arr[min] > arr[j]) { 18 | min = j; 19 | } 20 | } 21 | swap((arr + min), (arr + i)); 22 | } 23 | } 24 | 25 | int main() 26 | { 27 | int arr[] = {-5, 6, 87, 99, 50, -54, 0, 123, 4}; 28 | bubbleSort(arr, 9); 29 | 30 | for(int i = 0;i < 9;i++) { 31 | printf("%d ", arr[i]); 32 | } 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Sorting/Java/README.md: -------------------------------------------------------------------------------- 1 | # Sorting Algos in _Java_ 2 | - Give proper file names. (_PascalCasing_ is required) 3 | - ``` 4 | XyzSort.java 5 | ``` 6 | 7 | - Functional programming is must. 8 | - ``` 9 | public static void main(String[] args) { ... func(); } 10 | static void func() { ... } 11 | ``` 12 | 13 | - Proper commenting is recommended. 14 | - ``` 15 | // a function to specify the swapping of variables 16 | 17 | or 18 | 19 | /* a function to specify the swapping of variables */ 20 | ``` 21 | 22 | - Try to be as legit as you can. Learn, understand and then code. 🙏 23 | 24 | ### P.S.: Please adhere to the above mentioned criterias for successfull contribution and PR acceptance. -------------------------------------------------------------------------------- /prime_factorisation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #define ll long long 5 | 6 | vector p_fact(ll n) 7 | { 8 | vector v; 9 | if (n % 2 == 0) 10 | { 11 | while (n % 2 == 0) 12 | { 13 | v.push_back(2); 14 | n /= 2; 15 | } 16 | } 17 | for (int i = 3; i * i <= n; i += 2) 18 | { 19 | if (n % i == 0) 20 | { 21 | while (n % i == 0) 22 | { 23 | v.push_back(i); 24 | n /= i; 25 | } 26 | } 27 | } 28 | if (n != 1) 29 | { 30 | v.push_back(n); 31 | } 32 | return v; 33 | } 34 | 35 | int main() 36 | { 37 | ll n; 38 | cin >> n; 39 | vector v; 40 | v = p_fact(n); 41 | for (int i = 0; i < v.size(); ++i) 42 | { 43 | cout << v[i] << " "; 44 | } 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /Sorting/C++/binarySearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | int search(vector& nums, int target) { 8 | int k = 0; 9 | int n = nums.size(); 10 | for(int b = n / 2; b >= 1; b /= 2) 11 | { 12 | while(k+b < n && nums[k+b] <= target) 13 | k += b; 14 | } 15 | 16 | if (nums[k] == target) 17 | { 18 | return k; 19 | } 20 | 21 | return -1; 22 | } 23 | }; 24 | 25 | int main() 26 | { 27 | Solution s1; 28 | //int t; 29 | vector vec = {-1,0,3,5,9,12}; 30 | cout << s1.search(vec, 9); 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Searching/C++/Linear_search.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int search(int arr[], int n, int x) 5 | { 6 | int i; 7 | for (i = 0; i < n; i++) 8 | if (arr[i] == x) 9 | return i; 10 | return -1; 11 | } 12 | 13 | int main() 14 | { 15 | int i, n, x; 16 | cout << "Enter array size: "; 17 | cin >> n; 18 | int a[n]; 19 | cout << "Enter array elements: "; 20 | for (i = 0; i < n; i++) 21 | cin >> a[i]; 22 | cout << "Enter element to be searched: "; 23 | cin >> x; 24 | int result = search(a, n, x); 25 | if (result == -1) 26 | cout << x << " is not found."; 27 | else 28 | cout << x << " is found at position " << result + 1 << " in the array"; 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /C codes/SparseMatrix.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void main () 4 | { 5 | int matrix[10][10]; 6 | int i, j, m, n; 7 | int c = 0; 8 | 9 | printf("Enter order of the matix \n"); 10 | scanf("%d %d", &m, &n); 11 | printf("Enter elements of the matix \n"); 12 | for (i = 0; i < m; ++i) 13 | { 14 | for (j = 0; j < n; ++j) 15 | { 16 | scanf("%d", &matrix[i][j]); 17 | if (matrix[i][j] == 0) 18 | { 19 | ++c; 20 | } 21 | } 22 | } 23 | if (c > ((m * n) / 2)) 24 | { 25 | printf("The given matrix is Sparse Matrix \n"); 26 | } 27 | else 28 | printf("The given matrix is not a Sparse Matrix \n"); 29 | printf("There are %d number of Zeros.", c); 30 | } -------------------------------------------------------------------------------- /Sorting/Python/SelectionSort.py: -------------------------------------------------------------------------------- 1 | # Python program to implement Selection Sort 2 | 3 | def selection_sort(arr): 4 | # Traverse through all array elements 5 | for i in range(len(arr)): 6 | 7 | # Find the minimum element in remaining unsorted array 8 | min_idx = i 9 | for j in range(i + 1, len(arr)): 10 | if arr[min_idx] > arr[j]: 11 | min_idx = j 12 | 13 | # Swap the found minimum element with the first element 14 | arr[i], arr[min_idx] = arr[min_idx], arr[i] 15 | 16 | 17 | # Driver function 18 | if __name__ == '__main__': 19 | ls = list(map(int, input().split())) # Taking 'ls' list input as integers separated by space 20 | selection_sort(ls) # Calling the Selection_sort function by passing the 'ls' list 21 | 22 | # Printing the sorted list 23 | print(*ls) 24 | -------------------------------------------------------------------------------- /sieve_of_erantosthenes.cpp: -------------------------------------------------------------------------------- 1 | // Used to compute all primes upto n(n<=10^7). 2 | 3 | #include 4 | using namespace std; 5 | 6 | void soe(vector &v, int n) 7 | { 8 | for (int i = 0; i < n + 1; ++i) 9 | v[i] = true; 10 | v[0] = false; 11 | v[1] = false; 12 | for (int i = 2; i * i <= n + 1; ++i) 13 | { 14 | if (v[i] == true) 15 | { 16 | for (int j = 2 * i; j < n + 1; j += i) 17 | { 18 | v[j] = false; 19 | } 20 | } 21 | } 22 | } 23 | 24 | int main() 25 | { 26 | int n; 27 | cin >> n; 28 | vector v(n + 1); 29 | soe(v, n); 30 | for (int i = 0; i < n + 1; ++i) 31 | { 32 | if (v[i] == true) 33 | { 34 | cout << i << " "; 35 | } 36 | } 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Sorting/Java/BubbleSort.md: -------------------------------------------------------------------------------- 1 | ## Bubble Sort 2 | **There are various sorting algorithm available and Bubble sort is one of them.** 3 | * It is very simple and easy to understand sorting algorithm and the major steps involved in it is swapping of elements. 4 | * The worst time complexity is **O(n^2)**. 5 | * The best time complexity is **O(n)** 6 | * Best case occurs when the array is already sorted. 7 | * Space complexity for bubble sort is constant i.e. O(1). 8 | 9 | **Code for bubble sort** 10 | ``` 11 | public void BubbleSort(int Arr[]) 12 | { 13 | int n=Arr.length; //assigning Size of array to vairable n 14 | 15 | for(int i=1;iArr[j+1]) 18 | { 19 | int temp=Arr[j]; 20 | Arr[j]=Arr[j+1]; 21 | A[j+1]=temp; 22 | 23 | } 24 | 25 | 26 | } 27 | 28 | ``` 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /C codes/LCM.c: -------------------------------------------------------------------------------- 1 | // This C programme is used to find LCM of any number of terms 2 | 3 | #include 4 | 5 | int lcm(int arr[], int n) 6 | { 7 | int i = 0, fact = 1; 8 | while (fact) 9 | { 10 | int count = 0; 11 | i++; 12 | for (int j = 0; j < n; j++) 13 | { 14 | if (i % arr[j] == 0) 15 | { 16 | count++; 17 | } 18 | } 19 | if (count == n) 20 | fact = 0; 21 | } 22 | return i; 23 | } 24 | 25 | int main() 26 | { 27 | int n; 28 | printf("Enter the number of terms : "); 29 | scanf("%d", &n); 30 | int arr[n]; 31 | printf("Enter the numbers\n"); 32 | for (int i = 0; i < n; i++) 33 | { 34 | scanf("%d", &arr[i]); 35 | } 36 | int LCM = lcm(arr, n); 37 | printf("The LCM is %d\n", LCM); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | char txt[100],option; 8 | int key; 9 | cout<<"Enter plaintext : "; 10 | cin.getline(txt,100); 11 | cout<<"Enter key : "; 12 | cin>>key; 13 | reoptn: 14 | cout<<"Enter option ( e for encryption, d for decryption ) : "; 15 | cin>>option; 16 | 17 | if(option == 'e' || option == 'E') 18 | { 19 | for(int i = 0 ; txt[i] != '\0' ; i++) 20 | { 21 | txt[i] += key; 22 | } 23 | cout<<"Encrypted text : "< 2 | 3 | int main() 4 | { 5 | int c, d, n, a[100], b[100]; 6 | printf("\n\nEnter number of elements in array :"); 7 | scanf("%d", &n); 8 | printf("\n\nEnter %d elements\n", n); 9 | 10 | for(c = 0; c < n; c++) 11 | scanf("%d", &a[c]); 12 | 13 | /* 14 | temporarily storing elements into array b 15 | starting from end of array a 16 | */ 17 | for(c = n-1, d = 0; c >= 0; c--, d++) 18 | b[d] = a[c]; 19 | 20 | /* 21 | copying reversed array into original. 22 | Here we are modifying original array to reverse it. 23 | */ 24 | 25 | for(c = 0; c < n; c++) 26 | a[c] = b[c]; 27 | 28 | printf("\n\n Resultant array is: "); 29 | for(c = 0; c < n; c++) 30 | printf("%d", a[c]); 31 | 32 | printf("\n\n\t\t\tCoding is Fun !\n\n\n"); 33 | return 0; 34 | } -------------------------------------------------------------------------------- /Bubble_Sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void swap(int *xp, int *yp) 5 | { 6 | int temp = *xp; 7 | *xp = *yp; 8 | *yp = temp; 9 | } 10 | 11 | void bubbleSort(int arr[], int n) 12 | { 13 | int i, j; 14 | for (i = 0; i < n-1; i++) 15 | 16 | for (j = 0; j < n-i-1; j++) 17 | if (arr[j] > arr[j+1]) 18 | swap(&arr[j], &arr[j+1]); 19 | } 20 | 21 | void printArray(int arr[], int size) 22 | { 23 | int i; 24 | for (i=0; i < size; i++) 25 | printf("%d ", arr[i]); 26 | printf("\n"); 27 | } 28 | 29 | int main() 30 | { 31 | int arr[500],n,i; 32 | 33 | cout<<"Enter the numbber of elements: "; 34 | cin>>n; 35 | 36 | cout<<"Enter the numbers:\n"; 37 | for(i=0;i>arr[i]; 39 | 40 | bubbleSort(arr, n); 41 | cout<<"Sorted array: \n"; 42 | printArray(arr, n); 43 | return 0; 44 | } -------------------------------------------------------------------------------- /C codes/intToRoman.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const char *thousands[4] = {"", "M", "MM", "MMM"}; 4 | const char *hundreds[10] = {"", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM"}; 5 | const char *tens[10] = {"", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC"}; 6 | const char *ones[10] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX"}; 7 | 8 | char *intToRoman(int num){ 9 | char *roman = malloc(16); 10 | int index1000, index100, index10, index1; 11 | index1000 = num / 1000; 12 | index100 = (num % 1000) / 100; 13 | index10 = (num % 100) / 10; 14 | index1 = (num % 10); 15 | strcpy(roman, thousands[index1000]); 16 | strcat(roman, hundreds[index100]); 17 | strcat(roman, tens[index10]); 18 | strcat(roman, ones[index1]); 19 | return roman; 20 | } 21 | 22 | int main() 23 | { 24 | printf("%s\n",intToRoman(1994)); 25 | return 0; 26 | } -------------------------------------------------------------------------------- /binary_search.c: -------------------------------------------------------------------------------- 1 | #include 2 | int binarySearch(int arr[], int l, int r, int x) 3 | { 4 | if (r >= l) { 5 | int mid = l + (r - l) / 2; 6 | if (arr[mid] == x) 7 | return mid; 8 | if (arr[mid] > x) 9 | return binarySearch(arr, l, mid - 1, x); 10 | return binarySearch(arr, mid + 1, r, x); 11 | } 12 | return -1; 13 | } 14 | 15 | int main(void) 16 | { int n,x; 17 | printf("\nenter array size : "); 18 | scanf("%d",&n); 19 | int a[n]; 20 | for(int i=0;i