From 95f6f064bc73dc5c94642542ef6aac7c8a6519f2 Mon Sep 17 00:00:00 2001 From: Mrdecent08 <60995685+Mrdecent08@users.noreply.github.com> Date: Tue, 13 Oct 2020 18:39:39 +0530 Subject: [PATCH 001/781] Create Bubble sort in c --- Bubble sort in c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Bubble sort in c diff --git a/Bubble sort in c b/Bubble sort in c new file mode 100644 index 00000000..97a6f877 --- /dev/null +++ b/Bubble sort in c @@ -0,0 +1,34 @@ +#include +void swap(int *k, int *l); +void main(){ + + int a[100],i,j,n,temp; + printf("enter number of elements"); + scanf("%d",&n); + for (i = 0; i < 5 ; i++) + { + scanf("%d",&a[i]); + } + for(i=0;ia[j+1]) + { + swap(&a[j],&a[j+1]); + } + + } + } + for (j = 0; j < n ; j++) + { + printf("%d ",a[j]); + } + +} +void swap(int *k,int *l){ + int temp; + temp=*k; + *k=*l; + *l=temp; +} From fa1521f070904a3f4173832e3c615ef0c26dc9d2 Mon Sep 17 00:00:00 2001 From: Anshita Varyani <67929122+Anshitavaryani@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:06:27 +0530 Subject: [PATCH 002/781] Create Sum of elements in array Optimized code for getting sum of elements in an array --- Sum of elements in array | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Sum of elements in array diff --git a/Sum of elements in array b/Sum of elements in array new file mode 100644 index 00000000..a41c0e06 --- /dev/null +++ b/Sum of elements in array @@ -0,0 +1,27 @@ +#include + #include + + +int main() +{ + int a[1000],i,n,sum=0; + + printf("Enter size of the array : "); + scanf("%d",&n); + + printf("Enter elements in array : "); + for(i=0; i Date: Thu, 15 Oct 2020 23:07:12 +0530 Subject: [PATCH 003/781] Create to find the largest element in an array to get the largest element in an array --- to find the largest element in an array | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 to find the largest element in an array diff --git a/to find the largest element in an array b/to find the largest element in an array new file mode 100644 index 00000000..75ccc198 --- /dev/null +++ b/to find the largest element in an array @@ -0,0 +1,14 @@ +# largest function +def largest(arr,n): + #maximum element + max = arr[0] + # traverse the whole loop + for i in range(1, n): + if arr[i] > max: + max = arr[i] + return max +# Driver Code +arr = [23,1,32,67,2,34,12] +n = len(arr) +Ans = largest(arr,n) +print ("Largest element given in array is",Ans) From 5f4e5ba8efc8953cba32ecc3ab6f28ecab47ac1a Mon Sep 17 00:00:00 2001 From: Samarth Pandey <58460493+innovator-creator-maker@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:10:27 +0530 Subject: [PATCH 004/781] Create to find the length of a string python code for getting the length of a string --- to find the length of a string | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 to find the length of a string diff --git a/to find the length of a string b/to find the length of a string new file mode 100644 index 00000000..e876e50f --- /dev/null +++ b/to find the length of a string @@ -0,0 +1,8 @@ +# User inputs the string and it gets stored in variable str +str = input("Enter a string: ") + +# counter variable to count the character in a string +counter = 0 +for s in str: + counter = counter+1 +print("Length of the input string is:", counter) From 58019c8a3f9b528f8153a1eba26c156f621b8eb0 Mon Sep 17 00:00:00 2001 From: Ritesh Sharma Date: Thu, 15 Oct 2020 23:12:45 +0530 Subject: [PATCH 005/781] Create Sum of Elements in array Code for finding the sum of elements in an array. --- Sum of Elements in array | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Sum of Elements in array diff --git a/Sum of Elements in array b/Sum of Elements in array new file mode 100644 index 00000000..1e7b8c64 --- /dev/null +++ b/Sum of Elements in array @@ -0,0 +1,22 @@ +#include +using namespace std; + + +int sum(int arr[], int n) +{ + int sum = 0; + + for (int i = 0; i < n; i++) + sum = sum + arr[i]; + + return sum; +} + + +int main() +{ + int Array1[] = {99, 99, 99, 99}; + int N = sizeof(Array1) / sizeof(Array1[0]); + cout << "Sum of given array is " << sum(Array1, N); + return 0; +} From 9c737a651be57a816b2f99984a4d105813f542b0 Mon Sep 17 00:00:00 2001 From: Samarth Pandey <58460493+innovator-creator-maker@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:15:54 +0530 Subject: [PATCH 006/781] Create to get the smallest element in the array to find the smallest element in the array --- to get the smallest element in the array | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 to get the smallest element in the array diff --git a/to get the smallest element in the array b/to get the smallest element in the array new file mode 100644 index 00000000..de939d35 --- /dev/null +++ b/to get the smallest element in the array @@ -0,0 +1,14 @@ +#Initialize array +arr = [25, 11, 7, 75, 56]; + +#Initialize min with the first element of the array. + +min = arr[0]; + +#Loop through the array +for i in range(0, len(arr)): + #Compare elements of array with min + if(arr[i] < min): + min = arr[i]; + +print("Smallest element present in given array: " + str(min)); From 6c9cd58e54f9fae5f66b25bd646c1f50e9e748d4 Mon Sep 17 00:00:00 2001 From: Mayank Badsara <72911127+BadsaraMayank@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:16:56 +0530 Subject: [PATCH 007/781] Factorial program in c Factorial program using loop. --- Factorial program in c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Factorial program in c diff --git a/Factorial program in c b/Factorial program in c new file mode 100644 index 00000000..1663258b --- /dev/null +++ b/Factorial program in c @@ -0,0 +1,12 @@ +#include +int main() +{ + int i,fact=1,number; + printf("Enter a number: "); + scanf("%d",&number); + for(i=1;i<=number;i++){ + fact=fact*i; + } + printf("Factorial of %d is: %d",number,fact); +return 0; +} From da801253b1b2c6e9bcd9b3494dd5e326ccdde7d4 Mon Sep 17 00:00:00 2001 From: Anshita Varyani <67929122+Anshitavaryani@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:17:32 +0530 Subject: [PATCH 008/781] Create Find length of a string Optimized code for finding a length of a string --- Find length of a string | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Find length of a string diff --git a/Find length of a string b/Find length of a string new file mode 100644 index 00000000..ed08fd81 --- /dev/null +++ b/Find length of a string @@ -0,0 +1,12 @@ +#include +#include +int main() { + char string1[]={"naman"}; + int i=0, length; + while(string1[i] !='\0') { + i++; + } + length=i; + printf(" string length is %d",length); + return 0; +} From d8806c6d64a65421ef228373ef26602bd120c7f1 Mon Sep 17 00:00:00 2001 From: Jakub Szymczak <58909195+Szymek887@users.noreply.github.com> Date: Thu, 15 Oct 2020 19:50:08 +0200 Subject: [PATCH 009/781] Program to find length of the string in javaScript This program was written in javaScript. --- Program to find length of the string in javaScript | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Program to find length of the string in javaScript diff --git a/Program to find length of the string in javaScript b/Program to find length of the string in javaScript new file mode 100644 index 00000000..8b3e5d40 --- /dev/null +++ b/Program to find length of the string in javaScript @@ -0,0 +1,5 @@ +// Length of the string + +var text = 'Some text'; + +console.log(text.length); From 28327aed326971e3cc4d9eb400cc0bc522a07a54 Mon Sep 17 00:00:00 2001 From: Anshita Varyani <67929122+Anshitavaryani@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:21:31 +0530 Subject: [PATCH 010/781] Create Find largest element in an array Optimized code for finding the largest element in an array --- Find largest element in an array | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Find largest element in an array diff --git a/Find largest element in an array b/Find largest element in an array new file mode 100644 index 00000000..f28eec6c --- /dev/null +++ b/Find largest element in an array @@ -0,0 +1,17 @@ +#include + +int main() { + int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + int loop, largest; + + largest = array[0]; + + for(loop = 1; loop < 10; loop++) { + if( largest < array[loop] ) + largest = array[loop]; + } + + printf("Largest element of array is %d", largest); + + return 0; +} From bbb911c919654ea5781b3eadfe77bf32113a43f5 Mon Sep 17 00:00:00 2001 From: Ritesh Sharma Date: Thu, 15 Oct 2020 23:25:10 +0530 Subject: [PATCH 011/781] Create Hacktoberfest: Program to print leap years in given range Code to find every leap year present in a given range. --- ...Program to print leap years in given range | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Hacktoberfest: Program to print leap years in given range diff --git a/Hacktoberfest: Program to print leap years in given range b/Hacktoberfest: Program to print leap years in given range new file mode 100644 index 00000000..5e818296 --- /dev/null +++ b/Hacktoberfest: Program to print leap years in given range @@ -0,0 +1,29 @@ +//Program to print leap years in given range + +#include + +int LeapYear(int year) +{ + if( (year % 400==0)||(year%4==0 && year%100!=0) ) + return 1; + else + return 0; +} + +int main() +{ + int i,End,Beg; + printf("Enter the year from where you want to print all leap years: "); + scanf("%d",&Beg); + printf("Enter the year till where you want to print all leap years: "); + scanf("%d",&End); + + printf("Leap years from %d to %d:\n",Beg,End); + for(i=Beg;i<=End;i++) + { + if(LeapYear(i)) + printf("%d\t",i); + } + + return 0; +} From 8940e28e400a6c3073e1d475802050d2e3fd7ffc Mon Sep 17 00:00:00 2001 From: Anshita Varyani <67929122+Anshitavaryani@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:25:15 +0530 Subject: [PATCH 012/781] Create Find factorial of a number Optimized code for finding the factorial of a number --- Find factorial of a number | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Find factorial of a number diff --git a/Find factorial of a number b/Find factorial of a number new file mode 100644 index 00000000..67a7d505 --- /dev/null +++ b/Find factorial of a number @@ -0,0 +1,12 @@ +#include +void main(){ + int i,f=1,num; + + printf("Input the number : "); + scanf("%d",&num); + + for(i=1;i<=num;i++) + f=f*i; + + printf("The Factorial of %d is: %d\n",num,f); +} From b7ff0e652b1cbf97628b21b79b678346961a15da Mon Sep 17 00:00:00 2001 From: Mayank Badsara <72911127+BadsaraMayank@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:26:04 +0530 Subject: [PATCH 013/781] Program to print the smallest element in an array Program to print the smallest element in an array using JavaScript. --- ...ram to print the smallest element in an array | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program to print the smallest element in an array diff --git a/Program to print the smallest element in an array b/Program to print the smallest element in an array new file mode 100644 index 00000000..f79e6844 --- /dev/null +++ b/Program to print the smallest element in an array @@ -0,0 +1,16 @@ +public class SmallestElement_array { + public static void main(String[] args) { + + //Initialize array + int [] arr = new int [] {25, 11, 7, 75, 56}; + //Initialize min with first element of array. + int min = arr[0]; + //Loop through the array + for (int i = 0; i < arr.length; i++) { + //Compare elements of array with min + if(arr[i] Date: Thu, 15 Oct 2020 23:26:27 +0530 Subject: [PATCH 014/781] Create Program to add sum off all numbers In an array --- ...ram to add sum off all numbers In an array | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program to add sum off all numbers In an array diff --git a/Program to add sum off all numbers In an array b/Program to add sum off all numbers In an array new file mode 100644 index 00000000..90d1570d --- /dev/null +++ b/Program to add sum off all numbers In an array @@ -0,0 +1,19 @@ +''' +Python code to calculate the sum of an array... +''' + + +def arraySum(array): + sum = 0 + for element in array: + sum+=element + + return sum + + + + +if __name__="__main__": + array = map(int,input().split()) + result = arraySum(array) + print(result) From 22e4d915356c1bed309ead5b218070549b5dc335 Mon Sep 17 00:00:00 2001 From: Jakub Szymczak <58909195+Szymek887@users.noreply.github.com> Date: Thu, 15 Oct 2020 19:57:03 +0200 Subject: [PATCH 015/781] Program to reverse the array in javaScript This program was written in javaScript. --- Program to reverse the array in javaScript | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Program to reverse the array in javaScript diff --git a/Program to reverse the array in javaScript b/Program to reverse the array in javaScript new file mode 100644 index 00000000..1544f222 --- /dev/null +++ b/Program to reverse the array in javaScript @@ -0,0 +1,7 @@ +// Reverse the array + +var numbers = [1,2,3,4]; +console.log('Your first array is: ' + numbers); + +var reversedArray = numbers.reverse(); +console.log('Your reversed array is: ' + reversedArray); From f39aac4c4b0e3d7946031846784e6a6f4bc37a5b Mon Sep 17 00:00:00 2001 From: Mayank Badsara <72911127+BadsaraMayank@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:28:34 +0530 Subject: [PATCH 016/781] Array elements in descending order Java Program to sort the elements of an array in descending order. --- ...e elements of an array in descending order | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Java Program to sort the elements of an array in descending order diff --git a/Java Program to sort the elements of an array in descending order b/Java Program to sort the elements of an array in descending order new file mode 100644 index 00000000..4bea335a --- /dev/null +++ b/Java Program to sort the elements of an array in descending order @@ -0,0 +1,32 @@ +public class SortDsc { + public static void main(String[] args) { + //Initialize array + int [] arr = new int [] {5, 2, 8, 7, 1}; + int temp = 0; + + //Displaying elements of original array + System.out.println("Elements of original array: "); + for (int i = 0; i < arr.length; i++) { + System.out.print(arr[i] + " "); + } + + //Sort the array in descending order + for (int i = 0; i < arr.length; i++) { + for (int j = i+1; j < arr.length; j++) { + if(arr[i] < arr[j]) { + temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + } + } + } + + System.out.println(); + + //Displaying elements of array after sorting + System.out.println("Elements of array sorted in descending order: "); + for (int i = 0; i < arr.length; i++) { + System.out.print(arr[i] + " "); + } + } +} From ed03db385e1ea85d1d0af8be72c9955f2092a10f Mon Sep 17 00:00:00 2001 From: Ritesh Sharma Date: Thu, 15 Oct 2020 23:29:59 +0530 Subject: [PATCH 017/781] Create Hacktoberfest: Program to find factorial of number Code for finding factorial of a positive number. --- ...rfest: Program to find factorial of number | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Hacktoberfest: Program to find factorial of number diff --git a/Hacktoberfest: Program to find factorial of number b/Hacktoberfest: Program to find factorial of number new file mode 100644 index 00000000..5c96fd19 --- /dev/null +++ b/Hacktoberfest: Program to find factorial of number @@ -0,0 +1,21 @@ +//Program to find factorial of number + +#include +using namespace std; + +int main() +{ + int n; + int factorial = 1; + + cout << "Enter a positive integer: "; + cin >> n; + + for(int i = 1; i <=n; ++i) + { + factorial *= i; + } + + cout << "Factorial of " << n << " = " << factorial; + return 0; +} From d48dab4af736d33881a71a6bffe049a303abd537 Mon Sep 17 00:00:00 2001 From: Mayank Badsara <72911127+BadsaraMayank@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:31:09 +0530 Subject: [PATCH 018/781] Sum of all the elements of an array Java Program to print the sum of all the elements of an array. --- ...o print the sum of all the elements of an array | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Java Program to print the sum of all the elements of an array diff --git a/Java Program to print the sum of all the elements of an array b/Java Program to print the sum of all the elements of an array new file mode 100644 index 00000000..87d4450a --- /dev/null +++ b/Java Program to print the sum of all the elements of an array @@ -0,0 +1,14 @@ +public class SumOfArray { + public static void main(String[] args) { + + //Initialize array + int [] arr = new int [] {1, 2, 3, 4, 5}; + int sum = 0; + + //Loop through the array to calculate sum of elements + for (int i = 0; i < arr.length; i++) { + sum = sum + arr[i]; + } + System.out.println("Sum of all the elements of an array: " + sum); + } +} From e9b4e182826e04e3ce414e1f3aff1584ebbcbbca Mon Sep 17 00:00:00 2001 From: Ritesh Sharma Date: Thu, 15 Oct 2020 23:36:20 +0530 Subject: [PATCH 019/781] Create Hacktoberfest: Program to calculate count of vowels & consonants in string Code to find Vowels and Consonants in a String. --- ...ate count of vowels & consonants in string | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Hacktoberfest: Program to calculate count of vowels & consonants in string diff --git a/Hacktoberfest: Program to calculate count of vowels & consonants in string b/Hacktoberfest: Program to calculate count of vowels & consonants in string new file mode 100644 index 00000000..71831861 --- /dev/null +++ b/Hacktoberfest: Program to calculate count of vowels & consonants in string @@ -0,0 +1,27 @@ +//Program to calculate count of vowels & consonants in string + +#include +#include +#include + +int main() +{ + int i, vowels= 0, consonant = 0; + + char str[] = "A compiler is a special program that processes statements written in a particular programming language and turns them into machine language or code that a computer's processor uses."; + + for(i = 0; i < strlen(str); i++){ + str[i] = tolower(str[i]); + if(str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u') { + vowels++; + } + else if(str[i] >= 'a' && str[i] <= 'z'){ + consonant++; + } + } + + printf("Number of vowels are : %d\n", vowels); + printf("Number of consonant are: %d", consonant); + + return 0; +} From 80ff3fc970d8139539875890cf521617e4f969d2 Mon Sep 17 00:00:00 2001 From: Rutvik Patel <72887393+rutvikpatel20@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:36:36 +0530 Subject: [PATCH 020/781] Create ExecutionTimeQuickSort.c --- ExecutionTimeQuickSort.c | 60 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 ExecutionTimeQuickSort.c diff --git a/ExecutionTimeQuickSort.c b/ExecutionTimeQuickSort.c new file mode 100644 index 00000000..0506e58c --- /dev/null +++ b/ExecutionTimeQuickSort.c @@ -0,0 +1,60 @@ +// Quick sort with Execution Time in C + +#include +#include +void swap(int *xp, int *yp) +{ + int temp = *xp; + *xp = *yp; + *yp = temp; +} +int i,j; +int part(int arr[], int low, int high) +{ + int pivot = arr[high]; + int i = (low - 1); + + for (j = low; j < high; j++) + { + if (arr[j] <= pivot) + { + i++; + swap(&arr[i], &arr[j]); + } + } + swap(&arr[i + 1], &arr[high]); + return (i + 1); +} +void quickSort(int arr[], int low, int high) +{ + if (low < high) + { + int pivot = part(arr, low, high); + quickSort(arr, low, pivot - 1); + quickSort(arr, pivot + 1, high); + } +} + +void printArray(int arr[], int size) +{ + for (i = 0; i < size; ++i) + printf("%d ", arr[i]); + printf("\n"); +} + +int main() +{ + clock_t start,end; + double cpu_time_used; + + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + printf("Old Array:- 64 34 25 12 22 11 90\n"); + int n = sizeof(arr) / sizeof(arr[0]); + start = clock(); + quickSort(arr, 0, n - 1); + printf("Sorted array:- "); + printArray(arr, n); + end = clock(); + cpu_time_used = ((double)(end - start))/CLOCKS_PER_SEC; + printf("Execution Time:- %lf",cpu_time_used); +} From 5557522a5d8e07283b35852bae5d7d8934969bdb Mon Sep 17 00:00:00 2001 From: Jakub Szymczak <58909195+Szymek887@users.noreply.github.com> Date: Thu, 15 Oct 2020 20:06:40 +0200 Subject: [PATCH 021/781] Program to count sum of all numbers in array This program was written in javaScript. --- ... to count sum of all numbers in array in javaScript | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program to count sum of all numbers in array in javaScript diff --git a/Program to count sum of all numbers in array in javaScript b/Program to count sum of all numbers in array in javaScript new file mode 100644 index 00000000..ed095cdf --- /dev/null +++ b/Program to count sum of all numbers in array in javaScript @@ -0,0 +1,10 @@ +// Count sum of all numbers in array + +var numbers = [10,56,16,1,90,25,-7,58,62,111]; +var sum = 0; + +for(var i = 0; i < numbers.length; i++) +{ + sum += numbers[i]; +} +console.log(sum); From 00aa9495be53ea7e560f6d4c3d6f1b4482af8842 Mon Sep 17 00:00:00 2001 From: Satyam Tripathi Date: Thu, 15 Oct 2020 23:36:46 +0530 Subject: [PATCH 022/781] Queue using 2 stacks A very important interview question in AMAZON --- QueueUsing2Stacks1 (1).cpp | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 QueueUsing2Stacks1 (1).cpp diff --git a/QueueUsing2Stacks1 (1).cpp b/QueueUsing2Stacks1 (1).cpp new file mode 100644 index 00000000..495b3b3e --- /dev/null +++ b/QueueUsing2Stacks1 (1).cpp @@ -0,0 +1,60 @@ +#include +using namespace std; + +struct node +{ +int data; +struct node *next; +}; + + +struct myStack{ +struct node *top; +void push(int item) +{ +struct node *t= new node; +t->data=item; +t->next=top; +top=t; +//cout<<"pushed "<data; + top=top->next; + delete p; + } + return item; +} +bool isEmpty(){if (top==NULL) return true; else return false;} +}; +myStack s1,s2; + +void insertQ(int item) +{ +s1.push(item); +cout<<"inserted in Queue "< Date: Thu, 15 Oct 2020 23:41:13 +0530 Subject: [PATCH 023/781] Create Factorial of a number. It's a code for factorial of a number --- Factorial of a number. | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Factorial of a number. diff --git a/Factorial of a number. b/Factorial of a number. new file mode 100644 index 00000000..70220ed2 --- /dev/null +++ b/Factorial of a number. @@ -0,0 +1,10 @@ +num = int(input("Enter a number: ")) +factorial = 1 +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(1,num + 1): + factorial = factorial*i + print("The factorial of",num,"is",factorial) From a234b2235dc3f92cb507e7a264c10d5fc43ee30d Mon Sep 17 00:00:00 2001 From: KGX10 <54179637+KGX10@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:42:59 +0530 Subject: [PATCH 024/781] Create Reverse an Array using python Reverse an array --- Reverse an Array using python | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Reverse an Array using python diff --git a/Reverse an Array using python b/Reverse an Array using python new file mode 100644 index 00000000..b72fde36 --- /dev/null +++ b/Reverse an Array using python @@ -0,0 +1,14 @@ +def arrayRev(array): + length = len(array) + revArray = [] + i=length-1 + while i >= 0: + revArray.append(array[i]) + i-=1 + return revArray + +if __name__=="__main__": + array = map(int,input().split()) + array = list(array) + result = arrayRev(array) + print(result) From 3c43d8e76aed921dfd0c0fa914d0ffd6b348e72d Mon Sep 17 00:00:00 2001 From: Shubasarkar1999 <44487360+Shubasarkar1999@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:47:02 +0530 Subject: [PATCH 025/781] Create To find length of a string. An easy code to find length of a string. --- To find length of a string. | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 To find length of a string. diff --git a/To find length of a string. b/To find length of a string. new file mode 100644 index 00000000..fb0675b1 --- /dev/null +++ b/To find length of a string. @@ -0,0 +1,9 @@ +def findLen(str): + if not str: + return 0 + else: + some_random_str = 'py' + return ((some_random_str).join(str)).count(some_random_str) + 1 + +str = "geeks" +print(findLen(str)) From 10c235fc131c2ba7b5993959d329be86be7fd7e5 Mon Sep 17 00:00:00 2001 From: Shubasarkar1999 <44487360+Shubasarkar1999@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:50:52 +0530 Subject: [PATCH 026/781] Create Smallest element in an array. Easy code for finding the smallest element in an array --- Smallest element in an array. | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Smallest element in an array. diff --git a/Smallest element in an array. b/Smallest element in an array. new file mode 100644 index 00000000..520ab540 --- /dev/null +++ b/Smallest element in an array. @@ -0,0 +1,20 @@ + + +#Initialize array +arr = [25, 11, 7, 75, 56]; + +#Initialize min with the first element of the array. + +min = arr[0]; + +#Loop through the array +for i in range(0, len(arr)): + #Compare elements of array with min + if(arr[i] < min): + min = arr[i]; + +print("Smallest element present in given array: " + str(min)); + + + + From 8862bd37f092e60ecd967173bd6626f1c5da5dd2 Mon Sep 17 00:00:00 2001 From: Venkateshwara Rao Jayasurya Date: Thu, 15 Oct 2020 23:52:37 +0530 Subject: [PATCH 027/781] Create factorial of a number in javascript --- factorial of a number in javascript.js | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 factorial of a number in javascript.js diff --git a/factorial of a number in javascript.js b/factorial of a number in javascript.js new file mode 100644 index 00000000..953fb80b --- /dev/null +++ b/factorial of a number in javascript.js @@ -0,0 +1,46 @@ + + + + + + Factorial of a number using JavaScript + + + + + +

+

+ + + +

+

+ + + + + From ae35ca19b99ad08f6f9d01eadab698eef4ed1829 Mon Sep 17 00:00:00 2001 From: Shubasarkar1999 <44487360+Shubasarkar1999@users.noreply.github.com> Date: Thu, 15 Oct 2020 23:57:39 +0530 Subject: [PATCH 028/781] Create Largest element in an array. Easy code for finding the largest number in an array --- Largest element in an array. | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Largest element in an array. diff --git a/Largest element in an array. b/Largest element in an array. new file mode 100644 index 00000000..33680616 --- /dev/null +++ b/Largest element in an array. @@ -0,0 +1,17 @@ +#Initialize array +arr = [25, 11, 7, 75, 56]; + +#Initialize max with first element of array. +max = arr[0]; + +#Loop through the array +for i in range(0, len(arr)): + #Compare elements of array with max + if(arr[i] > max): + max = arr[i]; + +print("Largest element present in given array: " + str(max)); + + + + From 70824c683fc011fbc867942ed177ddabe091d17b Mon Sep 17 00:00:00 2001 From: Venkateshwara Rao Jayasurya Date: Fri, 16 Oct 2020 00:16:47 +0530 Subject: [PATCH 029/781] fibonacci series in javascript --- fibonacci series in javascript.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 fibonacci series in javascript.js diff --git a/fibonacci series in javascript.js b/fibonacci series in javascript.js new file mode 100644 index 00000000..74b81843 --- /dev/null +++ b/fibonacci series in javascript.js @@ -0,0 +1,12 @@ + From 71ce1b7de624603014fa99cb23edbd2f36aec018 Mon Sep 17 00:00:00 2001 From: Venkateshwara Rao Jayasurya Date: Fri, 16 Oct 2020 00:22:18 +0530 Subject: [PATCH 030/781] find power of a number in javascript --- find Power of a number in javascript.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 find Power of a number in javascript.js diff --git a/find Power of a number in javascript.js b/find Power of a number in javascript.js new file mode 100644 index 00000000..fe1c863e --- /dev/null +++ b/find Power of a number in javascript.js @@ -0,0 +1,18 @@ + + + + +

Click the button to display the result of 5*5*5.

+ + + +

+ + + + + From 4628dd2318f176254c21391fb1fb3bb89bca20ab Mon Sep 17 00:00:00 2001 From: Venkateshwara Rao Jayasurya Date: Fri, 16 Oct 2020 00:26:25 +0530 Subject: [PATCH 031/781] string length in javascript --- string length in javascript.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 string length in javascript.js diff --git a/string length in javascript.js b/string length in javascript.js new file mode 100644 index 00000000..ff0a9037 --- /dev/null +++ b/string length in javascript.js @@ -0,0 +1,12 @@ + + + Program to find string length + + + + + + From b84b87ddca2be70226d5ef1364333b2e068350a7 Mon Sep 17 00:00:00 2001 From: bullishking <71932188+bullishking@users.noreply.github.com> Date: Fri, 16 Oct 2020 01:27:56 +0530 Subject: [PATCH 032/781] Compare triplet --- Compare Triplet | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Compare Triplet diff --git a/Compare Triplet b/Compare Triplet new file mode 100644 index 00000000..a8b561bc --- /dev/null +++ b/Compare Triplet @@ -0,0 +1,31 @@ +import math +import os +import random +import re +import sys + +# Complete the compareTriplets function below. +def compareTriplets(a, b): + awins = 0 + bwins = 0 + for x,y in zip(a,b): + if x>y: + awins+=1 + elif x Date: Fri, 16 Oct 2020 01:44:11 +0530 Subject: [PATCH 033/781] Fibonacci series in cpp adding Fibonacci series using array --- Fibonacci series using array | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Fibonacci series using array diff --git a/Fibonacci series using array b/Fibonacci series using array new file mode 100644 index 00000000..9308fc89 --- /dev/null +++ b/Fibonacci series using array @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + int n,arr[50]; + cout<<"Enter No. of Fabionacci term: "; + cin>>n; + arr[0]=0; + arr[1]=1; + cout< Date: Fri, 16 Oct 2020 01:59:34 +0530 Subject: [PATCH 034/781] Create program to find factorial of number --- program to find factorial of number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 program to find factorial of number diff --git a/program to find factorial of number b/program to find factorial of number new file mode 100644 index 00000000..ae621fea --- /dev/null +++ b/program to find factorial of number @@ -0,0 +1,14 @@ +public class Factorial { + + public static void main(String[] args) { + + int num = 10; + long factorial = 1; + for(int i = 1; i <= num; ++i) + { + // factorial = factorial * i; + factorial *= i; + } + System.out.printf("Factorial of %d = %d", num, factorial); + } +} From 21be20d33768f611f94e6cb2e1c462bad69702aa Mon Sep 17 00:00:00 2001 From: plsmailpranit <72949980+plsmailpranit@users.noreply.github.com> Date: Fri, 16 Oct 2020 04:04:39 +0530 Subject: [PATCH 035/781] Create Program to multiply 2D or 3D Matrices Optimized Code For Program to multiply 2D or 3D Matrices In C Language --- Program to multiply 2D or 3D Matrices | 82 +++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Program to multiply 2D or 3D Matrices diff --git a/Program to multiply 2D or 3D Matrices b/Program to multiply 2D or 3D Matrices new file mode 100644 index 00000000..def03f7b --- /dev/null +++ b/Program to multiply 2D or 3D Matrices @@ -0,0 +1,82 @@ +#include + +// function to get matrix elements entered by the user +void getMatrixElements(int matrix[][10], int row, int column) { + + printf("\nEnter elements: \n"); + + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("Enter a%d%d: ", i + 1, j + 1); + scanf("%d", &matrix[i][j]); + } + } +} + +// function to multiply two matrices +void multiplyMatrices(int first[][10], + int second[][10], + int result[][10], + int r1, int c1, int r2, int c2) { + + // Initializing elements of matrix mult to 0. + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + result[i][j] = 0; + } + } + + // Multiplying first and second matrices and storing it in result + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + for (int k = 0; k < c1; ++k) { + result[i][j] += first[i][k] * second[k][j]; + } + } + } +} + +// function to display the matrix +void display(int result[][10], int row, int column) { + + printf("\nOutput Matrix:\n"); + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("%d ", result[i][j]); + if (j == column - 1) + printf("\n"); + } + } +} + +int main() { + int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2; + printf("Enter rows and column for the first matrix: "); + scanf("%d %d", &r1, &c1); + printf("Enter rows and column for the second matrix: "); + scanf("%d %d", &r2, &c2); + + // Taking input until + // 1st matrix columns is not equal to 2nd matrix row + while (c1 != r2) { + printf("Error! Enter rows and columns again.\n"); + printf("Enter rows and columns for the first matrix: "); + scanf("%d%d", &r1, &c1); + printf("Enter rows and columns for the second matrix: "); + scanf("%d%d", &r2, &c2); + } + + // get elements of the first matrix + getMatrixElements(first, r1, c1); + + // get elements of the second matrix + getMatrixElements(second, r2, c2); + + // multiply two matrices. + multiplyMatrices(first, second, result, r1, c1, r2, c2); + + // display the result + display(result, r1, c2); + + return 0; +} From e75c27b3310b704fa3d2322944efcacf6a60413e Mon Sep 17 00:00:00 2001 From: plsmailpranit <72949980+plsmailpranit@users.noreply.github.com> Date: Fri, 16 Oct 2020 04:09:12 +0530 Subject: [PATCH 036/781] Create Program to convert binary to decimal number Optimized Code For Program to convert binary to decimal number In C Language. --- Program to convert binary to decimal number | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Program to convert binary to decimal number diff --git a/Program to convert binary to decimal number b/Program to convert binary to decimal number new file mode 100644 index 00000000..6b73a730 --- /dev/null +++ b/Program to convert binary to decimal number @@ -0,0 +1,21 @@ +#include +#include +int convert(long long n); +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +int convert(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From d1c278c75b0c15aa46e723ecb6e3d997605c41da Mon Sep 17 00:00:00 2001 From: plsmailpranit <72949980+plsmailpranit@users.noreply.github.com> Date: Fri, 16 Oct 2020 04:11:52 +0530 Subject: [PATCH 037/781] Create Program to convert binary to octal number In C Language Optimized Code For Program to convert binary to octal number In C Language. --- ...nvert binary to octal number In C Language | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Program to convert binary to octal number In C Language diff --git a/Program to convert binary to octal number In C Language b/Program to convert binary to octal number In C Language new file mode 100644 index 00000000..c1bff256 --- /dev/null +++ b/Program to convert binary to octal number In C Language @@ -0,0 +1,29 @@ +#include +int convert(long long bin); +int main() { + long long bin; + printf("Enter a binary number: "); + scanf("%lld", &bin); + printf("%lld in binary = %d in octal", bin, convert(bin)); + return 0; +} + +int convert(long long bin) { + int oct = 0, dec = 0, i = 0; + + // converting binary to decimal + while (bin != 0) { + dec += (bin % 10) * pow(2, i); + ++i; + bin /= 10; + } + i = 1; + + // converting to decimal to octal + while (dec != 0) { + oct += (dec % 8) * i; + dec /= 8; + i *= 10; + } + return oct; +} From 1fa33f7ae59cc76bcd3419d149101b6d598024dd Mon Sep 17 00:00:00 2001 From: plsmailpranit <72949980+plsmailpranit@users.noreply.github.com> Date: Fri, 16 Oct 2020 04:16:14 +0530 Subject: [PATCH 038/781] Create Program to find power of any number in C Language. Optimized Program to find power of any number In C Language --- ...am to find power of any number in C Language. | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program to find power of any number in C Language. diff --git a/Program to find power of any number in C Language. b/Program to find power of any number in C Language. new file mode 100644 index 00000000..e7d59525 --- /dev/null +++ b/Program to find power of any number in C Language. @@ -0,0 +1,16 @@ +#include +int main() { + int base, exp; + long long result = 1; + printf("Enter a base number: "); + scanf("%d", &base); + printf("Enter an exponent: "); + scanf("%d", &exp); + + while (exp != 0) { + result *= base; + --exp; + } + printf("Answer = %lld", result); + return 0; +} From 717a11a8000cba5f4e48e9769389d97dc31614e3 Mon Sep 17 00:00:00 2001 From: sagar2s Date: Fri, 16 Oct 2020 07:01:06 +0545 Subject: [PATCH 039/781] URL shortner using python --- URL_Shortner.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 URL_Shortner.py diff --git a/URL_Shortner.py b/URL_Shortner.py new file mode 100644 index 00000000..eae3376d --- /dev/null +++ b/URL_Shortner.py @@ -0,0 +1,29 @@ +from __future__ import with_statement + +import contextlib + +try: + from urllib.parse import urlencode + +except ImportError: + from urllib import urlencode +try: + from urllib.request import urlopen + +except ImportError: + from urllib2 import urlopen + +import sys + + +def make_tiny(url): + request_url = ('http://tinyurl.com/api-create.php?' + urlencode({'url':url})) + with contextlib.closing(urlopen(request_url)) as response: + return response.read().decode('utf-8 ') + +def main(): + for tinyurl in map(make_tiny, sys.argv[1:]): + print(tinyurl) + +if __name__ == '__main__': + main() From 411d03df0b725702464c521ac4fa49469cef7071 Mon Sep 17 00:00:00 2001 From: Ethan Wentworth <43764998+AwesomeSamIAm@users.noreply.github.com> Date: Thu, 15 Oct 2020 19:30:04 -0700 Subject: [PATCH 040/781] Create binaryToDecimal.py Some python code to convert a binary number that ranges from any 8 bit number into a number that ranges from 0-255. --- binaryToDecimal.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 binaryToDecimal.py diff --git a/binaryToDecimal.py b/binaryToDecimal.py new file mode 100644 index 00000000..6d3e8a04 --- /dev/null +++ b/binaryToDecimal.py @@ -0,0 +1,39 @@ +binnum = int(input("Enter a binary number ")) + +final = int(0) + + +#128 +if (binnum >= 10000000): + binnum = int(binnum-10000000) + final = int(final+128) +#64 +if (binnum >= 1000000): + binnum = int(binnum-1000000) + final = int(final+64) +#32 +if (binnum >= 100000): + binnum = int(binnum-100000) + final = int(final+32) +#16 +if (binnum >= 10000): + binnum = int(binnum-10000) + final = int(final+16) +#8 +if (binnum >= 1000): + binnum = int(binnum-1000) + final = int(final+8) +#4 +if (binnum >= 100): + binnum = int(binnum-100) + final = int(final+4) +#2 +if (binnum >= 10): + binnum = int(binnum-10) + final = int(final+2) +#1 +if (binnum >= 1): + binnum = int(binnum-1) + final = int(final+1) + +print(final) From 38e69fbb5214da055974e23b0e32f2de3ad31f8b Mon Sep 17 00:00:00 2001 From: praveenkumar54327 <72930333+praveenkumar54327@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:00:41 +0530 Subject: [PATCH 041/781] Create Program to check if number is even or odd Optimized code for getting Even or Odd Number --- Program to check if number is even or odd | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Program to check if number is even or odd diff --git a/Program to check if number is even or odd b/Program to check if number is even or odd new file mode 100644 index 00000000..b93a1387 --- /dev/null +++ b/Program to check if number is even or odd @@ -0,0 +1,17 @@ +#include +int main() +{ + // This variable is to store the input number + int num; + + printf("Enter an integer: "); + scanf("%d",&num); + + // Modulus (%) returns remainder + if ( num%2 == 0 ) + printf("%d is an even number", num); + else + printf("%d is an odd number", num); + + return 0; +} From d5ac9054acfd57d550387a2b18d05ec34a2cc815 Mon Sep 17 00:00:00 2001 From: Ethan Wentworth <43764998+AwesomeSamIAm@users.noreply.github.com> Date: Thu, 15 Oct 2020 19:34:51 -0700 Subject: [PATCH 042/781] Create power.py Code to find the answer of any base number you input to the power of any exponent you enter. The code even works with negative exponents. --- power.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 power.py diff --git a/power.py b/power.py new file mode 100644 index 00000000..cf73cd50 --- /dev/null +++ b/power.py @@ -0,0 +1,4 @@ +base = int(input("Enter your base number: ")) +power = int(input("Enter your power/exponent: ")) + +print(base**power) From f3bb278b677bb303055bdb2d4804411344c213ed Mon Sep 17 00:00:00 2001 From: praveenkumar54327 <72930333+praveenkumar54327@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:07:59 +0530 Subject: [PATCH 043/781] Create Perfect Number A number is a perfect number if is equal to sum of its proper divisors, that is, sum of its positive divisors excluding the number itself. Write a function to check if a given number is perfect or not. --- Perfect Number | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Perfect Number diff --git a/Perfect Number b/Perfect Number new file mode 100644 index 00000000..6a8ebd81 --- /dev/null +++ b/Perfect Number @@ -0,0 +1,40 @@ +// C++ program to check if a given number is perfect +// or not +#include +using namespace std; + +// Returns true if n is perfect +bool isPerfect(long long int n) +{ + // To store sum of divisors + long long int sum = 1; + + // Find all divisors and add them + for (long long int i=2; i*i<=n; i++) + { + if (n%i==0) + { + if(i*i!=n) + sum = sum + i + n/i; + else + sum=sum+i; + } + } + // If sum of divisors is equal to + // n, then n is a perfect number + if (sum == n && n != 1) + return true; + + return false; +} + +// Driver program +int main() +{ + cout << "Below are all perfect numbers till 10000\n"; + for (int n =2; n<10000; n++) + if (isPerfect(n)) + cout << n << " is a perfect number\n"; + + return 0; +} From 90dec24d8f873a4ee32aaf46b51e9b04ec184df0 Mon Sep 17 00:00:00 2001 From: praveenkumar54327 <72930333+praveenkumar54327@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:09:15 +0530 Subject: [PATCH 044/781] Create Program to print first N Prime numbers Given a number N, the task is to print the first N prime number from 1 to N. --- Program to print first N Prime numbers | 52 ++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Program to print first N Prime numbers diff --git a/Program to print first N Prime numbers b/Program to print first N Prime numbers new file mode 100644 index 00000000..05f40332 --- /dev/null +++ b/Program to print first N Prime numbers @@ -0,0 +1,52 @@ +// C++ program to display first N Prime numbers + +#include +using namespace std; + +// Function to print first N prime numbers +void print_first_N_primes(int N) +{ + // Declare the variables + int i, j, flag; + + // Print display message + cout << "\nPrime numbers between 1 and " + << N << " are:\n"; + + // Traverse each number from 1 to N + // with the help of for loop + for (i = 1; i <= N; i++) { + + // Skip 0 and 1 as they are + // niether prime nor composite + if (i == 1 || i == 0) + continue; + + // flag variable to tell + // if i is prime or not + flag = 1; + + for (j = 2; j <= i / 2; ++j) { + if (i % j == 0) { + flag = 0; + break; + } + } + + // flag = 1 means i is prime + // and flag = 0 means i is not prime + if (flag == 1) + cout << i << " "; + } +} + +// Driver code +int main() +{ + + int N = 100; + + print_first_N_primes(N); + + return 0; +} From 9950da45c4f38e623f67a00ad06e9dd7847461d0 Mon Sep 17 00:00:00 2001 From: mr-rawat <72936796+mr-rawat@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:10:00 +0530 Subject: [PATCH 045/781] Create C_using_arrays.c --- Fibonnaci Series/C_using_arrays.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Fibonnaci Series/C_using_arrays.c diff --git a/Fibonnaci Series/C_using_arrays.c b/Fibonnaci Series/C_using_arrays.c new file mode 100644 index 00000000..f0cea498 --- /dev/null +++ b/Fibonnaci Series/C_using_arrays.c @@ -0,0 +1,25 @@ +/** + Fibonacci series in C++ using array by codebind.com + */ + +#include + +int main(void) { + int i,number; + long int arr[40]; + + std::cout << "Enter the number : "<< std::endl; + std::cin >> number; + + arr[0]=0; + arr[1]=1; + + for(i = 2; i< number ; i++){ + arr[i] = arr[i-1] + arr[i-2]; + } + + std::cout << "Fibonacci series is: "; + for(i=0; i< number; i++) + std::cout << arr[i] << std::endl; + return 0; +} From 3db7770e895769ff042b98c22bebd50464689352 Mon Sep 17 00:00:00 2001 From: praveenkumar54327 <72930333+praveenkumar54327@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:10:41 +0530 Subject: [PATCH 046/781] Create Given a number N, the task is to print the first N prime number from 1 to N. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given an array A containing n integers. The task is to check whether the array is Monotonic or not. An array is monotonic if it is either monotone increasing or monotone decreasing. An array A is monotone increasing if for all i <= j, A[i] <= A[j]. An array A is monotone decreasing if for all i <= j, A[i] >= A[j]. Return “True” if the given array A is monotonic else return “False” (without quotes). --- ...o print the first N prime number from 1 to N. | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Given a number N, the task is to print the first N prime number from 1 to N. diff --git a/Given a number N, the task is to print the first N prime number from 1 to N. b/Given a number N, the task is to print the first N prime number from 1 to N. new file mode 100644 index 00000000..59faf504 --- /dev/null +++ b/Given a number N, the task is to print the first N prime number from 1 to N. @@ -0,0 +1,16 @@ +# Python3 program to find sum in Nth group + +# Check if given array is Monotonic +def isMonotonic(A): + + return (all(A[i] <= A[i + 1] for i in range(len(A) - 1)) or + all(A[i] >= A[i + 1] for i in range(len(A) - 1))) + +# Driver program +A = [6, 5, 4, 4] + +# Print required result +print(isMonotonic(A)) + +# This code is written by +# Sanjit_Prasad From d0c30089f0ccac1500df842abddf8158d3906b84 Mon Sep 17 00:00:00 2001 From: Ethan Wentworth <43764998+AwesomeSamIAm@users.noreply.github.com> Date: Thu, 15 Oct 2020 19:41:02 -0700 Subject: [PATCH 047/781] Create lengthOfString.py A simple bit of code that gives you the exact number (the length) of characters in a string. --- lengthOfString.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 lengthOfString.py diff --git a/lengthOfString.py b/lengthOfString.py new file mode 100644 index 00000000..38c8b0fc --- /dev/null +++ b/lengthOfString.py @@ -0,0 +1,3 @@ +ans = input("Enter a string to find the length: ") +fin = len(ans) +print(fin) From 7fedbb907e53f5270df3110cd560225098ecedec Mon Sep 17 00:00:00 2001 From: Candra Perdana <51086958+cp2940@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:48:02 +0700 Subject: [PATCH 048/781] Create Find a Smallest Element In the Array Please correct --- Find a Smallest Element In the Array | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Find a Smallest Element In the Array diff --git a/Find a Smallest Element In the Array b/Find a Smallest Element In the Array new file mode 100644 index 00000000..cefd176e --- /dev/null +++ b/Find a Smallest Element In the Array @@ -0,0 +1,20 @@ +#include +#include +int main() +{ + int i, n; + float *arr; + arr=(float*)malloc(1*sizeof(float)); + printf("Enter the number of elements "); + scanf("%d", &n); + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + printf("Largest element = %.2f", arr[0]); + return 0; +} From d2804d43c03d30f6dac67ec172fca707303e78ee Mon Sep 17 00:00:00 2001 From: ns9137625751 <72907070+ns9137625751@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:44:33 +0530 Subject: [PATCH 049/781] Create C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) example of C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) --- ...n Lexicographical Order (Dictionary Order) | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) diff --git a/C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) b/C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) new file mode 100644 index 00000000..e0744e09 --- /dev/null +++ b/C++ Program to Sort Elements in Lexicographical Order (Dictionary Order) @@ -0,0 +1,32 @@ +#include +using namespace std; + +int main() +{ + string str[10], temp; + + cout << "Enter 10 words: " << endl; + for(int i = 0; i < 10; ++i) + { + getline(cin, str[i]); + } + + for(int i = 0; i < 9; ++i) + for( int j = i+1; j < 10; ++j) + { + if(str[i] > str[j]) + { + temp = str[i]; + str[i] = str[j]; + str[j] = temp; + } + } + + cout << "In lexicographical order: " << endl; + + for(int i = 0; i < 10; ++i) + { + cout << str[i] << endl; + } + return 0; +} From cecaa271da48db17a0f096bf96940af520bee157 Mon Sep 17 00:00:00 2001 From: Yashwantbisht <72188791+Yashwantbisht@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:50:54 +0530 Subject: [PATCH 050/781] Create Please merge my pull request C program to swap two numbers using temporary variables --- Please merge my pull request | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Please merge my pull request diff --git a/Please merge my pull request b/Please merge my pull request new file mode 100644 index 00000000..5c7f9e45 --- /dev/null +++ b/Please merge my pull request @@ -0,0 +1,21 @@ +#include +int main() { + double first, second, temp; + printf("Enter first number: "); + scanf("%lf", &first); + printf("Enter second number: "); + scanf("%lf", &second); + + // Value of first is assigned to temp + temp = first; + + // Value of second is assigned to first + first = second; + + // Value of temp (initial value of first) is assigned to second + second = temp; + + printf("\nAfter swapping, firstNumber = %.2lf\n", first); + printf("After swapping, secondNumber = %.2lf", second); + return 0; +} From 38fb30ff5d3ad77e69ce9f0e7b4b2ebd1b2c166e Mon Sep 17 00:00:00 2001 From: Yashwantbisht <72188791+Yashwantbisht@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:55:41 +0530 Subject: [PATCH 051/781] Create C Programming to calculate average Using Arrays An simple example of C progarm --- C Programming to calculate average Using Arrays | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 C Programming to calculate average Using Arrays diff --git a/C Programming to calculate average Using Arrays b/C Programming to calculate average Using Arrays new file mode 100644 index 00000000..6910d189 --- /dev/null +++ b/C Programming to calculate average Using Arrays @@ -0,0 +1,13 @@ +#include +int main() { + int n, i; + float num[100], sum = 0.0, avg; + + printf("Enter the numbers of elements: "); + scanf("%d", &n); + + while (n > 100 || n < 1) { + printf("Error! number should in range of (1 to 100).\n"); + printf("Enter the number again: "); + scanf("%d", &n); + } From 8f328ec13097c12a3b423ae853a8866a256b1cfd Mon Sep 17 00:00:00 2001 From: Mayank Badsara <72908882+Badsara-Mayank@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:14:05 +0530 Subject: [PATCH 052/781] Find leap year between two given years Find leap year between two given years using python program. --- ...ogram to find leap year between two given years | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 python program to find leap year between two given years diff --git a/python program to find leap year between two given years b/python program to find leap year between two given years new file mode 100644 index 00000000..87af4c8f --- /dev/null +++ b/python program to find leap year between two given years @@ -0,0 +1,14 @@ +#Print a string about the program +print ("Print leap year between two given years") +#Get the input start and end year from user +print ("Enter start year") +startYear = int(input()) +print ("Enter last year") +endYear = int(input()) + +print ("List of leap years:") +#loop through between the start and end year +for year in range(startYear, endYear): + #check if the year is a Leap year if yes print + if (0 == year % 4) and (0 != year % 100) or (0 == year % 400): + print (year) From 1b5f2f287d3890e5a19231307b8d09e006a8e78d Mon Sep 17 00:00:00 2001 From: Mayank Badsara <72908882+Badsara-Mayank@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:16:46 +0530 Subject: [PATCH 053/781] Find the Length of a String Find the length of a string using C Program. --- C Program to Find the Length of a String | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 C Program to Find the Length of a String diff --git a/C Program to Find the Length of a String b/C Program to Find the Length of a String new file mode 100644 index 00000000..c90dfe30 --- /dev/null +++ b/C Program to Find the Length of a String @@ -0,0 +1,17 @@ +#include +#include + +int main() +{ + char Str[100]; + int Length; + + printf("\n Please Enter any String \n"); + gets (Str); + + Length = strlen(Str); + + printf("Length of a String = %d\n", Length); + + return 0; +} From 8f997e3e67a0f76453450fecd1f4645be9f01a57 Mon Sep 17 00:00:00 2001 From: Mayank Badsara <72908882+Badsara-Mayank@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:18:48 +0530 Subject: [PATCH 054/781] Find the Largest and Smallest Elements in an Array Find the Largest and Smallest Elements in an Array using C++ Program. --- ... Largest and Smallest Elements in an Array | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 C++ Program to Find the Largest and Smallest Elements in an Array diff --git a/C++ Program to Find the Largest and Smallest Elements in an Array b/C++ Program to Find the Largest and Smallest Elements in an Array new file mode 100644 index 00000000..f9f1d337 --- /dev/null +++ b/C++ Program to Find the Largest and Smallest Elements in an Array @@ -0,0 +1,26 @@ +#include +using namespace std; +int main () +{ + int arr[10], n, i, max, min; + cout << "Enter the size of the array : "; + cin >> n; + cout << "Enter the elements of the array : "; + for (i = 0; i < n; i++) + cin >> arr[i]; + max = arr[0]; + for (i = 0; i < n; i++) + { + if (max < arr[i]) + max = arr[i]; + } + min = arr[0]; + for (i = 0; i < n; i++) + { + if (min > arr[i]) + min = arr[i]; + } + cout << "Largest element : " << max; + cout << "Smallest element : " << min; + return 0; +} From ecd339440b9059858ee81e6ec362c6a97c1b3e8a Mon Sep 17 00:00:00 2001 From: Mayank Badsara <72908882+Badsara-Mayank@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:20:53 +0530 Subject: [PATCH 055/781] Find largest Element in an Array Find largest Element in an Array using C++ Program. --- ...rogram to Find Largest Element of an Array | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 C++ Program to Find Largest Element of an Array diff --git a/C++ Program to Find Largest Element of an Array b/C++ Program to Find Largest Element of an Array new file mode 100644 index 00000000..1e909f66 --- /dev/null +++ b/C++ Program to Find Largest Element of an Array @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main() +{ + int i, n; + float arr[100]; + + cout << "Enter total number of elements(1 to 100): "; + cin >> n; + cout << endl; + + // Store number entered by the user + for(i = 0; i < n; ++i) + { + cout << "Enter Number " << i + 1 << " : "; + cin >> arr[i]; + } + + // Loop to store largest number to arr[0] + for(i = 1;i < n; ++i) + { + // Change < to > if you want to find the smallest element + if(arr[0] < arr[i]) + arr[0] = arr[i]; + } + cout << "Largest element = " << arr[0]; + + return 0; +} From 42827357a9da43306e3323ab2acb0ac24275ec4b Mon Sep 17 00:00:00 2001 From: yashkumarjha12 <72943344+yashkumarjha12@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:23:10 +0530 Subject: [PATCH 056/781] Program to find the length of the string. This program is used to find out the length of the string provided. --- Program to find the length of the string. | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program to find the length of the string. diff --git a/Program to find the length of the string. b/Program to find the length of the string. new file mode 100644 index 00000000..7b09e4c4 --- /dev/null +++ b/Program to find the length of the string. @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Hacktoberfest is on!!!."; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 420ae2667e0dd4e4797164777418cea11fb4e9b4 Mon Sep 17 00:00:00 2001 From: yashkumarjha12 <72943344+yashkumarjha12@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:28:47 +0530 Subject: [PATCH 057/781] Create Program to print Fibonacci Series This will print the fibonacci series upto which you want. --- Program to print Fibonacci Series | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program to print Fibonacci Series diff --git a/Program to print Fibonacci Series b/Program to print Fibonacci Series new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/Program to print Fibonacci Series @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 7e76bced5cee267a398335cca1633265c0f7329a Mon Sep 17 00:00:00 2001 From: yashkumarjha12 <72943344+yashkumarjha12@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:31:10 +0530 Subject: [PATCH 058/781] Create Program to find the smallest element in array This will print the smallest element in the array. --- Program to find the smallest element in array | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Program to find the smallest element in array diff --git a/Program to find the smallest element in array b/Program to find the smallest element in array new file mode 100644 index 00000000..3bced32f --- /dev/null +++ b/Program to find the smallest element in array @@ -0,0 +1,24 @@ +#include + +int main() { + int a[30], i, num, smallest; + + printf("\nEnter no of elements :"); + scanf("%d", &num); + + for (i = 0; i < num; i++) + scanf("%d", &a[i]); + + smallest = a[0]; + + for (i = 0; i < num; i++) { + if (a[i] < smallest) { + smallest = a[i]; + } + } + + + printf("\nSmallest Element : %d", smallest); + + return (0); +} From 8967f4f5cec1e2952efe6ae8711779f6828a2cb4 Mon Sep 17 00:00:00 2001 From: yashkumarjha12 <72943344+yashkumarjha12@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:33:38 +0530 Subject: [PATCH 059/781] Create Program to find the factorial of a number. This is used to find the factorial of the number. --- Program to find the factorial of a number. | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program to find the factorial of a number. diff --git a/Program to find the factorial of a number. b/Program to find the factorial of a number. new file mode 100644 index 00000000..07b09ea2 --- /dev/null +++ b/Program to find the factorial of a number. @@ -0,0 +1,19 @@ +#include +int main() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows error if the user enters a negative integer + if (n < 0) + printf("Error! Factorial of a negative number doesn't exist."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + return 0; +} From b4409bb8cd2ae01de2fe3e466a66f08f00b2967a Mon Sep 17 00:00:00 2001 From: Sandesh2003 <72540199+Sandesh2003@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:51:02 +0530 Subject: [PATCH 060/781] Greater Number Program to find greatest of two numbers of c --- Greater number | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Greater number diff --git a/Greater number b/Greater number new file mode 100644 index 00000000..44608557 --- /dev/null +++ b/Greater number @@ -0,0 +1,24 @@ +/* C Program to Find Largest of Two numbers */ + +#include + +int main() { + int a, b; + printf("Please Enter Two different values\n"); + scanf("%d %d", &a, &b); + + if(a > b) + { + printf("%d is Largest\n", a); + } + else if (b > a) + { + printf("%d is Largest\n", b); + } + else + { + printf("Both are Equal\n"); + } + + return 0; +} From d7b70d9121f2add1fae4c88cf7ee9879174c2548 Mon Sep 17 00:00:00 2001 From: prashasti1299 <72958668+prashasti1299@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:54:07 +0530 Subject: [PATCH 061/781] Create ASCII value of a given character --- ASCII value of a given character | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 ASCII value of a given character diff --git a/ASCII value of a given character b/ASCII value of a given character new file mode 100644 index 00000000..00fb29bd --- /dev/null +++ b/ASCII value of a given character @@ -0,0 +1,2 @@ +character=input("Enter the character") +print(f"The ASCII value of {character} is {ord(character})") From 2cd1d8c8f677446cfb0ae495afae3fab738e1de6 Mon Sep 17 00:00:00 2001 From: Sandesh2003 <72540199+Sandesh2003@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:57:47 +0530 Subject: [PATCH 062/781] Hello word program How to hello word using javascript --- Hello word program | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Hello word program diff --git a/Hello word program b/Hello word program new file mode 100644 index 00000000..c76cc5fb --- /dev/null +++ b/Hello word program @@ -0,0 +1,10 @@ +// Simple Java Programs to Print Hello World +public class HelloWorld { + + public static void main(String[] args) + { + System.out.println("\n Hello World "); + } + +} +OUTPUT From 22ae84ac250e5fb3c9b3ed33c2ec969c3b374ae0 Mon Sep 17 00:00:00 2001 From: prashasti1299 <72958668+prashasti1299@users.noreply.github.com> Date: Fri, 16 Oct 2020 09:57:49 +0530 Subject: [PATCH 063/781] Create Finding the length of the string finding the length of the string in python --- Finding the length of the string | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Finding the length of the string diff --git a/Finding the length of the string b/Finding the length of the string new file mode 100644 index 00000000..61114d2e --- /dev/null +++ b/Finding the length of the string @@ -0,0 +1,2 @@ +string=input("Enter Your String: ") +print(f"The Length of the string is{len(string)}") From c9dae6acb61b200d17ee883e109f6b6bfd2151ac Mon Sep 17 00:00:00 2001 From: prashasti1299 <72958668+prashasti1299@users.noreply.github.com> Date: Fri, 16 Oct 2020 10:00:38 +0530 Subject: [PATCH 064/781] Create Leap Year Finder in python --- Leap Year Finder in python | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Leap Year Finder in python diff --git a/Leap Year Finder in python b/Leap Year Finder in python new file mode 100644 index 00000000..5e521a53 --- /dev/null +++ b/Leap Year Finder in python @@ -0,0 +1,12 @@ +def is_leap(year): + leap=False + if (year%400==0): + leap= False + elif(year%100==0): + leap= False + elif(year%4==0): + leap=True + return leap + +year = int(input()) +print(is_leap(year)) From ed3860dbd9acd0229e7a3194a354ee93ec06aff9 Mon Sep 17 00:00:00 2001 From: prashasti1299 <72958668+prashasti1299@users.noreply.github.com> Date: Fri, 16 Oct 2020 10:04:28 +0530 Subject: [PATCH 065/781] Create Calculating power of a number in python --- Calculating power of a number in python | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Calculating power of a number in python diff --git a/Calculating power of a number in python b/Calculating power of a number in python new file mode 100644 index 00000000..f9da35a2 --- /dev/null +++ b/Calculating power of a number in python @@ -0,0 +1,3 @@ +number=input("Enter the number: ") +power=input("Enter the power: ") +print(f"{number} raised to the power {power} is {number**power}") From 93d25389283be722485d01ba8b54b2b5648b285b Mon Sep 17 00:00:00 2001 From: dipanshumishra <67684227+dipanshumishra@users.noreply.github.com> Date: Thu, 15 Oct 2020 22:25:47 -0700 Subject: [PATCH 066/781] Create dflow-mishra.md --- dflow-mishra.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 dflow-mishra.md diff --git a/dflow-mishra.md b/dflow-mishra.md new file mode 100644 index 00000000..a93a5504 --- /dev/null +++ b/dflow-mishra.md @@ -0,0 +1,7 @@ +Dipanshu Mishra + +Photo:https://www.clipartkey.com/view/TTTxxT_no-copyright-logo-png/ + +Location:India + +Github:https://github.com/dipanshumishra From 0220da4715b37cb8ddaa521b1650e4d08f5452d7 Mon Sep 17 00:00:00 2001 From: vandana-kotnala <72218336+vandana-kotnala@users.noreply.github.com> Date: Thu, 15 Oct 2020 17:36:26 -1200 Subject: [PATCH 067/781] To perform arithmetic operations on two integers. --- ...orm To perform arithmetic operations on two integers. | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 perform To perform arithmetic operations on two integers. diff --git a/perform To perform arithmetic operations on two integers. b/perform To perform arithmetic operations on two integers. new file mode 100644 index 00000000..e1bd137d --- /dev/null +++ b/perform To perform arithmetic operations on two integers. @@ -0,0 +1,9 @@ +Read two input integers using input() or raw_input(). +Addition operation using + operator, num1 + num2 adds 2 numbers. +Subtraction operation using - operator, num1 - num2 right hand operand from left hand operand. +Multiplication operation using * operator, num1 * num2 multiplies 2 numbers. +Division operation using / operator, num1 / num2 divides left hand operand by right hand operand. +Floor Division operation using // operator, num1 // num2 divides left hand operand by right hand operand, here it removes the values after decimal point. +Modulus % operator when applied returns the remainder when left hand operand is divided by right hand operand num1 % num2. +Exponential operation using ** operator, num1 ** num2 returns value of num1 num2 +Print the result of each operation. From fc2d43cd203dece6cbd3b52cea34fb65b76dd5b5 Mon Sep 17 00:00:00 2001 From: tandrima16 <55499787+tandrima16@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:21:46 +0530 Subject: [PATCH 068/781] Create Fibonacci series using c c program for finding facrorial --- Fibonacci series using c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Fibonacci series using c diff --git a/Fibonacci series using c b/Fibonacci series using c new file mode 100644 index 00000000..006ed1b2 --- /dev/null +++ b/Fibonacci series using c @@ -0,0 +1,15 @@ +#include + +unsigned int factorial(unsigned int n) +{ + if (n == 0) + return 1; + return n * factorial(n - 1); +} + +int main() +{ + int num = 10; + printf("Factorial of %d is %d", num, factorial(num)); + return 0; +} From 913ce0aeee97e501f3cb37b8930377a9f1b0ec6a Mon Sep 17 00:00:00 2001 From: tandrima16 <55499787+tandrima16@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:41:40 +0530 Subject: [PATCH 069/781] Create binary to decimal conversion using c c program to convert binary no. to decimal no. --- binary to decimal conversion using c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 binary to decimal conversion using c diff --git a/binary to decimal conversion using c b/binary to decimal conversion using c new file mode 100644 index 00000000..5ada4dcd --- /dev/null +++ b/binary to decimal conversion using c @@ -0,0 +1,19 @@ +#include + +int main() +{ + int num, b_val, d_val = 0, base = 1, rem; + + printf("Enter a binary number(1s and 0s) \n"); + scanf("%d", &num); /* maximum five digits */ + binary_val = num; + while (num > 0) + { + rem = num % 10; + d_val = d_val + rem * base; + num = num / 10 ; + base = base * 2; + } + printf("The Binary number is = %d \n", b_val); + printf("Its decimal equivalent is = %d \n", d_val); +} From 6b73d16b6fb6ff105315281f3818b7e60603a7a1 Mon Sep 17 00:00:00 2001 From: tandrima16 <55499787+tandrima16@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:47:08 +0530 Subject: [PATCH 070/781] Create program to calculate the no. of vowels and consonants A C program that counts the total no of vowels and consonants --- ...calculate the no. of vowels and consonants | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 program to calculate the no. of vowels and consonants diff --git a/program to calculate the no. of vowels and consonants b/program to calculate the no. of vowels and consonants new file mode 100644 index 00000000..5c597a7b --- /dev/null +++ b/program to calculate the no. of vowels and consonants @@ -0,0 +1,32 @@ +#include +#include +#include + +#define str_size 100 +int main() +{ + char str[str_size]; + int i, len, vowel, cons; + + printf("Input the string : "); + fgets(str, sizeof str, stdin); + + vowel = 0; + cons = 0; + len = strlen(str); + + for(i=0; i='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z')) + { + cons++; + } + } + printf("\nThe total number of vowel in the string is : %d\n", vowel); + printf("The total number of consonant in the string is : %d\n\n", cons); +} From f60dacc1a071a28c5735f1931c385842dc4829c8 Mon Sep 17 00:00:00 2001 From: cssjai <59202490+cssjai@users.noreply.github.com> Date: Fri, 16 Oct 2020 12:10:14 +0530 Subject: [PATCH 071/781] Create printing the reverse of the array optimized code for printing the elements of the array in reverse order --- printing the reverse of the array | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 printing the reverse of the array diff --git a/printing the reverse of the array b/printing the reverse of the array new file mode 100644 index 00000000..4892daf6 --- /dev/null +++ b/printing the reverse of the array @@ -0,0 +1,14 @@ +#include +using namespace std; + +int main() +{ + int A[10] = {1,2,3,4,5,6,7,8,9,10}; + + cout<<"the reversed array is : "; + for(int i=9;i>=0;i--) + { + cout< Date: Fri, 16 Oct 2020 12:21:04 +0530 Subject: [PATCH 072/781] Create calculate power of number optimized code for calculating the power of a number --- calculate power of number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 calculate power of number diff --git a/calculate power of number b/calculate power of number new file mode 100644 index 00000000..ee40cf16 --- /dev/null +++ b/calculate power of number @@ -0,0 +1,14 @@ +#include +#include +using namespace std; + +int main() +{ + int p,e; + cout<<"enter the element and the power respectively"; + cin>>e>>p; + + cout<<"the "< Date: Fri, 16 Oct 2020 12:42:33 +0530 Subject: [PATCH 074/781] Create 3_matrix_multiplication_using_numpy.py This is multiplying 3 matrix using numpy in python and giving result in both order. --- 3_matrix_multiplication_using_numpy.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 3_matrix_multiplication_using_numpy.py diff --git a/3_matrix_multiplication_using_numpy.py b/3_matrix_multiplication_using_numpy.py new file mode 100644 index 00000000..03129fbb --- /dev/null +++ b/3_matrix_multiplication_using_numpy.py @@ -0,0 +1,23 @@ +import numpy as np + +np.random.seed(42) + +A = np.random.randint(0, 10, size=(2,2)) + +B = np.random.randint(0, 10, size=(2,3)) + +C = np.random.randint(0, 10, size=(3,3)) + +print("Matrix A is:\n{}, shape={}\n".format(A, A.shape)) + +print("Matrix B is:\n{}, shape={}\n".format(B, B.shape)) + +print("Matrix C is:\n{}, shape={}\n".format(C, C.shape)) + +D = np.matmul(np.matmul(A,B), C) + +print("Multiplication in the order (AB)C:\n\n{},shape={}\n".format(D, D.shape)) + +D = np.matmul(A, np.matmul(B,C)) + +print("Multiplication in the order A(BC):\n\n{},shape={}".format(D, D.shape)) From 8a69a6146c3c4f9e7e8a5561bda01eade13ab5fa Mon Sep 17 00:00:00 2001 From: cssjai <59202490+cssjai@users.noreply.github.com> Date: Fri, 16 Oct 2020 12:42:38 +0530 Subject: [PATCH 075/781] Create Binary to decimal optimized code for conversion of a binary number to decimal number --- Binary to decimal | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Binary to decimal diff --git a/Binary to decimal b/Binary to decimal new file mode 100644 index 00000000..baac2403 --- /dev/null +++ b/Binary to decimal @@ -0,0 +1,18 @@ +#include +#include +using namespace std; + +int main() +{ + long bi, deci = 0, j = 1, r; + cout << " Input a binary number: "; + cin>> bi; + while (bi != 0) + { + r = bi%10; + deci = deci + r*j; + j = j*2; + bi = bi/10; + } + cout<<" The decimal number: " << deci<<"\n"; +} From 435e279ca55ee1bcbce5934d3e09646e5756c84e Mon Sep 17 00:00:00 2001 From: Mitanshu Holkar Date: Fri, 16 Oct 2020 12:47:01 +0530 Subject: [PATCH 076/781] Create cpp program to find factorial of number Optimized CPP code for getting factorial of a number. --- cpp program to find factorial of number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 cpp program to find factorial of number diff --git a/cpp program to find factorial of number b/cpp program to find factorial of number new file mode 100644 index 00000000..d18c0983 --- /dev/null +++ b/cpp program to find factorial of number @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + unsigned int n; + unsigned long long factorial = 1; + + cout << "Enter a positive integer: "; + cin >> n; + + for(int i = 1; i <=n; ++i) + { + factorial *= i; + } + + cout << "Factorial of " << n << " = " << factorial; + return 0; +} From b7c5d4c9c990a6374ee2b54a1ee63a22ad7b8163 Mon Sep 17 00:00:00 2001 From: Niharikajain2812 Date: Fri, 16 Oct 2020 12:47:39 +0530 Subject: [PATCH 077/781] Create Prime Numbers Optimized code for Prime numbers --- Prime Numbers | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Prime Numbers diff --git a/Prime Numbers b/Prime Numbers new file mode 100644 index 00000000..f390a7ba --- /dev/null +++ b/Prime Numbers @@ -0,0 +1,23 @@ +#include +int main() { + int n, i, flag = 0; + printf("Enter a positive integer: "); + scanf("%d", &n); + for (i = 2; i <= n / 2; ++i) + { + if (n % i == 0) { + flag = 1; + break; + }} + if (n == 1) { + printf("1 is neither prime nor composite."); + } + else { + if (flag == 0) + printf("%d is a prime number.", n); + else + printf("%d is not a prime number.", n); + } + + return 0; +} From 6de5c4c0d110441def8265c153369fbbe2fcb83e Mon Sep 17 00:00:00 2001 From: Mitanshu Holkar Date: Fri, 16 Oct 2020 12:51:13 +0530 Subject: [PATCH 078/781] Create Python program to find largest element in array Optimized commented python code for finding largest element in an array --- Python program to find largest element in array | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Python program to find largest element in array diff --git a/Python program to find largest element in array b/Python program to find largest element in array new file mode 100644 index 00000000..e33c5118 --- /dev/null +++ b/Python program to find largest element in array @@ -0,0 +1,11 @@ +def largestFun(arr,n): #function to find the largest element in an array with two arguements - array and size of array. + maxNum = arr[0] #maximum element initialized + for i in range(1, n): #Traverse through the array to find the largest element + if arr[i] > maxNum: + maxNum = arr[i] + return maxNum + +arr = [13430, 33424, 45000, 56390, 938408] #Array intialized +n = len(arr) #Finding the length of array +largestElement = largestFun(arr,n) #Calling the function to find the largest element in the array. +print ("Largest element in the given array is",largestElement) #Printing output. From 2e03ed06f45f311cc32175dff2a476066e408c18 Mon Sep 17 00:00:00 2001 From: Jai Gupta Date: Fri, 16 Oct 2020 12:51:21 +0530 Subject: [PATCH 079/781] Create array sorting in python.py array sorting in python without using any builtin sorting function --- array sorting in python.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 array sorting in python.py diff --git a/array sorting in python.py b/array sorting in python.py new file mode 100644 index 00000000..5bcbb0ad --- /dev/null +++ b/array sorting in python.py @@ -0,0 +1,19 @@ +arr = [5, 2, 8, 7, 1]; +temp = 0; + +print("Elements of original array: "); +for i in range(0, len(arr)): + print(arr[i], end=" "); + +for i in range(0, len(arr)): + for j in range(i+1, len(arr)): + if(arr[i] > arr[j]): + temp = arr[i]; + arr[i] = arr[j]; + arr[j] = temp; + +print(); + +print("The final sorted array is: "); +for i in range(0, len(arr)): + print(arr[i], end=" "); From ab3426d4539daab8f6ca48bd888fa454b315cfb9 Mon Sep 17 00:00:00 2001 From: Mitanshu Holkar Date: Fri, 16 Oct 2020 12:54:20 +0530 Subject: [PATCH 080/781] Create CPP program to find smallest element in array Optimized cpp code for finding smallest element in an array --- CPP program to find smallest element in array | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CPP program to find smallest element in array diff --git a/CPP program to find smallest element in array b/CPP program to find smallest element in array new file mode 100644 index 00000000..9d69ab4b --- /dev/null +++ b/CPP program to find smallest element in array @@ -0,0 +1,23 @@ +#include +using namespace std; +int findSmallestElement(int arr[], int n){ + int temp = arr[0]; + for(int i=0; iarr[i]) { + temp=arr[i]; + } + } + return temp; +} +int main() { + int n; + cout<<"Enter the size of array: "; + cin>>n; int arr[n-1]; + cout<<"Enter array elements: "; + for(int i=0; i>arr[i]; + } + int smallest = findSmallestElement(arr, n); + cout<<"Smallest Element is: "< Date: Fri, 16 Oct 2020 12:54:38 +0530 Subject: [PATCH 081/781] Create Largest element in array in java Optimized code for Largest element in array in java --- Largest element in array in java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Largest element in array in java diff --git a/Largest element in array in java b/Largest element in array in java new file mode 100644 index 00000000..88f7f509 --- /dev/null +++ b/Largest element in array in java @@ -0,0 +1,20 @@ +class Test +{ + static int arr[] = {10, 324, 45, 90, 9808}; + + // Method to find maximum in arr[] + static int largest() + { + int i; + int max = arr[0]; + for (i = 1; i < arr.length; i++) + if (arr[i] > max) + max = arr[i]; + + return max; + } + public static void main(String[] args) + { + System.out.println("Largest in given array is " + largest()); + } + } From a58354ba858e907fa9403c16365254a5d9b4bf19 Mon Sep 17 00:00:00 2001 From: Mitanshu Holkar Date: Fri, 16 Oct 2020 12:56:34 +0530 Subject: [PATCH 082/781] Create C program to find length of a string Optimized C code for finding length of a string --- C program to find length of a string | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 C program to find length of a string diff --git a/C program to find length of a string b/C program to find length of a string new file mode 100644 index 00000000..c90dfe30 --- /dev/null +++ b/C program to find length of a string @@ -0,0 +1,17 @@ +#include +#include + +int main() +{ + char Str[100]; + int Length; + + printf("\n Please Enter any String \n"); + gets (Str); + + Length = strlen(Str); + + printf("Length of a String = %d\n", Length); + + return 0; +} From 182b4c0b1d750ea8f20db10bd41a4ef01d662fdd Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:12:43 +0530 Subject: [PATCH 083/781] Create HeartPattern.c program to print heart pattern in c language --- HeartPattern.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 HeartPattern.c diff --git a/HeartPattern.c b/HeartPattern.c new file mode 100644 index 00000000..0e5890fc --- /dev/null +++ b/HeartPattern.c @@ -0,0 +1,51 @@ +#include + +int main() +{ + int i, j, n; + + printf("Enter value of n : "); + scanf("%d", &n); + + for(i=n/2; i<=n; i+=2) + { + for(j=1; j=1; i--) + { + for(j=i; j Date: Fri, 16 Oct 2020 13:13:45 +0530 Subject: [PATCH 084/781] Create Python program to print ASCII value of given character Optimized code for finding/printing ASCII value of any character provided by the user. --- Python program to print ASCII value of given character | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Python program to print ASCII value of given character diff --git a/Python program to print ASCII value of given character b/Python program to print ASCII value of given character new file mode 100644 index 00000000..46f3c4d2 --- /dev/null +++ b/Python program to print ASCII value of given character @@ -0,0 +1,2 @@ +character=input() +print("The ASCII value of the given character is: ",ord(character)) From 08af74543c4ef780b2bab2c74f8ea3e500cebbaa Mon Sep 17 00:00:00 2001 From: Jai Gupta Date: Fri, 16 Oct 2020 13:15:59 +0530 Subject: [PATCH 085/781] Create Print_fibonacci_sequence_in_go.go program to print fibonacci in golang --- Print_fibonacci_sequence_in_go.go | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Print_fibonacci_sequence_in_go.go diff --git a/Print_fibonacci_sequence_in_go.go b/Print_fibonacci_sequence_in_go.go new file mode 100644 index 00000000..b9c92e43 --- /dev/null +++ b/Print_fibonacci_sequence_in_go.go @@ -0,0 +1,37 @@ +package main + +import ( + "fmt" + "strconv" +) + +func A(n int) int { + f := make([]int, n+1, n+2) + if n < 2 { + f = f[0:2] + } + f[0] = 0 + f[1] = 1 + for i := 2; i <= n; i++ { + f[i] = f[i-1] + f[i-2] + } + return f[n] +} + +func B(n int) int { + if n <= 1 { + return n + } + return B(n-1) + B(n-2) +} + +func main() { + for i := 0; i <= 9; i++ { + fmt.Print(strconv.Itoa(A(i)) + " ") + } + fmt.Println("") + for i := 0; i <= 9; i++ { + fmt.Print(strconv.Itoa(B(i)) + " ") + } + fmt.Println("") +} From 422f60b6abbece95f3ca5e31a6e5eb4d42003152 Mon Sep 17 00:00:00 2001 From: sinharitika009 Date: Fri, 16 Oct 2020 13:18:17 +0530 Subject: [PATCH 086/781] Update Factorial Of Number --- Factorial Of Number | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Factorial Of Number b/Factorial Of Number index b8476f7c..49cf63be 100644 --- a/Factorial Of Number +++ b/Factorial Of Number @@ -18,3 +18,13 @@ int factorial(int a) { return factorial(a)*factorial(a-1); } } + + +#using python to find factorial of a number +def factorial(n): + if(n <= 1): + return 1 + else: + return(n*factorial(n-1)) +n = int(input("Enter number:") +print(factorial(n)) From 4578632928e4a231ecce19c74b9715bdee0ffc0f Mon Sep 17 00:00:00 2001 From: Jai Gupta Date: Fri, 16 Oct 2020 13:21:31 +0530 Subject: [PATCH 087/781] Create arithmetic_oprations_in_java.java java program for doing basic arithmetic operations --- arithmetic_oprations_in_java.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 arithmetic_oprations_in_java.java diff --git a/arithmetic_oprations_in_java.java b/arithmetic_oprations_in_java.java new file mode 100644 index 00000000..e1d49c13 --- /dev/null +++ b/arithmetic_oprations_in_java.java @@ -0,0 +1,28 @@ +import java.util.Scanner; + +class Test +{ +public static void main(String args[]) +{ + int num1, num2; + int sum, sub, mult, mod; + float div; + Scanner op=new Scanner(System.in); + System.out.print("Enter 1st no: "); + num1=op.nextInt(); + System.out.print("Enter 2nd no:"); + num2=op.nextInt(); + + sum = num1 + num2; + sub = num1 - num2; + mult = num1 * num2; + div = (float)num1 / num2; + mod = num1 % num2; + + System.out.println("SUM = "+sum); + System.out.println("DIFF = "+sub); + System.out.println("PRODUCT = "+mult); + System.out.println("QUOTIENT = "+div); + System.out.println("MODULUS = "+mod); + } +} From 8da0a6be4826e333c0ece24862bc7de92c32b8c5 Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:22:31 +0530 Subject: [PATCH 088/781] binary to decimal converter --- Binary to decimal converter | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/Binary to decimal converter b/Binary to decimal converter index da2c287d..62752959 100644 --- a/Binary to decimal converter +++ b/Binary to decimal converter @@ -1,9 +1,31 @@ -import java.util.Scanner; -class BinaryToDecimal { - public static void main(String args[]){ - Scanner input = new Scanner( System.in ); - System.out.print("Enter a binary number: "); - String binaryString =input.nextLine(); - System.out.println("Output: "+Integer.parseInt(binaryString,2)); +#include +using namespace std; + + +int binaryToDecimal(int n) +{ + int num = n; + int dec_value = 0; + + // Initializing base value to 1, i.e 2^0 + int base = 1; + + int temp = num; + while (temp) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base; + + base = base * 2; } + + return dec_value; +} + +int main() +{ + int num = 10101001; + + cout << binaryToDecimal(num) << endl; } From dd2d740bdade12ad36dc58cf2c5b15e9f9dba401 Mon Sep 17 00:00:00 2001 From: Niharikajain2812 Date: Fri, 16 Oct 2020 13:25:16 +0530 Subject: [PATCH 089/781] Create Program to print ASCII value of given character in JAVA Optimized Program to print ASCII value of given character --- ...ram to print ASCII value of given character in JAVA | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program to print ASCII value of given character in JAVA diff --git a/Program to print ASCII value of given character in JAVA b/Program to print ASCII value of given character in JAVA new file mode 100644 index 00000000..0ba9ad03 --- /dev/null +++ b/Program to print ASCII value of given character in JAVA @@ -0,0 +1,10 @@ +public class AsciiValue { + + public static void main(String[] args) + { + + char c = 'e'; + int ascii = c; + System.out.println("The ASCII value of " + c + " is: " + ascii); + } +} From 184b68e1041a5169b4715867d66e3a42486e0cef Mon Sep 17 00:00:00 2001 From: sinharitika009 Date: Fri, 16 Oct 2020 13:25:37 +0530 Subject: [PATCH 090/781] Create Factorial of a number using python --- Factorial of a number using python | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Factorial of a number using python diff --git a/Factorial of a number using python b/Factorial of a number using python new file mode 100644 index 00000000..bb0fa689 --- /dev/null +++ b/Factorial of a number using python @@ -0,0 +1,9 @@ +#using python +def factorial(n): + if(n <= 1): + return 1 + else: + return(n*factorial(n-1)) +n = int(input("Enter number:")) +print("The required output:") +print(factorial(n)) From a18968b2968e4bf244475412a5dba3e784032774 Mon Sep 17 00:00:00 2001 From: Niharikajain2812 Date: Fri, 16 Oct 2020 13:28:59 +0530 Subject: [PATCH 091/781] Create Program to calculate power of number in JAVA Optimized Program to calculate power of number. --- Program to calculate power of number in JAVA | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Program to calculate power of number in JAVA diff --git a/Program to calculate power of number in JAVA b/Program to calculate power of number in JAVA new file mode 100644 index 00000000..f4b492e2 --- /dev/null +++ b/Program to calculate power of number in JAVA @@ -0,0 +1,17 @@ +public class Power { + + public static void main(String[] args) { + + int base = 3, exponent = 4; + + long result = 1; + + while (exponent != 0) + { + result *= base; + --exponent; + } + + System.out.println("Answer = " + result); + } +} From 227c7101915eef7b508ccbd8aa4b8919cee817a9 Mon Sep 17 00:00:00 2001 From: Encryptor <62632966+Encryptor-Sec@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:35:56 +0530 Subject: [PATCH 092/781] Create Program to calculate count of vowels & consonants in string by Encryptor-Sec Efficient python program to check the total number of vowels and consonants in a sentence or word --- ... of vowels & consonants in string by Encryptor-Sec | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Program to calculate count of vowels & consonants in string by Encryptor-Sec diff --git a/Program to calculate count of vowels & consonants in string by Encryptor-Sec b/Program to calculate count of vowels & consonants in string by Encryptor-Sec new file mode 100644 index 00000000..653a5cec --- /dev/null +++ b/Program to calculate count of vowels & consonants in string by Encryptor-Sec @@ -0,0 +1,11 @@ +vcount = 0; +ccount = 0; +str = str(input('Enter a String: ')) +str = str.lower(); +for i in range(0,len(str)): + if str[i] in ('a',"e","i","o","u"): + vcount = vcount + 1; + elif (str[i] >= 'a' and str[i] <= 'z'): + ccount = ccount + 1; +print("Total Vowels :",vcount); +print("Total consonant :",ccount); From 730f785d45f5572c271cc5b7cba3d54a548fee1a Mon Sep 17 00:00:00 2001 From: MukeshBahuguna <52329826+MukeshBahuguna@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:36:37 +0530 Subject: [PATCH 093/781] Create Python Program to print Fibonacci Series Using recursion prints Fibonacci series in a single line. --- Python Program to print Fibonacci Series | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Python Program to print Fibonacci Series diff --git a/Python Program to print Fibonacci Series b/Python Program to print Fibonacci Series new file mode 100644 index 00000000..2e75fa3b --- /dev/null +++ b/Python Program to print Fibonacci Series @@ -0,0 +1,9 @@ +n=int(input('Input the number: ')) +def fib(a=0,b=1): + if b>=n+1: + return a + else: + print( a ,end=' ') + a,b=b,a+b + return fib(a,b) +print(fib()) From 252bce825423fd4ab5f33645f8f6a38eaaeea3b8 Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:43:20 +0530 Subject: [PATCH 094/781] Create in php --- to find factorial of number/in php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 to find factorial of number/in php diff --git a/to find factorial of number/in php b/to find factorial of number/in php new file mode 100644 index 00000000..a72922ab --- /dev/null +++ b/to find factorial of number/in php @@ -0,0 +1,16 @@ + From acc306ae3d4ba83aabd625b4b822c800e5a42e66 Mon Sep 17 00:00:00 2001 From: anmolrk <60808502+anmolrk@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:45:55 +0530 Subject: [PATCH 095/781] Create Program to print prime numbers in given range user input Optimized code for Program to print prime numbers in the given range where the user provides the limits and the prime no. prints --- ...nt prime numbers in given range user input | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Program to print prime numbers in given range user input diff --git a/Program to print prime numbers in given range user input b/Program to print prime numbers in given range user input new file mode 100644 index 00000000..8a40e4ca --- /dev/null +++ b/Program to print prime numbers in given range user input @@ -0,0 +1,54 @@ +// C++ program to find the prime numbers between a given interval +#include +using namespace std; + +// Function for print prime +// number in given range +void primeInRange(int L, int R) +{ + int flag; + + // Traverse each number in the + // interval with the help of for loop + for (int i = L; i <= R; i++) { + + // Skip 0 and 1 as they are + // niether prime nor composite + if (i == 1 || i == 0) + continue; + + // flag variable to tell + // if i is prime or not + flag = 1; + + // Iterate to check if i is prime + // or not + for (int j = 2; j <= i / 2; ++j) { + if (i % j == 0) { + flag = 0; + break; + } + } + + // flag = 1 means i is prime + // and flag = 0 means i is not prime + if (flag == 1) + cout << i << " "; + } +} + +// Driver Code +int main() +{ + int L,R; + // Given Range + cout<<"Enter the beginning number of the list"<>L; + cout<<"Enter the last number of the list"<>R; + + // Function Call + primeInRange(L, R); + + return 0; +} From e28346325ed8f7ad57ffa61ec2858968dca0dc4d Mon Sep 17 00:00:00 2001 From: tandrima16 <55499787+tandrima16@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:49:22 +0530 Subject: [PATCH 096/781] Create C program to find prime no. in a given range C program that finds prime no. in a given range --- C program to find prime no. in a given range | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 C program to find prime no. in a given range diff --git a/C program to find prime no. in a given range b/C program to find prime no. in a given range new file mode 100644 index 00000000..9b64644e --- /dev/null +++ b/C program to find prime no. in a given range @@ -0,0 +1,29 @@ +#include + +int main(){ + int num,i,ctr,m,n; + + printf("Input starting number of range: "); + scanf("%d",&m); + + printf("Input ending number of range : "); + scanf("%d",&n); + printf("The prime numbers between %d and %d are : \n",m,n); + + for(num = m;num<=n;num++) + { + ctr = 0; + + for(i=2;i<=num/2;i++) + { + if(num%i==0){ + ctr++; + break; + } + } + + if(ctr==0 && num!= 1) + printf("%d ",num); + } +printf("\n"); +} From 00e733a93c8d121d3b7a39d811ce5643d38a87ab Mon Sep 17 00:00:00 2001 From: Muhammad Arif Ramadhani <63437285+ariframadhan01@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:25:10 +0700 Subject: [PATCH 097/781] Create new of elements in array Optimized Code For Getting Sum of Elements in an array quickly --- new of elements in array | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 new of elements in array diff --git a/new of elements in array b/new of elements in array new file mode 100644 index 00000000..45c0659b --- /dev/null +++ b/new of elements in array @@ -0,0 +1,19 @@ +#include +using namespace std; + +int x,y; +int tabel[3][5] = { + {1, 2, 3, 4, 5}, + {2, 4, 6, 8, 10}, + {3, 6, 9, 12, 15} + }; + +int main () +{ + for (x=0; x<3; x++) + for (y=0; y<5; y++) + { + cout << tabel[x][y] << " "; + } + cout << "\n"; +} From d9a81296e2920034a71d4116fa72cb990a6f3cc4 Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:56:44 +0530 Subject: [PATCH 098/781] Create c# in c# --- to find factorial of number/c# | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 to find factorial of number/c# diff --git a/to find factorial of number/c# b/to find factorial of number/c# new file mode 100644 index 00000000..b9984f17 --- /dev/null +++ b/to find factorial of number/c# @@ -0,0 +1,22 @@ +using System; + +class Test { + // method to find factorial + // of given number + static int factorial(int n) + { + if (n == 0) + return 1; + + return n * factorial(n - 1); + } + + + public static void Main() + { + int num = 5; + Console.WriteLine("Factorial of " + + num + " is " + factorial(5)); + } +} + From 2745169f211877e42d29bb94a127607b25191e94 Mon Sep 17 00:00:00 2001 From: MukeshBahuguna <52329826+MukeshBahuguna@users.noreply.github.com> Date: Fri, 16 Oct 2020 13:57:45 +0530 Subject: [PATCH 099/781] Create Python Program to convert binary to octal number Optimized way of converting a binary number into its octal form. --- Python Program to convert binary to octal number | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Python Program to convert binary to octal number diff --git a/Python Program to convert binary to octal number b/Python Program to convert binary to octal number new file mode 100644 index 00000000..4f3d31b1 --- /dev/null +++ b/Python Program to convert binary to octal number @@ -0,0 +1,3 @@ +n=input("Input the binary number that you want to convert: ") +a=int(n,2) +print("The octal rep. of the given binary number is: ", oct(a)) From e862a64a1aba942edf5ebb4734a350a77113e8d0 Mon Sep 17 00:00:00 2001 From: Encryptor <62632966+Encryptor-Sec@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:03:12 +0530 Subject: [PATCH 100/781] Create Program to find power of any number by Encryptor-Sec A program written in C for calculating power of a given number and it's exponent --- ...to find power of any number by Encryptor-Sec | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program to find power of any number by Encryptor-Sec diff --git a/Program to find power of any number by Encryptor-Sec b/Program to find power of any number by Encryptor-Sec new file mode 100644 index 00000000..e7d59525 --- /dev/null +++ b/Program to find power of any number by Encryptor-Sec @@ -0,0 +1,16 @@ +#include +int main() { + int base, exp; + long long result = 1; + printf("Enter a base number: "); + scanf("%d", &base); + printf("Enter an exponent: "); + scanf("%d", &exp); + + while (exp != 0) { + result *= base; + --exp; + } + printf("Answer = %lld", result); + return 0; +} From d6b30a2e571a3ff36b50ce057828806869dfbaaf Mon Sep 17 00:00:00 2001 From: Akash kumar maurya <71809598+akash5256@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:06:03 +0530 Subject: [PATCH 101/781] Create binary to octal code --- binary to octal code | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 binary to octal code diff --git a/binary to octal code b/binary to octal code new file mode 100644 index 00000000..e67c7da4 --- /dev/null +++ b/binary to octal code @@ -0,0 +1,34 @@ +import java.util.*; +public class Main +{ +public static int binary_to_octal( int binary) +{ +int octal = 0, decimal = 0, i = 0; + +while(binary != 0) +{ +decimal += (binary%10) * Math.pow(2,i); +++i; +binary/=10; +} + +i = 1; + +while (decimal != 0) +{ +octal += (decimal % 8) * i; +decimal /= 8; +i *= 10; +} + +return octal; +} + +public static void main(String[] args) +{ +Scanner sc = new Scanner(System.in); +System.out.print(“Enter the binary number : “); +int binary = sc.nextInt(); +System.out.print(“\nEquivalent octal number : ” + binary_to_octal(binary)); +} +} From 1bfe2cf50be495260a467fb01cbd9d7102eb4a19 Mon Sep 17 00:00:00 2001 From: Akash kumar maurya <71809598+akash5256@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:08:41 +0530 Subject: [PATCH 102/781] Create adding two number --- adding two number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 adding two number diff --git a/adding two number b/adding two number new file mode 100644 index 00000000..c7a914fb --- /dev/null +++ b/adding two number @@ -0,0 +1,14 @@ +#include +int main() +{ + int x, y, z; + + printf("Enter two numbers to add\n"); + scanf("%d%d", &x, &y); + + z = x + y; + + printf("Sum of the numbers = %d\n", z); + + return 0; +} From 0c54675ab93231ec919f5e36af952cf8c6824989 Mon Sep 17 00:00:00 2001 From: Mrityunjay <59202490+cssjai@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:10:09 +0530 Subject: [PATCH 103/781] Create factorial of any number optimized code for calculating the factorial of a number --- factorial of any number | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 factorial of any number diff --git a/factorial of any number b/factorial of any number new file mode 100644 index 00000000..6e8b10e0 --- /dev/null +++ b/factorial of any number @@ -0,0 +1,17 @@ +#include +using namespace std; + +long facto(long n) +{ + if (n == 0) + return 1; + return n * facto(n - 1); +} + +int main() +{ + long num ; + cin>>num; + cout << "Factorial of "<< num << " is = " << facto(num) << endl; + return 0; +} From 52c1dc5be9e95970aacedae74b2360f058853f66 Mon Sep 17 00:00:00 2001 From: Kamasani Chaithanya Date: Fri, 16 Oct 2020 14:17:46 +0530 Subject: [PATCH 104/781] Create c for linearsearch --- c for linearsearch | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 c for linearsearch diff --git a/c for linearsearch b/c for linearsearch new file mode 100644 index 00000000..8e625c7c --- /dev/null +++ b/c for linearsearch @@ -0,0 +1,29 @@ +#include +int main() +{ + int array[100], search, c, n; + + printf("Enter number of elements in array\n"); + scanf("%d", &n); + + printf("Enter %d integer(s)\n", n); + + for (c = 0; c < n; c++) + scanf("%d", &array[c]); + + printf("Enter a number to search\n"); + scanf("%d", &search); + + for (c = 0; c < n; c++) + { + if (array[c] == search) /* If required element is found */ + { + printf("%d is present at location %d.\n", search, c+1); + break; + } + } + if (c == n) + printf("%d isn't present in the array.\n", search); + + return 0; +} From 53e19b2647fc7bb1bb6c3127889f59a965db2483 Mon Sep 17 00:00:00 2001 From: Coder-Gautam <72969264+Coder-Gautam@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:18:02 +0530 Subject: [PATCH 105/781] Program to find factorial Program to find factorial using C++ --- C++ Program to Find Factorial | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 C++ Program to Find Factorial diff --git a/C++ Program to Find Factorial b/C++ Program to Find Factorial new file mode 100644 index 00000000..810be643 --- /dev/null +++ b/C++ Program to Find Factorial @@ -0,0 +1,13 @@ +#include +using namespace std; +int fact(int n) { + if ((n==0)||(n==1)) + return 1; + else + return n*fact(n-1); +} +int main() { + int n = 5; + cout<<"Factorial of "< Date: Fri, 16 Oct 2020 14:18:13 +0530 Subject: [PATCH 106/781] Add files via upload --- SinglyLinkedList.cpp | 237 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 SinglyLinkedList.cpp diff --git a/SinglyLinkedList.cpp b/SinglyLinkedList.cpp new file mode 100644 index 00000000..65b54ef2 --- /dev/null +++ b/SinglyLinkedList.cpp @@ -0,0 +1,237 @@ +#include + +using namespace std; + +class Node { + public: + int key; + int data; + Node * next; + + Node() { + key = 0; + data = 0; + next = NULL; + } + Node(int k, int d) { + key = k; + data = d; + } +}; + +class SinglyLinkedList { + public: + Node * head; + + SinglyLinkedList() { + head = NULL; + } + SinglyLinkedList(Node * n) { + head = n; + } + + // 1. CHeck if node exists using key value + Node * nodeExists(int k) { + Node * temp = NULL; + + Node * ptr = head; + while (ptr != NULL) { + if (ptr -> key == k) { + temp = ptr; + } + ptr = ptr -> next; + + } + return temp; + } + + // 2. Append a node to the list + void appendNode(Node * n) { + if (nodeExists(n -> key) != NULL) { + cout << "Node Already exists with key value : " << n -> key << ". Append another node with different Key value" << endl; + } else { + if (head == NULL) { + head = n; + cout << "Node Appended" << endl; + } else { + Node * ptr = head; + while (ptr -> next != NULL) { + ptr = ptr -> next; + } + ptr -> next = n; + cout << "Node Appended" << endl; + } + } + + } + // 3. Prepend Node - Attach a node at the start + void prependNode(Node * n) { + if (nodeExists(n -> key) != NULL) { + cout << "Node Already exists with key value : " << n -> key << ". Append another node with different Key value" << endl; + } else { + n -> next = head; + head = n; + cout << "Node Prepended" << endl; + } + } + + // 4. Insert a Node after a particular node in the list + void insertNodeAfter(int k, Node * n) { + Node * ptr = nodeExists(k); + if (ptr == NULL) { + cout << "No node exists with key value: " << k << endl; + } else { + if (nodeExists(n -> key) != NULL) { + cout << "Node Already exists with key value : " << n -> key << ". Append another node with different Key value" << endl; + } else { + n -> next = ptr -> next; + ptr -> next = n; + cout << "Node Inserted" << endl; + } + } + } + + // 5. Delete node by unique key + void deleteNodeByKey(int k) { + if (head == NULL) { + cout << "Singly Linked List already Empty. Cant delete" << endl; + } else if (head != NULL) { + if (head -> key == k) { + head = head -> next; + cout << "Node UNLINKED with keys value : " << k << endl; + } else { + Node * temp = NULL; + Node * prevptr = head; + Node * currentptr = head -> next; + while (currentptr != NULL) { + if (currentptr -> key == k) { + temp = currentptr; + currentptr = NULL; + } else { + prevptr = prevptr -> next; + currentptr = currentptr -> next; + } + } + if (temp != NULL) { + prevptr -> next = temp -> next; + cout << "Node UNLINKED with keys value : " << k << endl; + } else { + cout << "Node Doesn't exist with key value : " << k << endl; + } + } + } + + } + // 6th update node + void updateNodeByKey(int k, int d) { + + Node * ptr = nodeExists(k); + if (ptr != NULL) { + ptr -> data = d; + cout << "Node Data Updated Successfully" << endl; + } else { + cout << "Node Doesn't exist with key value : " << k << endl; + } + + } + + // 7th printing + void printList() { + if (head == NULL) { + cout << "No Nodes in Singly Linked List"; + } else { + cout << endl << "Singly Linked List Values : "; + Node * temp = head; + + while (temp != NULL) { + cout << "(" << temp -> key << "," << temp -> data << ") --> "; + temp = temp -> next; + } + } + + } + +}; + +int main() { + + SinglyLinkedList s; + int option; + int key1, k1, data1; + do { + cout << "\nWhat operation do you want to perform? Select Option number. Enter 0 to exit." << endl; + cout << "1. appendNode()" << endl; + cout << "2. prependNode()" << endl; + cout << "3. insertNodeAfter()" << endl; + cout << "4. deleteNodeByKey()" << endl; + cout << "5. updateNodeByKey()" << endl; + cout << "6. print()" << endl; + cout << "7. Clear Screen" << endl << endl; + + cin >> option; + Node * n1 = new Node(); + //Node n1; + + switch (option) { + case 0: + break; + case 1: + cout << "Append Node Operation \nEnter key & data of the Node to be Appended" << endl; + cin >> key1; + cin >> data1; + n1 -> key = key1; + n1 -> data = data1; + s.appendNode(n1); + //cout<> key1; + cin >> data1; + n1 -> key = key1; + n1 -> data = data1; + s.prependNode(n1); + break; + + case 3: + cout << "Insert Node After Operation \nEnter key of existing Node after which you want to Insert this New node: " << endl; + cin >> k1; + cout << "Enter key & data of the New Node first: " << endl; + cin >> key1; + cin >> data1; + n1 -> key = key1; + n1 -> data = data1; + + s.insertNodeAfter(k1, n1); + break; + + case 4: + + cout << "Delete Node By Key Operation - \nEnter key of the Node to be deleted: " << endl; + cin >> k1; + s.deleteNodeByKey(k1); + + break; + case 5: + cout << "Update Node By Key Operation - \nEnter key & NEW data to be updated" << endl; + cin >> key1; + cin >> data1; + s.updateNodeByKey(key1, data1); + + break; + case 6: + s.printList(); + + break; + case 7: + system("clear"); + break; + default: + cout << "Enter Proper Option number " << endl; + } + + } while (option != 0); + + return 0; +} \ No newline at end of file From 583140460e3e13806ba91830d700e21d351d6d1a Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:19:43 +0530 Subject: [PATCH 107/781] Update Program to convert binary to decimal number --- ...rogram to convert binary to decimal number | 45 ++++++++++++------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/Program to convert binary to decimal numberdef binaryToDecimal(n): num = n; dec_value = 0; # Initializing base # value to 1, i.e 2 ^ 0 base = 1; temp = num; while(temp): last_digit = temp % 10; temp = int(temp/Program to convert binary to decimal number b/Program to convert binary to decimal numberdef binaryToDecimal(n): num = n; dec_value = 0; # Initializing base # value to 1, i.e 2 ^ 0 base = 1; temp = num; while(temp): last_digit = temp % 10; temp = int(temp/Program to convert binary to decimal number index 84f768b5..2d64742f 100644 --- a/Program to convert binary to decimal numberdef binaryToDecimal(n): num = n; dec_value = 0; # Initializing base # value to 1, i.e 2 ^ 0 base = 1; temp = num; while(temp): last_digit = temp % 10; temp = int(temp/Program to convert binary to decimal number +++ b/Program to convert binary to decimal numberdef binaryToDecimal(n): num = n; dec_value = 0; # Initializing base # value to 1, i.e 2 ^ 0 base = 1; temp = num; while(temp): last_digit = temp % 10; temp = int(temp/Program to convert binary to decimal number @@ -1,17 +1,30 @@ -def binaryToDecimal(n): - num = n; - dec_value = 0; - - base = 1; - - temp = num; - while(temp): - last_digit = temp % 10; - temp = int(temp / 10); - - dec_value += last_digit * base; - base = base * 2; - return dec_value; +class GFG { + public static int binaryToDecimal(int n) + { + int num = n; + int dec_value = 0; -num = 10101001; -print(binaryToDecimal(num)); + // Initializing base1 + // value to 1, i.e 2^0 + int base1 = 1; + + int temp = num; + while (temp > 0) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base1; + + base1 = base1 * 2; + } + + return dec_value; + } + + public static void Main() + { + int num = 10101001; + + System.Console.Write(binaryToDecimal(num)); + } +} From 28bfcf2c50ece08c0f0eb5944881487157a1a492 Mon Sep 17 00:00:00 2001 From: Sandesh2003 <72540199+Sandesh2003@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:24:51 +0530 Subject: [PATCH 108/781] Python arithmetic operations Example This is help to do operations. --- Python arithmetic operations Example | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Python arithmetic operations Example diff --git a/Python arithmetic operations Example b/Python arithmetic operations Example new file mode 100644 index 00000000..99c09e6b --- /dev/null +++ b/Python arithmetic operations Example @@ -0,0 +1,16 @@ +>>> a = 12 +>>> b = 3 +>>> addition = a + b +>>> subtraction = a - b +>>> multiplication = a * b +>>> division = a / b +>>> modulus = a % b +>>> exponent = a ** b +>>> Floor_Division = a // b +>>> print("Addition of two numbers 12 and 3 is : ", addition) +>>> print("Subtracting Number 3 from 12 is : ", subtraction) +>>> print("Multiplication of two numbers 12 and 3 is : ", multiplication) +>>> print("Division of two numbers 12 and 3 is : ", division) +>>> print("Modulus of two numbers 12 and 3 is : ", modulus) +>>> print("Exponent of two numbers 12 and 3 is : ", exponent) +>>> print("Floor Division of two numbers 12 and 3 is : ", Floor_Division) From c4bcf9863c482b471b0607c2827ead32a995e202 Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:25:14 +0530 Subject: [PATCH 109/781] fibonacci series in java --- Fibonnaci Series/Java | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/Fibonnaci Series/Java b/Fibonnaci Series/Java index 7326348a..05ec767b 100644 --- a/Fibonnaci Series/Java +++ b/Fibonnaci Series/Java @@ -1,15 +1,16 @@ -class FibonacciExample1{ -public static void main(String args[]) -{ - int n1=0,n2=1,n3,i,count=10; - System.out.print(n1+" "+n2);//printing 0 and 1 - - for(i=2;i Date: Fri, 16 Oct 2020 14:26:42 +0530 Subject: [PATCH 110/781] Find the Largest and Smallest Elements in an Array C++ Program to Find the Largest and Smallest Elements in an Array --- ... Largest and Smallest Elements in an Array | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 C++ to Find the Largest and Smallest Elements in an Array diff --git a/C++ to Find the Largest and Smallest Elements in an Array b/C++ to Find the Largest and Smallest Elements in an Array new file mode 100644 index 00000000..f9f1d337 --- /dev/null +++ b/C++ to Find the Largest and Smallest Elements in an Array @@ -0,0 +1,26 @@ +#include +using namespace std; +int main () +{ + int arr[10], n, i, max, min; + cout << "Enter the size of the array : "; + cin >> n; + cout << "Enter the elements of the array : "; + for (i = 0; i < n; i++) + cin >> arr[i]; + max = arr[0]; + for (i = 0; i < n; i++) + { + if (max < arr[i]) + max = arr[i]; + } + min = arr[0]; + for (i = 0; i < n; i++) + { + if (min > arr[i]) + min = arr[i]; + } + cout << "Largest element : " << max; + cout << "Smallest element : " << min; + return 0; +} From 088905aefeeaf8a602392351090de52a363afb8e Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:29:52 +0530 Subject: [PATCH 111/781] updated java --- to find factorial of number/in java | 32 ++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/to find factorial of number/in java b/to find factorial of number/in java index ae621fea..4d431984 100644 --- a/to find factorial of number/in java +++ b/to find factorial of number/in java @@ -1,14 +1,18 @@ -public class Factorial { - - public static void main(String[] args) { - - int num = 10; - long factorial = 1; - for(int i = 1; i <= num; ++i) - { - // factorial = factorial * i; - factorial *= i; - } - System.out.printf("Factorial of %d = %d", num, factorial); - } -} +class Factorial { + + int factorial(int n) + { + + // single line to find factorial + return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); + } + + public static void main(String args[]) + { + Factorial obj = new Factorial(); + int num = 5; + System.out.println( + "Factorial of " + num + + " is " + obj.factorial(num)); + } +} From b15cec9054fbcb703e13cff5e9bc13669c2f7c37 Mon Sep 17 00:00:00 2001 From: Kamasani Chaithanya Date: Fri, 16 Oct 2020 14:30:01 +0530 Subject: [PATCH 112/781] Create pressmebuttongame in c --- pressmebuttongame in c | 189 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 pressmebuttongame in c diff --git a/pressmebuttongame in c b/pressmebuttongame in c new file mode 100644 index 00000000..2ea417d3 --- /dev/null +++ b/pressmebuttongame in c @@ -0,0 +1,189 @@ +#include +#include +#include +#include +#include +union REGS i, o; +int left = 265, top = 250; + +void initialize_graphics_mode() +{ + int gd = DETECT, gm, error; + + initgraph(&gd,&gm,"C:\\TC\\BGI"); + + error = graphresult(); + + if (error != grOk) + { + perror("Error "); + printf("Press any key to exit...\n"); + getch(); + exit(EXIT_FAILURE); + } +} + +void showmouseptr() +{ + i.x.ax = 1; + int86(0x33, &i, &o); +} + +void hidemouseptr() +{ + i.x.ax = 2; + int86(0x33, &i, &o); +} + +void getmousepos(int *x,int *y) +{ + i.x.ax = 3; + int86(0x33, &i, &o); + + *x = o.x.cx; + *y = o.x.dx; +} + +void draw_bar() +{ + hidemouseptr(); + setfillstyle(SOLID_FILL,CYAN); + bar(190,180,450,350); + showmouseptr(); +} + +void draw_button(int x, int y) +{ + hidemouseptr(); + setfillstyle(SOLID_FILL,MAGENTA); + bar(x,y,x+100,y+30); + moveto(x+5,y); + setcolor(YELLOW); + outtext("Press me"); + showmouseptr(); +} + +void draw() +{ + settextstyle(SANS_SERIF_FONT,HORIZ_DIR,2); + outtextxy(155,451,"www.programmingsimplified.com"); + setcolor(BLUE); + rectangle(0,0,639,450); + setcolor(RED); + outtextxy(160,25,"Try to press the \"Press me\" button"); + outtextxy(210,50,"Press escape key to exit"); + setfillstyle(XHATCH_FILL,GREEN); + setcolor(BLUE); + bar(1,1,75,449); + bar(565,1,638,449); + showmouseptr(); + draw_bar(); + draw_button(left,top); +} + +void initialize() +{ + initialize_graphics_mode(); + + if( !initmouse() ) + { + closegraph(); + printf("Unable to initialize the mouse"); + printf("Press any key to exit...\n"); + getch(); + exit(EXIT_SUCCESS); + } + + draw(); +} + +int initmouse() +{ + i.x.ax = 0; + int86(0x33, &i, &o); + return ( o.x.ax ); +} + +void get_input() +{ + int x, y; + + while(1) + { + getmousepos(&x,&y); + + /* mouse pointer in left of button */ + + if( x >= (left-3) && y >= (top-3) && y <= (top+30+3) && x < left ) + { + draw_bar(); + left = left + 4; + + if (left > 350) + left = 190; + + draw_button(left,top); + } + + /* mouse pointer in right of button */ + + else if (x<=(left+100+3)&&y>=(top-3)&&y<=(top+30+3)&&x>(left+100)) + { + draw_bar(); + left = left - 4; + + if (left < 190) + left = 350; + + draw_button(left,top); + } + + /* mouse pointer above button */ + + else if(x>(left-3) && y>=(top-3) && y<(top) && x<= (left+100+3)) + { + draw_bar(); + top = top + 4; + + if (top > 320) + top = 180; + + draw_button(left,top); + } + + /* mouse pointer below button */ + + else if (x>(left-3)&&y>(top+30)&&y<=(top+30+3)&&x<=(left+100+3)) + { + draw_bar(); + top = top - 4; + + if (top < 180) + top = 320; + + draw_button(left,top); + } + + if (kbhit()) + { + if (getkey() == 1) + exit(EXIT_SUCCESS); + } + } +} + +int getkey() +{ + i.h.ah = 0; + int86(22, &i, &o); + + return( o.h.ah ); +} + +main() +{ + initialize(); + + get_input(); + return 0; +} From 08afeb8085b8249ea87fff09e441ba1b8224c71f Mon Sep 17 00:00:00 2001 From: Sandesh2003 <72540199+Sandesh2003@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:30:38 +0530 Subject: [PATCH 113/781] Two integers sum Two integer variables a and Sum. --- Two integer sum. | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Two integer sum. diff --git a/Two integer sum. b/Two integer sum. new file mode 100644 index 00000000..0230c685 --- /dev/null +++ b/Two integer sum. @@ -0,0 +1,22 @@ +// Program for Java Assignment Operators +package JavaOperators; + +import java.util.Scanner; + +public class AssignmentOperators { + private static Scanner sc; + public static void main(String[] args) { + int a, Sum; + sc = new Scanner(System.in); + System.out.println(" Please Enter any integer Value: "); + a = sc.nextInt(); + System.out.println(" Please Enter any integer Value for Total: "); + Sum = sc.nextInt(); + + System.out.format(" Value of Sum = %d \n", Sum += a ); + System.out.format(" Value of Sum = %d \n", Sum -= a ); + System.out.format(" Value of Sum = %d \n", Sum *= a ); + System.out.format(" Value of Sum = %d \n", Sum /= a ); + System.out.format(" Value of Sum = %d \n", Sum %= a ); + } +} From edbbae7cfe2e10b86323eeb60816017b282dc803 Mon Sep 17 00:00:00 2001 From: Kamasani Chaithanya Date: Fri, 16 Oct 2020 14:32:08 +0530 Subject: [PATCH 114/781] Create floydls triangle --- floydls triangle | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 floydls triangle diff --git a/floydls triangle b/floydls triangle new file mode 100644 index 00000000..63b2b340 --- /dev/null +++ b/floydls triangle @@ -0,0 +1,20 @@ +#include +int main() +{ + int n, i, c, a = 1; + + printf("Enter the number of rows of Floyd's triangle to print\n"); + scanf("%d", &n); + + for (i = 1; i <= n; i++) + { + for (c = 1; c <= i; c++) + { + printf("%d ", a); // Please note space after %d + a++; + } + printf("\n"); + } + + return 0; +} From 760be3e02d070ddcdae5863e01a873832b7ca32e Mon Sep 17 00:00:00 2001 From: Encryptor <62632966+Encryptor-Sec@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:32:12 +0530 Subject: [PATCH 115/781] Create Program to Convert Binary Number to Octal by Encryptor-Sec C program to calculate binary to octal and vice versa --- ...t Binary Number to Octal by Encryptor-Sec | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Program to Convert Binary Number to Octal by Encryptor-Sec diff --git a/Program to Convert Binary Number to Octal by Encryptor-Sec b/Program to Convert Binary Number to Octal by Encryptor-Sec new file mode 100644 index 00000000..ba2a8920 --- /dev/null +++ b/Program to Convert Binary Number to Octal by Encryptor-Sec @@ -0,0 +1,29 @@ +#include +#include +int convert(long long bin); +int main() { + long long bin; + printf("Enter a binary number: "); + scanf("%lld", &bin); + printf("%lld in binary = %d in octal", bin, convert(bin)); + return 0; +} + +int convert(long long bin) { + int oct = 0, dec = 0, i = 0; + + // converting binary to decimal + while (bin != 0) { + dec += (bin % 10) * pow(2, i); + ++i; + bin /= 10; + } + i = 1; + + // converting to decimal to octal + while (dec != 0) { + oct += (dec % 8) * i; + dec /= 8; + i *= 10; + } + return oct; From 7d69ed68df1c73e868d430339762386b033dde0c Mon Sep 17 00:00:00 2001 From: Kamasani Chaithanya Date: Fri, 16 Oct 2020 14:34:06 +0530 Subject: [PATCH 116/781] Create C program check if an integer is prime or not --- C program check if an integer is prime or not | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 C program check if an integer is prime or not diff --git a/C program check if an integer is prime or not b/C program check if an integer is prime or not new file mode 100644 index 00000000..7a1e602e --- /dev/null +++ b/C program check if an integer is prime or not @@ -0,0 +1,25 @@ +#include + +int main() +{ + int n, c; + + printf("Enter a number\n"); + scanf("%d", &n); + + if (n == 2) + printf("Prime number.\n"); + else + { + for (c = 2; c <= n - 1; c++) + { + if (n % c == 0) + break; + } + if (c != n) + printf("Not prime.\n"); + else + printf("Prime number.\n"); + } + return 0; +} From 4cd57ba0ba4cd19956303bbf3d9b291942575efe Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:34:16 +0530 Subject: [PATCH 117/781] factorial using ternary operator --- Find factorial of a number | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/Find factorial of a number b/Find factorial of a number index 67a7d505..855b2cab 100644 --- a/Find factorial of a number +++ b/Find factorial of a number @@ -1,12 +1,19 @@ -#include -void main(){ - int i,f=1,num; - - printf("Input the number : "); - scanf("%d",&num); - - for(i=1;i<=num;i++) - f=f*i; - - printf("The Factorial of %d is: %d\n",num,f); -} +class Factorial { + + int factorial(int n) + { + + // single line to find factorial + return (n == 1 || n == 0) ? 1 : n * factorial(n - 1); + } + + // Driver Code + public static void main(String args[]) + { + Factorial obj = new Factorial(); + int num = 5; + System.out.println( + "Factorial of " + num + + " is " + obj.factorial(num)); + } +} From c55dd98b4e89cfeafc7128c600427acf1d8e4943 Mon Sep 17 00:00:00 2001 From: Coder-Gautam <72969264+Coder-Gautam@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:34:57 +0530 Subject: [PATCH 118/781] Find Sum Of All Array Elements Find Sum Of All Array Elements Using C Program. --- Find Sum Of All Array Elements | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Find Sum Of All Array Elements diff --git a/Find Sum Of All Array Elements b/Find Sum Of All Array Elements new file mode 100644 index 00000000..60e55679 --- /dev/null +++ b/Find Sum Of All Array Elements @@ -0,0 +1,26 @@ +#include + + +int main() +{ + int a[1000],i,n,sum=0; + + printf("Enter size of the array : "); + scanf("%d",&n); + + printf("Enter elements in array : "); + for(i=0; i Date: Fri, 16 Oct 2020 14:36:36 +0530 Subject: [PATCH 119/781] Create Program to check triangle is equilateral, isosceles or scalene by Encryptor A python program to check if a triangle is equilateral, isosceles or scalene --- ...lateral, isosceles or scalene by Encryptor | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Program to check triangle is equilateral, isosceles or scalene by Encryptor diff --git a/Program to check triangle is equilateral, isosceles or scalene by Encryptor b/Program to check triangle is equilateral, isosceles or scalene by Encryptor new file mode 100644 index 00000000..67c0dcb0 --- /dev/null +++ b/Program to check triangle is equilateral, isosceles or scalene by Encryptor @@ -0,0 +1,28 @@ +# Python3 program for the above approach + +# Function to check if the triangle +# is equilateral or isosceles or scalene +def checkTriangle(x, y, z): + + # _Check for equilateral triangle + if x == y == z: + print("Equilateral Triangle") + + # Check for isoceles triangle + elif x == y or y == z or z == x: + print("Isoceles Triangle") + + # Otherwise scalene triangle + else: + print("Scalene Triangle") + + +# Driver Code + +# Given sides of triangle +x = 8 +y = 7 +z = 9 + +# Function Call +checkTriangle(x, y, z) From 350e6a21873fb6a0d0f2bc6afedb5dfc29e1f974 Mon Sep 17 00:00:00 2001 From: Samyak Jain <39702724+samlpu@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:37:13 +0530 Subject: [PATCH 120/781] Create C Program to multiply 2D or 3D Matrices optimized C Program to multiply 2D or 3D Matrices --- C Program to multiply 2D or 3D Matrices | 69 +++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 C Program to multiply 2D or 3D Matrices diff --git a/C Program to multiply 2D or 3D Matrices b/C Program to multiply 2D or 3D Matrices new file mode 100644 index 00000000..666f21db --- /dev/null +++ b/C Program to multiply 2D or 3D Matrices @@ -0,0 +1,69 @@ +#include +void getMatrixElements(int matrix[][10], int row, int column) { + + printf("\nEnter elements: \n"); + + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("Enter a%d%d: ", i + 1, j + 1); + scanf("%d", &matrix[i][j]); + } + } +} + +void multiplyMatrices(int first[][10], + int second[][10], + int result[][10], + int r1, int c1, int r2, int c2) { + + // Initializing elements of matrix mult to 0. + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + result[i][j] = 0; + } + } + + // Multiplying first and second matrices and storing it in result + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + for (int k = 0; k < c1; ++k) { + result[i][j] += first[i][k] * second[k][j]; + } + } + } +} + +// function to display the matrix +void display(int result[][10], int row, int column) { + + printf("\nOutput Matrix:\n"); + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("%d ", result[i][j]); + if (j == column - 1) + printf("\n"); + } + } +} + +int main() { + int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2; + printf("Enter rows and column for the first matrix: "); + scanf("%d %d", &r1, &c1); + printf("Enter rows and column for the second matrix: "); + scanf("%d %d", &r2, &c2); + while (c1 != r2) { + printf("Error! Enter rows and columns again.\n"); + printf("Enter rows and columns for the first matrix: "); + scanf("%d%d", &r1, &c1); + printf("Enter rows and columns for the second matrix: "); + scanf("%d%d", &r2, &c2); + } + getMatrixElements(first, r1, c1); + getMatrixElements(second, r2, c2); + + multiplyMatrices(first, second, result, r1, c1, r2, c2); + display(result, r1, c2); + + return 0; +} From 2e50e03b2b432af6def0a97c589ded8789c46c0b Mon Sep 17 00:00:00 2001 From: Sandesh2003 <72540199+Sandesh2003@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:38:25 +0530 Subject: [PATCH 121/781] C String Initialization --- C String Initialization | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 C String Initialization diff --git a/C String Initialization b/C String Initialization new file mode 100644 index 00000000..369aa566 --- /dev/null +++ b/C String Initialization @@ -0,0 +1,8 @@ +// Declare C String without Size +char name[] = "Tutorial Gateway"; +// Declare String with Size +char name[50] = "Tutorial Gateway"; +// Declare String of Characters +char name[] = {'T', 'u', 't', 'o', 'r', 'i', 'a', 'l', 'G', 'a', 't', 'e', 'w', 'a', 'y', '\0'}; + +char name[16] = {'T', 'u', 't', 'o', 'r', 'i', 'a', 'l',' G', 'a', 't', 'e', 'w', 'a', 'y', '\0'}; From 4838888598cf92b165a4e09e21b087388685e787 Mon Sep 17 00:00:00 2001 From: Muhammad Arif Ramadhani <63437285+ariframadhan01@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:08:40 +0700 Subject: [PATCH 122/781] Create Program Find Factorial of a given number Program Find Factorial of a given number --- Program Find Factorial of a given number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program Find Factorial of a given number diff --git a/Program Find Factorial of a given number b/Program Find Factorial of a given number new file mode 100644 index 00000000..d18c0983 --- /dev/null +++ b/Program Find Factorial of a given number @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + unsigned int n; + unsigned long long factorial = 1; + + cout << "Enter a positive integer: "; + cin >> n; + + for(int i = 1; i <=n; ++i) + { + factorial *= i; + } + + cout << "Factorial of " << n << " = " << factorial; + return 0; +} From 59ea730e81aa94b7597a17ec04d7bae642ca779f Mon Sep 17 00:00:00 2001 From: Samyak Jain <39702724+samlpu@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:39:07 +0530 Subject: [PATCH 123/781] Create C Program to convert binary to decimal number Optimized C Program to convert binary to decimal number --- C Program to convert binary to decimal number | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 C Program to convert binary to decimal number diff --git a/C Program to convert binary to decimal number b/C Program to convert binary to decimal number new file mode 100644 index 00000000..aa3e14fd --- /dev/null +++ b/C Program to convert binary to decimal number @@ -0,0 +1,20 @@ +#include +int convert(long long n); +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +int convert(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From 743471246c85b96820c1bc96175622bd1d9a6e84 Mon Sep 17 00:00:00 2001 From: Kamasani Chaithanya Date: Fri, 16 Oct 2020 14:39:21 +0530 Subject: [PATCH 124/781] Create c program to print leap year --- c program to print leap year | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 c program to print leap year diff --git a/c program to print leap year b/c program to print leap year new file mode 100644 index 00000000..8e44022c --- /dev/null +++ b/c program to print leap year @@ -0,0 +1,29 @@ +#include +int main() +{ + int startYear, endYear, i; + + //print a string about the program + printf("Print leap years between two given years \n"); + + //get the start year from user + printf("Enter Start year: "); + scanf("%d", &startYear); + + //get the end year from user + printf("Enter End year: "); + scanf("%d", &endYear); + + printf("Leap years:\n"); + + //loop through between the start and end year + for(i=startYear; i <= endYear; i++){ + + //check if the (i) year is a Leap year if yes print + if( (0 == i % 4) && (0 != i % 100) || (0 == i % 400) ){ + printf("%d\n", i); + } + } + + return 0; +} From 016bc1b072334e8e474b26c4e57b7e1c41f43af1 Mon Sep 17 00:00:00 2001 From: Coder-Gautam <72969264+Coder-Gautam@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:39:27 +0530 Subject: [PATCH 125/781] Perform all arithmetic operations C program to perform all arithmetic operations. --- perform all arithmetic operations | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 perform all arithmetic operations diff --git a/perform all arithmetic operations b/perform all arithmetic operations new file mode 100644 index 00000000..ea23e48f --- /dev/null +++ b/perform all arithmetic operations @@ -0,0 +1,39 @@ + +/** + * C program to perform all arithmetic operations + */ + +#include + +int main() +{ + int num1, num2; + int sum, sub, mult, mod; + float div; + + /* + * Input two numbers from user + */ + printf("Enter any two numbers: "); + scanf("%d%d", &num1, &num2); + + /* + * Perform all arithmetic operations + */ + sum = num1 + num2; + sub = num1 - num2; + mult = num1 * num2; + div = (float)num1 / num2; + mod = num1 % num2; + + /* + * Print result of all arithmetic operations + */ + printf("SUM = %d\n", sum); + printf("DIFFERENCE = %d\n", sub); + printf("PRODUCT = %d\n", mult); + printf("QUOTIENT = %f\n", div); + printf("MODULUS = %d", mod); + + return 0; +} From 49697fb7cd5b11f36d2a8b452e37fe473dbd579a Mon Sep 17 00:00:00 2001 From: Sandesh2003 <72540199+Sandesh2003@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:41:38 +0530 Subject: [PATCH 126/781] Factor Number C Program to Find Factors of a Number Using For Loop --- Factor Number | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Factor Number diff --git a/Factor Number b/Factor Number new file mode 100644 index 00000000..97a59149 --- /dev/null +++ b/Factor Number @@ -0,0 +1,22 @@ +/* C Program to Find factors of a number */ + +#include + +int main() +{ + int i, Number; + + printf("\n Please Enter any number to Find Factors \n"); + scanf("%d", &Number); + + printf("\n Factors of the Given Number are:\n"); + for (i = 1; i <= Number; i++) + { + if(Number%i == 0) + { + printf(" %d ", i); + } + } + + return 0; +} From e5379c4bdec7a6e28a2f6b89806e986624d03291 Mon Sep 17 00:00:00 2001 From: Muhammad Arif Ramadhani <63437285+ariframadhan01@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:11:44 +0700 Subject: [PATCH 127/781] Create Program Calculate Length of String without Using strlen() Function Program Calculate Length of String without Using strlen() Function --- ...te Length of String without Using strlen() Function | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program Calculate Length of String without Using strlen() Function diff --git a/Program Calculate Length of String without Using strlen() Function b/Program Calculate Length of String without Using strlen() Function new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/Program Calculate Length of String without Using strlen() Function @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 051c481b3a8040830a4013483378c80ee5fea740 Mon Sep 17 00:00:00 2001 From: Muhammad Arif Ramadhani <63437285+ariframadhan01@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:13:45 +0700 Subject: [PATCH 128/781] Create Program Program to convert decimal to binary Program Program to convert decimal to binary --- Program Program to convert decimal to binary | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Program Program to convert decimal to binary diff --git a/Program Program to convert decimal to binary b/Program Program to convert decimal to binary new file mode 100644 index 00000000..0a7895f1 --- /dev/null +++ b/Program Program to convert decimal to binary @@ -0,0 +1,23 @@ +#include +#include +long long convert(int n); +int main() { + int n; + printf("Enter a decimal number: "); + scanf("%d", &n); + printf("%d in decimal = %lld in binary", n, convert(n)); + return 0; +} + +long long convert(int n) { + long long bin = 0; + int rem, i = 1, step = 1; + while (n != 0) { + rem = n % 2; + printf("Step %d: %d/2, Remainder = %d, Quotient = %d\n", step++, n, rem, n / 2); + n /= 2; + bin += rem * i; + i *= 10; + } + return bin; +} From f641425b8a7ec37ceaef9ca245b311a636c2463c Mon Sep 17 00:00:00 2001 From: subahan8055 <65856195+subahan8055@users.noreply.github.com> Date: Fri, 16 Oct 2020 02:14:42 -0700 Subject: [PATCH 129/781] Create program to find length of a given string optimized code to find length of a given string --- program to find length of a given string | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 program to find length of a given string diff --git a/program to find length of a given string b/program to find length of a given string new file mode 100644 index 00000000..f2edae7d --- /dev/null +++ b/program to find length of a given string @@ -0,0 +1,3 @@ +# testing len() +str1 = "Welcome to python" +print("The length of the string is :", len(str1)) From c37254145d81dd49ed39432ada72c05d5bd4e0fd Mon Sep 17 00:00:00 2001 From: Girish04-R <72377382+Girish04-R@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:45:55 +0530 Subject: [PATCH 130/781] Create Create Repeating Numbers Optimized code for Repeating Numbers in java --- Create Repeating Numbers | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Create Repeating Numbers diff --git a/Create Repeating Numbers b/Create Repeating Numbers new file mode 100644 index 00000000..b3d0fd94 --- /dev/null +++ b/Create Repeating Numbers @@ -0,0 +1,18 @@ +public class RepeatingNumbers { + + public static void print(int n) { + //Write your code here + int val=1; + for(int i=1;i<=n;i++){ + for(int j=1;j<=Math.pow(2,i-1);j++){ + System.out.print(val++); + if(val==10){ + val=1; + } + } + System.out.println(); + } + + } + +} From 5590ce21a35e7750a1492145baba1bbc41de946f Mon Sep 17 00:00:00 2001 From: subahan8055 <65856195+subahan8055@users.noreply.github.com> Date: Fri, 16 Oct 2020 02:18:25 -0700 Subject: [PATCH 131/781] Create Python Program to count sum of all numbers in array optimized program to count sum of all numbers in array --- Python Program to count sum of all numbers in array | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Python Program to count sum of all numbers in array diff --git a/Python Program to count sum of all numbers in array b/Python Program to count sum of all numbers in array new file mode 100644 index 00000000..3dc66ab2 --- /dev/null +++ b/Python Program to count sum of all numbers in array @@ -0,0 +1,7 @@ +#Initialize array. +arr = [1, 2, 3, 4, 5]; +sum = 0; +#Loop through the array to calculate sum of elements. +for i in range(0, len(arr)): +sum = sum + arr[i]; +print("Sum of all the elements of an array: " + str(sum)); From 548bd7b8b06536fdc0b3357117fef79794c10290 Mon Sep 17 00:00:00 2001 From: Shubham Sharma <62887866+HeisenBug-07@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:49:40 +0530 Subject: [PATCH 132/781] fibonacci series using recursion --- fibonacci_recursion.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 fibonacci_recursion.cpp diff --git a/fibonacci_recursion.cpp b/fibonacci_recursion.cpp new file mode 100644 index 00000000..1c3c686d --- /dev/null +++ b/fibonacci_recursion.cpp @@ -0,0 +1,22 @@ +// This program will help you to find fibonacci serise using recursion. + +#include +using namespace std; +int fib(int x) { + if((x==1)||(x==0)) { + return(x); + }else { + return(fib(x-1)+fib(x-2)); + } +} +int main() { + int x , i=0; + cout << "Enter the number of terms of series : "; + cin >> x; + cout << "\nFibonnaci Series : "; + while(i < x) { + cout << " " << fib(i); + i++; + } + return 0; +} From b308430562f05b92f35526b37f2e72968a7bd601 Mon Sep 17 00:00:00 2001 From: subahan8055 <65856195+subahan8055@users.noreply.github.com> Date: Fri, 16 Oct 2020 02:21:14 -0700 Subject: [PATCH 133/781] Create Python Program to find smallest element in array Optimized Python Program to find the smallest element in array --- Python Program to find smallest element in array | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Python Program to find smallest element in array diff --git a/Python Program to find smallest element in array b/Python Program to find smallest element in array new file mode 100644 index 00000000..df9050e8 --- /dev/null +++ b/Python Program to find smallest element in array @@ -0,0 +1,11 @@ +# Python program to find smallest +# number in a list + +# list of numbers +list1 = [10, 20, 4, 45, 99] + +# sorting the list +list1.sort() + +# printing the first element +print("Smallest element is:", *list1[:1]) From e3c58d3750240841edcf4e3af8dc18cd04e0259e Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:53:11 +0530 Subject: [PATCH 134/781] updated addition of matrices --- Addition of two matrix | 71 +++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/Addition of two matrix b/Addition of two matrix index 0986763b..89a2fc40 100644 --- a/Addition of two matrix +++ b/Addition of two matrix @@ -1,32 +1,39 @@ -#include - -int main() -{ - int m, n, c, d, first[10][10], second[10][10], sum[10][10]; - - printf("Enter the number of rows and columns of matrix\n"); - scanf("%d%d", &m, &n); - printf("Enter the elements of first matrix\n"); - - for (c = 0; c < m; c++) - for (d = 0; d < n; d++) - scanf("%d", &first[c][d]); - - printf("Enter the elements of second matrix\n"); - - for (c = 0; c < m; c++) - for (d = 0 ; d < n; d++) - scanf("%d", &second[c][d]); - - printf("Sum of entered matrices:-\n"); - - for (c = 0; c < m; c++) { - for (d = 0 ; d < n; d++) { - sum[c][d] = first[c][d] + second[c][d]; - printf("%d\t", sum[c][d]); - } - printf("\n"); - } - - return 0; -} +#include +#define N 4 + +// This function adds A[][] and B[][], and stores +// the result in C[][] +void add(int A[][N], int B[][N], int C[][N]) +{ + int i, j; + for (i = 0; i < N; i++) + for (j = 0; j < N; j++) + C[i][j] = A[i][j] + B[i][j]; +} + +int main() +{ + int A[N][N] = { {1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4}}; + + int B[N][N] = { {1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4}}; + + int C[N][N]; // To store result + int i, j; + add(A, B, C); + + printf("Result matrix is \n"); + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + printf("%d ", C[i][j]); + printf("\n"); + } + + return 0; +} From c93ca9cc46e75da734edb4c1e3c28723771aec02 Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:54:25 +0530 Subject: [PATCH 135/781] Update Addition of two matrix --- Addition of two matrix | 1 + 1 file changed, 1 insertion(+) diff --git a/Addition of two matrix b/Addition of two matrix index 0986763b..68f68063 100644 --- a/Addition of two matrix +++ b/Addition of two matrix @@ -29,4 +29,5 @@ int main() } return 0; + } From ad002c73cdbc8591a1d62a63d84f7cd08fd98685 Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:54:50 +0530 Subject: [PATCH 136/781] Update Addition of two matrix --- Addition of two matrix | 72 +++++++++++++++++++++++------------------- 1 file changed, 39 insertions(+), 33 deletions(-) diff --git a/Addition of two matrix b/Addition of two matrix index 68f68063..89a2fc40 100644 --- a/Addition of two matrix +++ b/Addition of two matrix @@ -1,33 +1,39 @@ -#include - -int main() -{ - int m, n, c, d, first[10][10], second[10][10], sum[10][10]; - - printf("Enter the number of rows and columns of matrix\n"); - scanf("%d%d", &m, &n); - printf("Enter the elements of first matrix\n"); - - for (c = 0; c < m; c++) - for (d = 0; d < n; d++) - scanf("%d", &first[c][d]); - - printf("Enter the elements of second matrix\n"); - - for (c = 0; c < m; c++) - for (d = 0 ; d < n; d++) - scanf("%d", &second[c][d]); - - printf("Sum of entered matrices:-\n"); - - for (c = 0; c < m; c++) { - for (d = 0 ; d < n; d++) { - sum[c][d] = first[c][d] + second[c][d]; - printf("%d\t", sum[c][d]); - } - printf("\n"); - } - - return 0; - -} +#include +#define N 4 + +// This function adds A[][] and B[][], and stores +// the result in C[][] +void add(int A[][N], int B[][N], int C[][N]) +{ + int i, j; + for (i = 0; i < N; i++) + for (j = 0; j < N; j++) + C[i][j] = A[i][j] + B[i][j]; +} + +int main() +{ + int A[N][N] = { {1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4}}; + + int B[N][N] = { {1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4}}; + + int C[N][N]; // To store result + int i, j; + add(A, B, C); + + printf("Result matrix is \n"); + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + printf("%d ", C[i][j]); + printf("\n"); + } + + return 0; +} From a272fd76407fe9d4e6f7162d896a9db2a8989166 Mon Sep 17 00:00:00 2001 From: Rajan Gautam <71542496+rgautam320@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:57:52 +0530 Subject: [PATCH 137/781] Multiplication of 2-D Array Multiplication of 2-D Array using C Programming --- Multiplication of 2-D Array | 88 +++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Multiplication of 2-D Array diff --git a/Multiplication of 2-D Array b/Multiplication of 2-D Array new file mode 100644 index 00000000..85832866 --- /dev/null +++ b/Multiplication of 2-D Array @@ -0,0 +1,88 @@ +/*Multiplication of 2-D Array using C Programming*/ +/*Author :- Rajan Gautam*/ + +#include +#include + +void multiplication(void); + +int A[30][30], B[30][30], C[30][30]; + +int i, j, k, m, n, sum = 0; +//Inside the main function +int main() +{ + //We are defining the size of arrays here + printf("Enter Number of Rows : "); + scanf("%d", &m); + printf("Enter Number of Columns : "); + scanf("%d", &n); + printf("Enter Array Element for First Matrix : \n"); + for(i = 0; i Date: Fri, 16 Oct 2020 14:58:36 +0530 Subject: [PATCH 138/781] Create tic tac toe game.py --- tic tac toe game.py | 112 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 tic tac toe game.py diff --git a/tic tac toe game.py b/tic tac toe game.py new file mode 100644 index 00000000..531c64b8 --- /dev/null +++ b/tic tac toe game.py @@ -0,0 +1,112 @@ +import numpy as np +import random +from time import sleep + +# Creates an empty board +def create_board(): + return(np.array([[0, 0, 0], + [0, 0, 0], + [0, 0, 0]])) + +# Check for empty places on board +def possibilities(board): + l = [] + + for i in range(len(board)): + for j in range(len(board)): + + if board[i][j] == 0: + l.append((i, j)) + return(l) + +# Select a random place for the player +def random_place(board, player): + selection = possibilities(board) + current_loc = random.choice(selection) + board[current_loc] = player + return(board) + +# Checks whether the player has three +# of their marks in a horizontal row +def row_win(board, player): + for x in range(len(board)): + win = True + + for y in range(len(board)): + if board[x, y] != player: + win = False + continue + + if win == True: + return(win) + return(win) + +# Checks whether the player has three +# of their marks in a vertical row +def col_win(board, player): + for x in range(len(board)): + win = True + + for y in range(len(board)): + if board[y][x] != player: + win = False + continue + + if win == True: + return(win) + return(win) + +# Checks whether the player has three +# of their marks in a diagonal row +def diag_win(board, player): + win = True + y = 0 + for x in range(len(board)): + if board[x, x] != player: + win = False + if win: + return win + win = True + if win: + for x in range(len(board)): + y = len(board) - 1 - x + if board[x, y] != player: + win = False + return win + +# Evaluates whether there is +# a winner or a tie +def evaluate(board): + winner = 0 + + for player in [1, 2]: + if (row_win(board, player) or + col_win(board,player) or + diag_win(board,player)): + + winner = player + + if np.all(board != 0) and winner == 0: + winner = -1 + return winner + +# Main function to start the game +def play_game(): + board, winner, counter = create_board(), 0, 1 + print(board) + sleep(2) + + while winner == 0: + for player in [1, 2]: + board = random_place(board, player) + print("Board after " + str(counter) + " move") + print(board) + sleep(2) + counter += 1 + winner = evaluate(board) + if winner != 0: + break + return(winner) + +# Driver Code +print("Winner is: " + str(play_game())) From 6c7f9d3ebb25a55faeb776043285c23eafa7cf85 Mon Sep 17 00:00:00 2001 From: pikaachu09 <72344695+pikaachu09@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:09:52 +0530 Subject: [PATCH 139/781] smallest element in the array --- smallest element in the array.c | 26 ++++++++++++++++++++++++ to get the smallest element in the array | 14 ------------- 2 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 smallest element in the array.c delete mode 100644 to get the smallest element in the array diff --git a/smallest element in the array.c b/smallest element in the array.c new file mode 100644 index 00000000..441e2ce4 --- /dev/null +++ b/smallest element in the array.c @@ -0,0 +1,26 @@ +#include + +int main() { + int a[30], i, num, smallest; + + printf("\nEnter no of elements :"); + scanf("%d", &num); + + //Read n elements in an array + for (i = 0; i < num; i++) + scanf("%d", &a[i]); + + //Consider first element as smallest + smallest = a[0]; + + for (i = 0; i < num; i++) { + if (a[i] < smallest) { + smallest = a[i]; + } + } + + // Print out the Result + printf("\nSmallest Element : %d", smallest); + + return (0); +} diff --git a/to get the smallest element in the array b/to get the smallest element in the array deleted file mode 100644 index de939d35..00000000 --- a/to get the smallest element in the array +++ /dev/null @@ -1,14 +0,0 @@ -#Initialize array -arr = [25, 11, 7, 75, 56]; - -#Initialize min with the first element of the array. - -min = arr[0]; - -#Loop through the array -for i in range(0, len(arr)): - #Compare elements of array with min - if(arr[i] < min): - min = arr[i]; - -print("Smallest element present in given array: " + str(min)); From 4f9c848e9c16e9def17bbc8152f5cc4b05b83248 Mon Sep 17 00:00:00 2001 From: varunjain4700 <54185285+varunjain4700@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:16:17 +0530 Subject: [PATCH 140/781] Create Program To Find power of any number Code to find power of a number --- Program To Find power of any number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Program To Find power of any number diff --git a/Program To Find power of any number b/Program To Find power of any number new file mode 100644 index 00000000..83383e3a --- /dev/null +++ b/Program To Find power of any number @@ -0,0 +1,14 @@ +#include +using namespace std; +long long int powerr(long long int x,long long int y){ + if(y==0) + return 1; + else + return x*powerr(x,y-1); +} +int main(){ + long long int base,power; + cin>>base; + cin>>power; + cout< Date: Fri, 16 Oct 2020 15:17:30 +0530 Subject: [PATCH 141/781] Create linkedlist.cpp --- linkedlist.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 linkedlist.cpp diff --git a/linkedlist.cpp b/linkedlist.cpp new file mode 100644 index 00000000..20abeed9 --- /dev/null +++ b/linkedlist.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +class Node { +public: + int data; + Node* next; +}; + +// This function prints contents of linked list +// starting from the given node +void printList(Node* n) +{ + while (n != NULL) { + cout << n->data << " "; + n = n->next; + } +} + +// Driver code +int main() +{ + Node* head = NULL; + Node* second = NULL; + Node* third = NULL; + + // allocate 3 nodes in the heap + head = new Node(); + second = new Node(); + third = new Node(); + + head->data = 1; // assign data in first node + head->next = second; // Link first node with second + + second->data = 2; // assign data to second node + second->next = third; + + third->data = 3; // assign data to third node + third->next = NULL; + + printList(head); + + return 0; +} + From 79d297f1d1255ffb1c9f243ef7b977316910186f Mon Sep 17 00:00:00 2001 From: Encryptor <62632966+Encryptor-Sec@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:27:14 +0530 Subject: [PATCH 142/781] Create Program to Find ASCII Value of a Character by Encryptor-Sec C program to print ASCII value of a character --- ... Find ASCII Value of a Character by Encryptor-Sec | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Program to Find ASCII Value of a Character by Encryptor-Sec diff --git a/Program to Find ASCII Value of a Character by Encryptor-Sec b/Program to Find ASCII Value of a Character by Encryptor-Sec new file mode 100644 index 00000000..a73b9c24 --- /dev/null +++ b/Program to Find ASCII Value of a Character by Encryptor-Sec @@ -0,0 +1,12 @@ +#include +int main() { + char c; + printf("Enter a character: "); + scanf("%c", &c); + + // %d displays the integer value of a character + // %c displays the actual character + printf("ASCII value of %c = %d", c, c); + + return 0; +} From b8dd81a1ada1a0ad35d388cd34fb33cde1fc8b61 Mon Sep 17 00:00:00 2001 From: Girish04-R <72377382+Girish04-R@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:29:33 +0530 Subject: [PATCH 143/781] Create Triangular Number pattern Optimized code for Triangular Number Pattern --- Triangular Number pattern | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Triangular Number pattern diff --git a/Triangular Number pattern b/Triangular Number pattern new file mode 100644 index 00000000..dbb2ce6d --- /dev/null +++ b/Triangular Number pattern @@ -0,0 +1,18 @@ +import java.util.Scanner; + +public class TraingularNumberPattern { + public static void main(String[] args) { + + + Scanner scan=new Scanner(System.in); + int n=scan.nextInt(); + for(int i=1;i<=n;i++) { + for(int j=1;j<=i;j++) { + System.out.print(i); + } + System.out.println(); + } + + + } +} From 25d70afbe8800da87d56f16166cf4806a6b2f57e Mon Sep 17 00:00:00 2001 From: Encryptor <62632966+Encryptor-Sec@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:30:04 +0530 Subject: [PATCH 144/781] Create Program to print Fibonnaci Series by Encryptor-Sec --- ...am to print Fibonnaci Series by Encryptor-Sec | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program to print Fibonnaci Series by Encryptor-Sec diff --git a/Program to print Fibonnaci Series by Encryptor-Sec b/Program to print Fibonnaci Series by Encryptor-Sec new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/Program to print Fibonnaci Series by Encryptor-Sec @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From e34ea0f1a7138cd66882023d329204b99f546a6f Mon Sep 17 00:00:00 2001 From: Encryptor <62632966+Encryptor-Sec@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:31:14 +0530 Subject: [PATCH 145/781] Create Program to Display Fibonacci Sequence by Encryptor-Sec --- ...o Display Fibonacci Sequence by Encryptor-Sec | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program to Display Fibonacci Sequence by Encryptor-Sec diff --git a/Program to Display Fibonacci Sequence by Encryptor-Sec b/Program to Display Fibonacci Sequence by Encryptor-Sec new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/Program to Display Fibonacci Sequence by Encryptor-Sec @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 239a54743888ea36f03cc655da7a3d418fc74b48 Mon Sep 17 00:00:00 2001 From: Sani-Pal <72972942+Sani-Pal@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:34:58 +0530 Subject: [PATCH 146/781] Create Calculating the power of a number in python --- Calculating the power of a number in python | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Calculating the power of a number in python diff --git a/Calculating the power of a number in python b/Calculating the power of a number in python new file mode 100644 index 00000000..8f3d3344 --- /dev/null +++ b/Calculating the power of a number in python @@ -0,0 +1,3 @@ +number = int(input("enter your nuumber: ")) +power=int(input("Enter the power: ")) +print(number**power) From aa1e940a798262bbd7052d1cebe4fa421e38cf8b Mon Sep 17 00:00:00 2001 From: Sani-Pal <72972942+Sani-Pal@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:35:52 +0530 Subject: [PATCH 147/781] Create Factorial of a number via python --- Factorial of a number via python | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Factorial of a number via python diff --git a/Factorial of a number via python b/Factorial of a number via python new file mode 100644 index 00000000..7708570c --- /dev/null +++ b/Factorial of a number via python @@ -0,0 +1,6 @@ +num1=int(input("Enter the number : ")) +fact=1; +for i in range(num1,0,-1): + fact=fact*num1 + num1-=1 +print("The factorial of the number is",fact) From 10a6494e818f9a7cd150b3cee8bf8523dd5c1474 Mon Sep 17 00:00:00 2001 From: Urmila Choudhary <72972873+Urmila-Coder@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:36:00 +0530 Subject: [PATCH 148/781] Total number of vowels & consonants in string Program to count the total number of vowels and consonants in a string using JavaScript --- Count of vowels & consonants in string | 28 ++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Count of vowels & consonants in string diff --git a/Count of vowels & consonants in string b/Count of vowels & consonants in string new file mode 100644 index 00000000..4f6588e3 --- /dev/null +++ b/Count of vowels & consonants in string @@ -0,0 +1,28 @@ +public class CountVowelConsonant { + public static void main(String[] args) { + + //Counter variable to store the count of vowels and consonant + int vCount = 0, cCount = 0; + + //Declare a string + String str = "This is a really simple sentence"; + + //Converting entire string to lower case to reduce the comparisons + str = str.toLowerCase(); + + for(int i = 0; i < str.length(); i++) { + //Checks whether a character is a vowel + if(str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u') { + //Increments the vowel counter + vCount++; + } + //Checks whether a character is a consonant + else if(str.charAt(i) >= 'a' && str.charAt(i)<='z') { + //Increments the consonant counter + cCount++; + } + } + System.out.println("Number of vowels: " + vCount); + System.out.println("Number of consonants: " + cCount); + } +} From cdf8a0019026d5aee6d69b8aa05b2f610843989a Mon Sep 17 00:00:00 2001 From: polisitni1 <64201881+polisitni1@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:06:11 +0700 Subject: [PATCH 149/781] Create Bit Fields in C --- Bit Fields in C | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Bit Fields in C diff --git a/Bit Fields in C b/Bit Fields in C new file mode 100644 index 00000000..23dd0a4b --- /dev/null +++ b/Bit Fields in C @@ -0,0 +1,21 @@ +#include +#include + +struct { + unsigned int age : 3; +} Age; + +int main( ) { + + Age.age = 4; + printf( "Sizeof( Age ) : %d\n", sizeof(Age) ); + printf( "Age.age : %d\n", Age.age ); + + Age.age = 7; + printf( "Age.age : %d\n", Age.age ); + + Age.age = 8; + printf( "Age.age : %d\n", Age.age ); + + return 0; +} From 4bb7bf767628849b46b7526efb6ca3f92c39b72a Mon Sep 17 00:00:00 2001 From: Sani-Pal <72972942+Sani-Pal@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:37:01 +0530 Subject: [PATCH 150/781] Create Checking whether given year is leap or not via python --- ...king whether given year is leap or not via python | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Checking whether given year is leap or not via python diff --git a/Checking whether given year is leap or not via python b/Checking whether given year is leap or not via python new file mode 100644 index 00000000..5e521a53 --- /dev/null +++ b/Checking whether given year is leap or not via python @@ -0,0 +1,12 @@ +def is_leap(year): + leap=False + if (year%400==0): + leap= False + elif(year%100==0): + leap= False + elif(year%4==0): + leap=True + return leap + +year = int(input()) +print(is_leap(year)) From 855d261e13afaa0f475444800033b0c2ed63f944 Mon Sep 17 00:00:00 2001 From: Girish04-R <72377382+Girish04-R@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:37:58 +0530 Subject: [PATCH 151/781] Create Triangular Star Pattern Optimized Code For Triangular Star Pattern In Java --- Triangular Star Pattern | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Triangular Star Pattern diff --git a/Triangular Star Pattern b/Triangular Star Pattern new file mode 100644 index 00000000..0061d988 --- /dev/null +++ b/Triangular Star Pattern @@ -0,0 +1,18 @@ +import java.util.Scanner; + +public class TraingularStarPattern { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner scan=new Scanner(System.in); + int n=scan.nextInt(); + for(int i=1;i<=n;i++) { + for(int j=1;j<=i;j++) { + System.out.print("*"); + } + System.out.println(); + } + + } + +} From 2b4f71a20f904f18797758b077850bfb2ea6ff72 Mon Sep 17 00:00:00 2001 From: Sani-Pal <72972942+Sani-Pal@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:38:46 +0530 Subject: [PATCH 152/781] Create Finding Length of the string via python --- Finding Length of the string via python | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Finding Length of the string via python diff --git a/Finding Length of the string via python b/Finding Length of the string via python new file mode 100644 index 00000000..626dc07e --- /dev/null +++ b/Finding Length of the string via python @@ -0,0 +1,2 @@ +string=input("Enter the string") +print(len(string)) From 295721769f4b388e3f18c28f9135a3a73da8af0b Mon Sep 17 00:00:00 2001 From: Urmila Choudhary <72972873+Urmila-Coder@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:39:03 +0530 Subject: [PATCH 153/781] Multi-dimensional Array in C Multi-dimensional Array in C Using C Language --- Multi-dimensional Array in C | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Multi-dimensional Array in C diff --git a/Multi-dimensional Array in C b/Multi-dimensional Array in C new file mode 100644 index 00000000..e0649bf2 --- /dev/null +++ b/Multi-dimensional Array in C @@ -0,0 +1,29 @@ +#include +void main() +{ +printf("Welcome to DataFlair tutorials!\n\n"); +int matrix[10][10]; +int no_of_rows, no_of_columns; +int iteration1, iteration2; +printf("Enter the number of rows of the matrix: "); +scanf("%d",&no_of_rows); +printf("Enter the number of columns of the matrix: "); +scanf("%d",&no_of_columns); +printf("Enter the elements of the matrix:\n"); +for(iteration1 = 0; iteration1 < no_of_rows; iteration1++ ) +{ +for(iteration2 = 0; iteration2 < no_of_columns; iteration2++) +{ +scanf("%d", &matrix[iteration1][iteration2]); +} +} +printf("The matrix is:\n"); +for(iteration1 = 0; iteration1 < no_of_rows; iteration1++ ) +{ +for(iteration2 = 0; iteration2 < no_of_columns; iteration2++) +{ +printf("%d\t",matrix[iteration1][iteration2]); +} +printf("\n"); +} +} From 04e7085f463b529efab87d28d3684fd4f6dcbf40 Mon Sep 17 00:00:00 2001 From: Urmila Choudhary <72972873+Urmila-Coder@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:43:07 +0530 Subject: [PATCH 154/781] Perform addition and subtraction of Matrices Perform addition and subtraction of Matrices using C Language --- Perform addition and subtraction of Matrices | 87 ++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Perform addition and subtraction of Matrices diff --git a/Perform addition and subtraction of Matrices b/Perform addition and subtraction of Matrices new file mode 100644 index 00000000..13a7d091 --- /dev/null +++ b/Perform addition and subtraction of Matrices @@ -0,0 +1,87 @@ +#include + +int main() +{ + printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); + + int n, m, c, d, first[10][10], second[10][10], sum[10][10], diff[10][10]; + printf("\nEnter the number of rows and columns of the first matrix \n\n"); + scanf("%d%d", &m, &n); + + printf("\nEnter the %d elements of the first matrix \n\n", m*n); + for(c = 0; c < m; c++) // to iterate the rows + for(d = 0; d < n; d++) // to iterate the columns + scanf("%d", &first[c][d]); + + printf("\nEnter the %d elements of the second matrix \n\n", m*n); + for(c = 0; c < m; c++) // to iterate the rows + for(d = 0; d < n; d++) // to iterate the columns + scanf("%d", &second[c][d]); + + /* + printing the first matrix + */ + printf("\n\nThe first matrix is: \n\n"); + for(c = 0; c < m; c++) // to iterate the rows + { + for(d = 0; d < n; d++) // to iterate the columns + { + printf("%d\t", first[c][d]); + } + printf("\n"); + } + + /* + printing the second matrix + */ + printf("\n\nThe second matrix is: \n\n"); + for(c = 0; c < m; c++) // to iterate the rows + { + for(d = 0; d < n; d++) // to iterate the columns + { + printf("%d\t", second[c][d]); + } + printf("\n"); + } + + /* + finding the SUM of the two matrices + and storing in another matrix sum of the same size + */ + for(c = 0; c < m; c++) + for(d = 0; d < n; d++) + sum[c][d] = first[c][d] + second[c][d]; + + // printing the elements of the sum matrix + printf("\n\nThe sum of the two entered matrices is: \n\n"); + for(c = 0; c < m; c++) + { + for(d = 0; d < n; d++) + { + printf("%d\t", sum[c][d]); + } + printf("\n"); + } + + /* + finding the DIFFERENCE of the two matrices + and storing in another matrix difference of the same size + */ + for(c = 0; c < m; c++) + for(d = 0; d < n; d++) + diff[c][d] = first[c][d] - second[c][d]; + + // printing the elements of the diff matrix + printf("\n\nThe difference(subtraction) of the two entered matrices is: \n\n"); + for(c = 0; c < m; c++) + { + for(d = 0; d < n; d++) + { + printf("%d\t", diff[c][d]); + } + printf("\n"); + } + + printf("\n\n\t\t\tCoding is Fun !\n\n\n"); + return 0; +} From 069757504d2415dbc2c4b26f26bb05d7d24563f2 Mon Sep 17 00:00:00 2001 From: Urmila Choudhary <72972873+Urmila-Coder@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:47:37 +0530 Subject: [PATCH 155/781] Calculate the Power of a Number Calculate the Power of a Number Using C Language. --- Calculate the Power of a Number | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Calculate the Power of a Number diff --git a/Calculate the Power of a Number b/Calculate the Power of a Number new file mode 100644 index 00000000..e7d59525 --- /dev/null +++ b/Calculate the Power of a Number @@ -0,0 +1,16 @@ +#include +int main() { + int base, exp; + long long result = 1; + printf("Enter a base number: "); + scanf("%d", &base); + printf("Enter an exponent: "); + scanf("%d", &exp); + + while (exp != 0) { + result *= base; + --exp; + } + printf("Answer = %lld", result); + return 0; +} From ff27e5512febfb3528d9b84211407158f690e923 Mon Sep 17 00:00:00 2001 From: benwatson23 <72973514+benwatson23@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:47:41 +0530 Subject: [PATCH 156/781] Create finding power of a number in python --- finding power of a number in python | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 finding power of a number in python diff --git a/finding power of a number in python b/finding power of a number in python new file mode 100644 index 00000000..4aab9348 --- /dev/null +++ b/finding power of a number in python @@ -0,0 +1,3 @@ +number = int(input("Enter your number: ")) +power=int(input("Enter the power: ")) +print(f"{number} raised to the power {power} is {number**power}") From 30f83746dfa999f269e210ce36e8530e6183f8c6 Mon Sep 17 00:00:00 2001 From: benwatson23 <72973514+benwatson23@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:48:33 +0530 Subject: [PATCH 157/781] Create Checking whether a year is leap in python --- Checking whether a year is leap in python | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Checking whether a year is leap in python diff --git a/Checking whether a year is leap in python b/Checking whether a year is leap in python new file mode 100644 index 00000000..5e521a53 --- /dev/null +++ b/Checking whether a year is leap in python @@ -0,0 +1,12 @@ +def is_leap(year): + leap=False + if (year%400==0): + leap= False + elif(year%100==0): + leap= False + elif(year%4==0): + leap=True + return leap + +year = int(input()) +print(is_leap(year)) From f9f549d7ece4bb27a859f4598f1068f752cef28b Mon Sep 17 00:00:00 2001 From: benwatson23 <72973514+benwatson23@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:49:17 +0530 Subject: [PATCH 158/781] Create Factorial in python --- Factorial in python | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Factorial in python diff --git a/Factorial in python b/Factorial in python new file mode 100644 index 00000000..7708570c --- /dev/null +++ b/Factorial in python @@ -0,0 +1,6 @@ +num1=int(input("Enter the number : ")) +fact=1; +for i in range(num1,0,-1): + fact=fact*num1 + num1-=1 +print("The factorial of the number is",fact) From 753723f452bad206cfc888beb3eb235374eccc8e Mon Sep 17 00:00:00 2001 From: benwatson23 <72973514+benwatson23@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:50:49 +0530 Subject: [PATCH 159/781] Create Fibonacci series in python --- Fibonacci series in python | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Fibonacci series in python diff --git a/Fibonacci series in python b/Fibonacci series in python new file mode 100644 index 00000000..4b3f6239 --- /dev/null +++ b/Fibonacci series in python @@ -0,0 +1,9 @@ +def fibonacci_series(n): + if(n==0): + return 0 + elif(n==1): + return 1 + else: + return fibonacci_series(n-1)+fibonacci_series(n-2) +num=int(input("Enter the Number: ")) +print(fibonacci_series(num)) From 4137cd7c0266cb8d8e9daf92fe253f9a83ea0f20 Mon Sep 17 00:00:00 2001 From: Ben-Watson23 <72974028+Ben-Watson23@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:55:30 +0530 Subject: [PATCH 160/781] Create Fibonacci Series via python --- Fibonacci Series via python | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Fibonacci Series via python diff --git a/Fibonacci Series via python b/Fibonacci Series via python new file mode 100644 index 00000000..4b3f6239 --- /dev/null +++ b/Fibonacci Series via python @@ -0,0 +1,9 @@ +def fibonacci_series(n): + if(n==0): + return 0 + elif(n==1): + return 1 + else: + return fibonacci_series(n-1)+fibonacci_series(n-2) +num=int(input("Enter the Number: ")) +print(fibonacci_series(num)) From bf3c4da5f9cae91db223e7b442342bfe098c6d56 Mon Sep 17 00:00:00 2001 From: Encryptor <62632966+Encryptor-Sec@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:56:31 +0530 Subject: [PATCH 161/781] Create Program to find sum of elements in a given array by Encryptor=Sec --- ...elements in a given array by Encryptor=Sec | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Program to find sum of elements in a given array by Encryptor=Sec diff --git a/Program to find sum of elements in a given array by Encryptor=Sec b/Program to find sum of elements in a given array by Encryptor=Sec new file mode 100644 index 00000000..9676b1ae --- /dev/null +++ b/Program to find sum of elements in a given array by Encryptor=Sec @@ -0,0 +1,21 @@ +# Python 3 code to find sum +# of elements in given array +def _sum(arr,n): + + # return sum using sum + # inbuilt sum() function + return(sum(arr)) + +# driver function +arr=[] +# input values to list +arr = [12, 3, 4, 15] + +# calculating length of array +n = len(arr) + +ans = _sum(arr,n) + +# display sum +print ('Sum of the array is ',ans) + From 45e8a13ed9e7e4c16c05eb3d3253756598cba214 Mon Sep 17 00:00:00 2001 From: KrenilBhikadiya <72907830+KrenilBhikadiya@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:57:00 +0530 Subject: [PATCH 162/781] Create HeapSort.cpp This is Efficient sorting algorithm . --- HeapSort.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 HeapSort.cpp diff --git a/HeapSort.cpp b/HeapSort.cpp new file mode 100644 index 00000000..cd06234b --- /dev/null +++ b/HeapSort.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; +void heapify(int a[],int n,int node){ + int mx=node; + int left=2*node+1,right=2*node+2; + if(lefta[mx])mx=left; + if(righta[mx])mx=right; + if(mx!=node){ + swap(a[node],a[mx]); + heapify(a,n,mx); + } +} +void heap(int a[],int n){ + int index=(n/2)-1; + for(int i=index;i>=0;i--)heapify(a,n,i); + for(int i=n-1;i>0;i--){ + swap(a[0],a[i]); + heapify(a,i,0); + } +} +int main(){ + int n; cin>>n; + int a[n]; + for(int i=0;i>a[i]; + heap(a,n); + for(int i=0;i Date: Fri, 16 Oct 2020 15:57:47 +0530 Subject: [PATCH 163/781] Create Factorial of a number by python --- Factorial of a number by python | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Factorial of a number by python diff --git a/Factorial of a number by python b/Factorial of a number by python new file mode 100644 index 00000000..7708570c --- /dev/null +++ b/Factorial of a number by python @@ -0,0 +1,6 @@ +num1=int(input("Enter the number : ")) +fact=1; +for i in range(num1,0,-1): + fact=fact*num1 + num1-=1 +print("The factorial of the number is",fact) From d6f2f163e1bd5a4ffe8da96e5ddecfd9ad24b76c Mon Sep 17 00:00:00 2001 From: polisitni1 <64201881+polisitni1@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:27:53 +0700 Subject: [PATCH 164/781] Create fputs in C --- fputs in C | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 fputs in C diff --git a/fputs in C b/fputs in C new file mode 100644 index 00000000..ceee3ab5 --- /dev/null +++ b/fputs in C @@ -0,0 +1,17 @@ +#include +int main() +{ +FILE *f = NULL; +f = fopen("aticle.txt", "w"); +if(f == NULL) +{ +printf("Error in creating the file\n"); +exit(1); +} +fputs("Writing the first Line in the file.",f); +fputs("Writing the Second Line in the file.",f); +fclose(f); +puts("Writing the first Line on the output screen."); +puts("Writing the second Line on the output screen."); +return 0; +} From d6fe9ff857283d59efb834d443b53c4275582431 Mon Sep 17 00:00:00 2001 From: Ben-Watson23 <72974028+Ben-Watson23@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:58:25 +0530 Subject: [PATCH 165/781] Create Finding a leap Year by Python --- Finding a leap Year by Python | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Finding a leap Year by Python diff --git a/Finding a leap Year by Python b/Finding a leap Year by Python new file mode 100644 index 00000000..5e521a53 --- /dev/null +++ b/Finding a leap Year by Python @@ -0,0 +1,12 @@ +def is_leap(year): + leap=False + if (year%400==0): + leap= False + elif(year%100==0): + leap= False + elif(year%4==0): + leap=True + return leap + +year = int(input()) +print(is_leap(year)) From 3f46753164cd9f70313bf6552c4146bd6b9346cb Mon Sep 17 00:00:00 2001 From: Ben-Watson23 <72974028+Ben-Watson23@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:59:19 +0530 Subject: [PATCH 166/781] Create Length of a string by python --- Length of a string by python | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Length of a string by python diff --git a/Length of a string by python b/Length of a string by python new file mode 100644 index 00000000..bc456277 --- /dev/null +++ b/Length of a string by python @@ -0,0 +1,2 @@ +String=input() +print(len(String)) From 9ed2d7fdd6c448c2b7d3e036459d6cc2193d3b76 Mon Sep 17 00:00:00 2001 From: KrenilBhikadiya <72907830+KrenilBhikadiya@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:00:18 +0530 Subject: [PATCH 167/781] Create Factorial.cpp Find factorial of number using both recursive and iterative way. --- Factorial.cpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Factorial.cpp diff --git a/Factorial.cpp b/Factorial.cpp new file mode 100644 index 00000000..6c91a4cd --- /dev/null +++ b/Factorial.cpp @@ -0,0 +1,31 @@ +// FACTORIAL OF NUMBER + +#include +#define ll unsigned long long int +using namespace std; +clock_t start; +ll rcrsn(ll n){ + start=clock(); + if(n>0) return n*rcrsn(n-1); + else return 1; + start=clock()-start; +} +int main(){ + ll n; cin>>n; + + // ITERATIVE + ll ans=1,t=n; + start=clock(); + while(t)ans*=t,t--; + //cout< Date: Fri, 16 Oct 2020 16:01:36 +0530 Subject: [PATCH 168/781] Create rev_arr.py rev_update.py --- rev_arr.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 rev_arr.py diff --git a/rev_arr.py b/rev_arr.py new file mode 100644 index 00000000..c1d5ff41 --- /dev/null +++ b/rev_arr.py @@ -0,0 +1,14 @@ +''' +Program to reverse the array +Created by Shouvik Dutta +Pls Merge my PR +''' +def rev(l): + ans=[] + for i in range(len(l)-1,-1,-1): + ans.append(l[i]) + return ans +if name==main: + l=[1,2,3,4,5,6] + ans=rev(l) + print(*ans) From f83b9914ca592c09e57043796ce219927620eb94 Mon Sep 17 00:00:00 2001 From: KrenilBhikadiya <72907830+KrenilBhikadiya@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:02:01 +0530 Subject: [PATCH 169/781] Create BinarySearch.cpp binary search program with time complexity analysis. --- BinarySearch.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 BinarySearch.cpp diff --git a/BinarySearch.cpp b/BinarySearch.cpp new file mode 100644 index 00000000..7c9fe7db --- /dev/null +++ b/BinarySearch.cpp @@ -0,0 +1,44 @@ +// BINARY SEARCH + +#include +using namespace std; +clock_t start; +int Bin_Search(int x,int arr[],int n){ + start=clock(); + int low=0,high=n-1; + while(low<=high){ + int mid=low+(high-low)/2; + if(arr[mid]==x) return mid; + if(arr[mid]>n; + int arr[n]; + for(int i=0;i Date: Fri, 16 Oct 2020 16:03:58 +0530 Subject: [PATCH 170/781] Create CoinChangeProblem.cpp This is a making change problem / coin change problem using dynamic programming. --- CoinChangeProblem.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 CoinChangeProblem.cpp diff --git a/CoinChangeProblem.cpp b/CoinChangeProblem.cpp new file mode 100644 index 00000000..de9136dc --- /dev/null +++ b/CoinChangeProblem.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +int coinChange(int coins[],int n,int sum) +{ + // DP table to store data.. + int dp[n+1][sum+1]; + + for(int i=1;i<=n;i++) dp[i][0]=0; + + for(int i=0;i<=sum;i++) dp[0][i]=INT_MAX; + + for(int i=1;i<=n;i++) + { + for(int j=1;j<=sum;j++) + { + // is a valid operation.. + if(j-coins[i-1]>=0) + { + dp[i][j]=min(dp[i-1][j],1+dp[i][j-coins[i-1]]); + } + // is an invalid operation.. + else + { + dp[i][j]=dp[i-1][j]; + } + } + } + + // final answer.. + return dp[n][sum]; +} + +int main() +{ + int N,total; + + // Taking number of coins.. + cin>>N; + + int coins[N]; + + for(int i=0;i>coins[i]; + + // Required Sum.. + cin>>total; + + cout< Date: Fri, 16 Oct 2020 16:07:15 +0530 Subject: [PATCH 171/781] Arithmetic Operations and role of Typecasting Show basic Arithmetic Operations and role of Typecasting Using C Language. --- ...thmetic Operations and role of Typecasting | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 show basic Arithmetic Operations and role of Typecasting diff --git a/show basic Arithmetic Operations and role of Typecasting b/show basic Arithmetic Operations and role of Typecasting new file mode 100644 index 00000000..4226dc5b --- /dev/null +++ b/show basic Arithmetic Operations and role of Typecasting @@ -0,0 +1,23 @@ +#include + +int main() +{ + printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); + int a, b, add, subtract, multiply; + float divide; + + printf("Enter two integers: \n"); + scanf("%d%d", &a, &b); + + add = a+b; + subtract = a-b; + multiply = a*b; + divide = a/b; + + printf("\nAddition of the numbers = %d\n", add); + printf("Subtraction of 2nd number from 1st = %d\n", subtract); + printf("Multiplication of the numbers = %d\n", multiply); + printf("Dividing 1st number from 2nd = %f\n", divide); + printf("\n\n\t\t\tCoding is Fun !\n\n\n"); + return 0; +} From 24ca71d1b6c8b38b393882521557d979ad255757 Mon Sep 17 00:00:00 2001 From: Megha Choudhary <72974234+Coder-Megha@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:09:53 +0530 Subject: [PATCH 172/781] Create Reverse an Array C Program to Reverse an Array using While Loop Using C Language. --- Reverse an Array using While Loop | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Reverse an Array using While Loop diff --git a/Reverse an Array using While Loop b/Reverse an Array using While Loop new file mode 100644 index 00000000..10a0fe0c --- /dev/null +++ b/Reverse an Array using While Loop @@ -0,0 +1,36 @@ +/* C Program to Reverse an Array using While loop */ +#include + +int main() +{ + int a[100], i, j, Size, Temp; + + printf("\nPlease Enter the size of an array: "); + scanf("%d",&Size); + + //Inserting elements into the array + for (i = 0; i < Size; i++) + { + scanf("%d", &a[i]); + } + + j = i - 1; // Assigning j to Last array element + i = 0; // Assigning i to first array element + + while (i < j) + { + Temp = a[i]; + a[i] = a[j]; + a[j] = Temp; + i++; + j--; + } + + printf("\nResult of an Reverse array is: "); + for (i = 0; i < Size; i++) + { + printf("%d \t", a[i]); + } + + return 0; +} From 662520015f2ab568e21256065b3112b26849bd51 Mon Sep 17 00:00:00 2001 From: Megha Choudhary <72974234+Coder-Megha@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:12:10 +0530 Subject: [PATCH 173/781] Display Prime Numbers Between Two Intervals C Program to Display Prime Numbers Between Two Intervals --- Display Prime Numbers Between Two Intervals | 37 +++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Display Prime Numbers Between Two Intervals diff --git a/Display Prime Numbers Between Two Intervals b/Display Prime Numbers Between Two Intervals new file mode 100644 index 00000000..abe97002 --- /dev/null +++ b/Display Prime Numbers Between Two Intervals @@ -0,0 +1,37 @@ +#include + +int main() { + int low, high, i, flag; + printf("Enter two numbers(intervals): "); + scanf("%d %d", &low, &high); + printf("Prime numbers between %d and %d are: ", low, high); + + // iteration until low is not equal to high + while (low < high) { + flag = 0; + + // ignore numbers less than 2 + if (low <= 1) { + ++low; + continue; + } + + // if low is a non-prime number, flag will be 1 + for (i = 2; i <= low / 2; ++i) { + + if (low % i == 0) { + flag = 1; + break; + } + } + + if (flag == 0) + printf("%d ", low); + + // to check prime for the next number + // increase low by 1 + ++low; + } + + return 0; +} From f7de63d82e150b443dc6d62cd5882de9e148b39b Mon Sep 17 00:00:00 2001 From: anmolrk <60808502+anmolrk@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:12:18 +0530 Subject: [PATCH 174/781] Program to convert binary to decimal number Added Optimised code for Program to convert binary to decimal number in C++, JAVA, and Python --- .../ProgramToConvertBinaryToDecimalNumber.cpp | 35 +++++++++++++++++++ ...ProgramToConvertBinaryToDecimalNumber.java | 35 +++++++++++++++++++ .../ProgramToConvertBinaryToDecimalNumber.py | 25 +++++++++++++ 3 files changed, 95 insertions(+) create mode 100644 Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp create mode 100644 Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.java create mode 100644 Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.py diff --git a/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp new file mode 100644 index 00000000..c1a4a0b8 --- /dev/null +++ b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp @@ -0,0 +1,35 @@ +// C++ program to convert binary to decimal +#include +using namespace std; + +// Function to convert binary to decimal +int binaryToDecimal(int n) +{ + int num = n; + int dec_value = 0; + + // Initializing base value to 1, i.e 2^0 + int base = 1; + + int temp = num; + while (temp) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base; + + base = base * 2; + } + + return dec_value; +} + +// Driver program to test above function +int main() +{ + int num; + cout<<"Enter the binary no. : "; + cin>>num; + + cout << binaryToDecimal(num) << endl; +} diff --git a/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.java b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.java new file mode 100644 index 00000000..7b83e4dd --- /dev/null +++ b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.java @@ -0,0 +1,35 @@ +// Java program to convert +// binary to decimal + +// Function to convert +// binary to decimal +class GFG { + static int binaryToDecimal(int n) + { + int num = n; + int dec_value = 0; + + // Initializing base + // value to 1, i.e 2^0 + int base = 1; + + int temp = num; + while (temp > 0) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base; + + base = base * 2; + } + + return dec_value; + } + + // Driver Code + public static void main(String[] args) + { + int num = 10101001; + System.out.println(binaryToDecimal(num)); + } +} diff --git a/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.py b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.py new file mode 100644 index 00000000..7219ebe8 --- /dev/null +++ b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.py @@ -0,0 +1,25 @@ +# Python3 program to convert +# binary to decimal + +# Function to convert +# binary to decimal +def binaryToDecimal(n): + num = n; + dec_value = 0; + + # Initializing base + # value to 1, i.e 2 ^ 0 + base = 1; + + temp = num; + while(temp): + last_digit = temp % 10; + temp = int(temp / 10); + + dec_value += last_digit * base; + base = base * 2; + return dec_value; + +# Driver Code +num = int(input("Enter the binary no. : ")) +print(binaryToDecimal(num)); From 4236557d25cf503f1ab4b08bd0e96079f45d46cb Mon Sep 17 00:00:00 2001 From: dhanrajchavan12 <72442221+dhanrajchavan12@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:12:19 +0530 Subject: [PATCH 175/781] Create ASCII New --- ASCII New | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ASCII New diff --git a/ASCII New b/ASCII New new file mode 100644 index 00000000..a73b9c24 --- /dev/null +++ b/ASCII New @@ -0,0 +1,12 @@ +#include +int main() { + char c; + printf("Enter a character: "); + scanf("%c", &c); + + // %d displays the integer value of a character + // %c displays the actual character + printf("ASCII value of %c = %d", c, c); + + return 0; +} From 036e804e336fbe25453e222ba4faea71997918ce Mon Sep 17 00:00:00 2001 From: Megha Choudhary <72974234+Coder-Megha@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:14:49 +0530 Subject: [PATCH 176/781] Calculate power of a number using a while loop Java Program to Calculate the Power of a Number --- Calculate the Power of a Number Using Java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Calculate the Power of a Number Using Java diff --git a/Calculate the Power of a Number Using Java b/Calculate the Power of a Number Using Java new file mode 100644 index 00000000..f4b492e2 --- /dev/null +++ b/Calculate the Power of a Number Using Java @@ -0,0 +1,17 @@ +public class Power { + + public static void main(String[] args) { + + int base = 3, exponent = 4; + + long result = 1; + + while (exponent != 0) + { + result *= base; + --exponent; + } + + System.out.println("Answer = " + result); + } +} From 2c9b92d623b6747355c7ad58c5dd04afdfa23d73 Mon Sep 17 00:00:00 2001 From: sd-cmd <72244536+sd-cmd@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:21:22 +0530 Subject: [PATCH 177/781] circular linked lists using c --- circular linked lists in c | 113 +++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 circular linked lists in c diff --git a/circular linked lists in c b/circular linked lists in c new file mode 100644 index 00000000..18a6842b --- /dev/null +++ b/circular linked lists in c @@ -0,0 +1,113 @@ +//circular linkedlist +#include +#include +struct node +{ + int info; + struct node *link; + +}; +typedef struct node *NODE; +NODE getnode() +{ + NODE x=(NODE)malloc(sizeof(struct node)); + if(x==NULL){ + printf("Mem not available\n"); + exit(0); + } + return x; +} +NODE insert_front(int item,NODE y) +{ + NODE new_node=getnode(); + new_node->info=item; + new_node->link=new_node; + if(y==NULL) + return new_node; + new_node->link=y->link; + y->link=new_node; + return y; + +} + NODE insert_rear(int item,NODE y) +{ + NODE new_node=getnode(); + new_node->info=item; + new_node->link=new_node; + if(y==NULL) + return new_node; + new_node->link=y->link; + y->link=new_node; + y=new_node; + return y; + +} + +NODE delete_front(NODE y) +{ + if(y==NULL) + { + printf("LinkedList doesn't exsists\n"); + return y; + } + NODE temp=y->link; + y->link=temp->link; + free(temp); + return y; +} +NODE delete_rear(NODE y) +{ + NODE cur,prev; + if(y==NULL) + { + printf("Linked list doesn't exsists\n"); + return y; + } + cur=y->link; + prev=NULL; + while(cur!=y) + { + prev=cur; + cur=cur->link; + } + prev->link=y->link; + y=prev; + free(cur); + return y; +} +void display(NODE y) +{ + NODE cur=y->link; + while(cur!=y) + { + printf("%d ",(*cur).info); + cur=cur->link; + } + printf("%d\n",cur->info); +} +int main() +{ + NODE last=NULL; + last=insert_front(8,last); + last=insert_front(7,last); + last=insert_front(6,last); + + display(last); + + last=insert_rear(9,last); + last=insert_rear(10,last); + last=insert_rear(11,last); + + display(last); + + + last=delete_front(last); + display(last); + + last=delete_rear(last); + display(last); + + return 0; + +} + From adcebb766da99c4dd00885638e0f25e25319ca5b Mon Sep 17 00:00:00 2001 From: shalinipal69 <63445999+shalinipal69@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:29:52 +0530 Subject: [PATCH 178/781] Python-pyramid-pattern program Very common beginner friendly program --- python-pyramid-pattern.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 python-pyramid-pattern.py diff --git a/python-pyramid-pattern.py b/python-pyramid-pattern.py new file mode 100644 index 00000000..6c9ceaae --- /dev/null +++ b/python-pyramid-pattern.py @@ -0,0 +1,36 @@ + +play_arrow + +brightness_4 +# Python 3.x code to demonstrate star pattern + +# Function to demonstrate printing pattern triangle +def triangle(n): + + # number of spaces + k = 2*n - 2 + + # outer loop to handle number of rows + for i in range(0, n): + + # inner loop to handle number spaces + # values changing acc. to requirement + for j in range(0, k): + print(end=" ") + + # decrementing k after each loop + k = k - 1 + + # inner loop to handle number of columns + # values changing acc. to outer loop + for j in range(0, i+1): + + # printing stars + print("* ", end="") + + # ending line after each row + print("\r") + +# Driver Code +n = 5 +triangle(n) From 59e3a42ba9004118bd714bdb2d33212dd1aaa776 Mon Sep 17 00:00:00 2001 From: anmolrk <60808502+anmolrk@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:36:36 +0530 Subject: [PATCH 179/781] Using pre-defined function Program To Convert Binary To Decimal Number Using pre-defined function: --- .../ProgramToConvertBinaryToDecimalNumber.c | 19 +++++++++++++++++++ .../ProgramToConvertBinaryToDecimalNumber.cpp | 11 +++++++++++ ...ProgramToConvertBinaryToDecimalNumber.java | 7 +++++++ .../ProgramToConvertBinaryToDecimalNumber.py | 9 +++++++++ 4 files changed, 46 insertions(+) create mode 100644 Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.c create mode 100644 Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.cpp create mode 100644 Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.java create mode 100644 Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.py diff --git a/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.c b/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.c new file mode 100644 index 00000000..f9fda78b --- /dev/null +++ b/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.c @@ -0,0 +1,19 @@ +#include +#include +#include + +int main() +{ + char binaryNumber[] = "1001"; + int bin, dec = 0; + + bin = atoi(binaryNumber); + + for(int i = 0; bin; i++, bin /= 10) + if (bin % 10) + dec += pow(2, i); + + printf("%d", dec); + + return 0; +} diff --git a/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.cpp b/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.cpp new file mode 100644 index 00000000..6ef2283f --- /dev/null +++ b/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + char binaryNumber[] = "1001"; + + cout << stoi(binaryNumber, 0, 2); + + return 0; +} diff --git a/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.java b/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.java new file mode 100644 index 00000000..17601ec0 --- /dev/null +++ b/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.java @@ -0,0 +1,7 @@ +class ConBintoDEC { + public static void main(String args[]) + { + String binaryNumber = "1001"; + System.out.println(Integer.parseInt(binaryNumber, 2)); + } +} diff --git a/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.py b/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.py new file mode 100644 index 00000000..ce80d835 --- /dev/null +++ b/Program to convert binary to decimal number/Pre-define/ProgramToConvertBinaryToDecimalNumber.py @@ -0,0 +1,9 @@ +# Python3 program to convert +# binary to decimal +n = input("Enter the binary no. : ") + +# Convert n to base 2 +s = int(n, 2) + +print(s) + From 4f1fabc4515f02ddad33a93127e9db0f90dd5c6b Mon Sep 17 00:00:00 2001 From: subahan8055 <65856195+subahan8055@users.noreply.github.com> Date: Fri, 16 Oct 2020 04:34:07 -0700 Subject: [PATCH 180/781] Create Python program to find largest element in the array optimized Python program to find largest element in the array --- ...ogram to find largest element in the array | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Python program to find largest element in the array diff --git a/Python program to find largest element in the array b/Python program to find largest element in the array new file mode 100644 index 00000000..68957817 --- /dev/null +++ b/Python program to find largest element in the array @@ -0,0 +1,24 @@ + +# Python program to find largest element in the array +# in arr[] of size n + +# python function to find maximum +# in arr[] of size n +def largest(arr,n): + + # Initialize maximum element + max = arr[0] + + # Traverse array elements from second + # and compare every element with + # current max + for i in range(1, n): + if arr[i] > max: + max = arr[i] + return max + +# Driver Code +arr = [10, 324, 45, 90, 9808] +n = len(arr) +Ans = largest(arr,n) +print ("Largest in given array is",Ans) From faa4272f8574480494e419aaac900d62d8a6f548 Mon Sep 17 00:00:00 2001 From: yashwanthHack29 <68225496+yashwanthHack29@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:08:26 +0530 Subject: [PATCH 181/781] Create sum of elements optimized code for getting sum of the numbers in arrzy quickly --- sum of elements | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 sum of elements diff --git a/sum of elements b/sum of elements new file mode 100644 index 00000000..89f34037 --- /dev/null +++ b/sum of elements @@ -0,0 +1,13 @@ +#include + +int main() { +int array [10] ={ 1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; +int sum,loop; + +sum=0 ; +for{loop = 9; loop>=0; loop--) { +sum = sum +array[loop]; +} +print("sum of array is %d.",sum) +return 0; +} From 1de79c1dcf3c69f62679db19bfee8af0ded4361a Mon Sep 17 00:00:00 2001 From: shaheryarshahid <38383182+shaheryarshahid@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:44:36 +0500 Subject: [PATCH 182/781] Create power of number Code to calculate the power of the number --- power of number | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 power of number diff --git a/power of number b/power of number new file mode 100644 index 00000000..df1bc45c --- /dev/null +++ b/power of number @@ -0,0 +1,35 @@ +using System; +public class RecExercise15 +{ + + public static void Main() + { + int bNum,pwr; + int result; + Console.Write("\n\n Recursion : Calculate power of any number :\n"); + Console.Write("------------------------------------------------\n"); + + Console.Write(" Input the base value : "); + bNum = Convert.ToInt32(Console.ReadLine()); + + Console.Write(" Input the exponent : "); + pwr = Convert.ToInt32(Console.ReadLine()); + + result=CalcuOfPower(bNum,pwr);//called the function CalcuOfPower + + Console.Write(" The value of {0} to the power of {1} is : {2} \n\n",bNum,pwr,result); + } + +public static int CalcuOfPower( int x,int y) + { + if (y == 0) + return 1; + else + return x * CalcuOfPower( x, y - 1 ); + } +} + +Copy +Sample Output: + + Recursion From 29f66fe2b955929b7312510371a3155072065ab2 Mon Sep 17 00:00:00 2001 From: yashwanthHack29 <68225496+yashwanthHack29@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:18:45 +0530 Subject: [PATCH 183/781] Create Multiplication of 2D Array using C --- Multiplication of 2D Array using C | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Multiplication of 2D Array using C diff --git a/Multiplication of 2D Array using C b/Multiplication of 2D Array using C new file mode 100644 index 00000000..871c7297 --- /dev/null +++ b/Multiplication of 2D Array using C @@ -0,0 +1,90 @@ + + +/*Multiplication of 2-D Array using C Programming*/ + + +#include +#include + +void multiplication(void); + +int A[30][30], B[30][30], C[30][30]; + +int i, j, k, m, n, sum = 0; +//Inside the main function +int main() +{ + //We are defining the size of arrays here + printf("Enter Number of Rows : "); + scanf("%d", &m); + printf("Enter Number of Columns : "); + scanf("%d", &n); + printf("Enter Array Element for First Matrix : \n"); + for(i = 0; i Date: Fri, 16 Oct 2020 17:21:21 +0530 Subject: [PATCH 184/781] Create binary - decimal --- binary - decimal | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 binary - decimal diff --git a/binary - decimal b/binary - decimal new file mode 100644 index 00000000..6b73a730 --- /dev/null +++ b/binary - decimal @@ -0,0 +1,21 @@ +#include +#include +int convert(long long n); +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +int convert(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From a018e36fecc66333acfcb80f9a62c767e1c8ce3b Mon Sep 17 00:00:00 2001 From: yashwanthHack29 <68225496+yashwanthHack29@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:23:59 +0530 Subject: [PATCH 185/781] Create c++ program to find the largest number --- c++ program to find the largest number | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 c++ program to find the largest number diff --git a/c++ program to find the largest number b/c++ program to find the largest number new file mode 100644 index 00000000..1e909f66 --- /dev/null +++ b/c++ program to find the largest number @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main() +{ + int i, n; + float arr[100]; + + cout << "Enter total number of elements(1 to 100): "; + cin >> n; + cout << endl; + + // Store number entered by the user + for(i = 0; i < n; ++i) + { + cout << "Enter Number " << i + 1 << " : "; + cin >> arr[i]; + } + + // Loop to store largest number to arr[0] + for(i = 1;i < n; ++i) + { + // Change < to > if you want to find the smallest element + if(arr[0] < arr[i]) + arr[0] = arr[i]; + } + cout << "Largest element = " << arr[0]; + + return 0; +} From e358a77cd7c86ad89e815443e867acf51b321192 Mon Sep 17 00:00:00 2001 From: shaheryarshahid <38383182+shaheryarshahid@users.noreply.github.com> Date: Fri, 16 Oct 2020 16:55:48 +0500 Subject: [PATCH 186/781] Create Large element in array Python program to find the largest element in an array --- Large element in array | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Large element in array diff --git a/Large element in array b/Large element in array new file mode 100644 index 00000000..2817be1a --- /dev/null +++ b/Large element in array @@ -0,0 +1,13 @@ +#Initialize array +arr = [25, 11, 7, 75, 56]; + +#Initialize max with first element of array. +max = arr[0]; + +#Loop through the array +for i in range(0, len(arr)): + #Compare elements of array with max + if(arr[i] > max): + max = arr[i]; + +print("Largest element present in given array: " + str(max)); From 1cc261d08b8c4b76eb69f4ae240f4ed24be3857d Mon Sep 17 00:00:00 2001 From: Igor Melo <47428695+irdevp@users.noreply.github.com> Date: Fri, 16 Oct 2020 08:57:49 -0300 Subject: [PATCH 187/781] Create ASCII value of given character(Python) --- ASCII value of given character(Python) | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ASCII value of given character(Python) diff --git a/ASCII value of given character(Python) b/ASCII value of given character(Python) new file mode 100644 index 00000000..c0cce301 --- /dev/null +++ b/ASCII value of given character(Python) @@ -0,0 +1,3 @@ +inpt = str(input("Enter Character ")) + +print(f"ASCII value of {inpt} is "+str(ord(inpt))) From 7330bfb0f17db8eda688aea132c7305d70ffc199 Mon Sep 17 00:00:00 2001 From: anmolrk <60808502+anmolrk@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:28:59 +0530 Subject: [PATCH 188/781] Pre-define ProgramToConvertBinaryToDecimalNumber Using Pre-define Function Program To Convert Binary To Decimal Number with C, C++, JAVA, Python --- .../ProgramToConvertBinaryToDecimalNumber.c | 19 +++++++++++++++++++ .../ProgramToConvertBinaryToDecimalNumber.cpp | 11 +++++++++++ ...ProgramToConvertBinaryToDecimalNumber.java | 7 +++++++ .../ProgramToConvertBinaryToDecimalNumber.py | 9 +++++++++ 4 files changed, 46 insertions(+) create mode 100644 Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.c create mode 100644 Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.cpp create mode 100644 Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.java create mode 100644 Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.py diff --git a/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.c b/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.c new file mode 100644 index 00000000..f9fda78b --- /dev/null +++ b/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.c @@ -0,0 +1,19 @@ +#include +#include +#include + +int main() +{ + char binaryNumber[] = "1001"; + int bin, dec = 0; + + bin = atoi(binaryNumber); + + for(int i = 0; bin; i++, bin /= 10) + if (bin % 10) + dec += pow(2, i); + + printf("%d", dec); + + return 0; +} diff --git a/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.cpp b/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.cpp new file mode 100644 index 00000000..6ef2283f --- /dev/null +++ b/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.cpp @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + char binaryNumber[] = "1001"; + + cout << stoi(binaryNumber, 0, 2); + + return 0; +} diff --git a/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.java b/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.java new file mode 100644 index 00000000..17601ec0 --- /dev/null +++ b/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.java @@ -0,0 +1,7 @@ +class ConBintoDEC { + public static void main(String args[]) + { + String binaryNumber = "1001"; + System.out.println(Integer.parseInt(binaryNumber, 2)); + } +} diff --git a/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.py b/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.py new file mode 100644 index 00000000..ce80d835 --- /dev/null +++ b/Program to convert binary to decimal number Pre-define Function/ProgramToConvertBinaryToDecimalNumber.py @@ -0,0 +1,9 @@ +# Python3 program to convert +# binary to decimal +n = input("Enter the binary no. : ") + +# Convert n to base 2 +s = int(n, 2) + +print(s) + From a53b8c09b6e8568dec28286c1625531db732a81a Mon Sep 17 00:00:00 2001 From: shaheryarshahid <38383182+shaheryarshahid@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:04:50 +0500 Subject: [PATCH 189/781] Create convert binary to decimal number Python program to convert a binary number to decimal number --- convert binary to decimal number | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 convert binary to decimal number diff --git a/convert binary to decimal number b/convert binary to decimal number new file mode 100644 index 00000000..18c2f126 --- /dev/null +++ b/convert binary to decimal number @@ -0,0 +1,8 @@ +b_num = list(input("Input a binary number: ")) +value = 0 + +for i in range(len(b_num)): + digit = b_num.pop() + if digit == '1': + value = value + pow(2, i) +print("The decimal value of the number is", value) From 62a6192153dc457345b7237529528d1bac497133 Mon Sep 17 00:00:00 2001 From: Hafeezur Rahman <53285091+Hafeezistic@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:39:49 +0530 Subject: [PATCH 190/781] Create Program to print Fibonacci series in JavaScript.js --- Program to print Fibonacci series in JavaScript.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Program to print Fibonacci series in JavaScript.js diff --git a/Program to print Fibonacci series in JavaScript.js b/Program to print Fibonacci series in JavaScript.js new file mode 100644 index 00000000..db2a6661 --- /dev/null +++ b/Program to print Fibonacci series in JavaScript.js @@ -0,0 +1,12 @@ +// fibonacci series + +let inputNum = prompt('Enter a Number:'); +let num1 = 0, n2 = 1, nextVal; + +nextVal = n1 + n2; + +while(nextVal <= inputNum) { + num1 = num2; + n2 = nextVal; + nextVal = n1 + n2; +} From 1a3ce759d0ed0d41058ade0c4cdfc70b7489d0d0 Mon Sep 17 00:00:00 2001 From: shaheryarshahid <38383182+shaheryarshahid@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:10:39 +0500 Subject: [PATCH 191/781] Create Display ASCII value of given character Get the ASCII value of a given character using Python --- Display ASCII value of given character | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Display ASCII value of given character diff --git a/Display ASCII value of given character b/Display ASCII value of given character new file mode 100644 index 00000000..ff39843c --- /dev/null +++ b/Display ASCII value of given character @@ -0,0 +1,6 @@ +def main(): + num = input("Enter a single number or character to find the ASCII value: ") + while True: + print(num,"converted to ASCII is:",ord(num)) + break +main() From 065c456075ee824db7a985476bade822587f08a3 Mon Sep 17 00:00:00 2001 From: Kunal Jat <72978297+Kunal-Jat@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:44:12 +0530 Subject: [PATCH 192/781] Multiply Two Matrix Using Multi-dimensional Arrays Multiply Two Matrix Using Multi-dimensional Arrays Using C++ Language --- ... Two Matrix Using Multi-dimensional Arrays | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Multiply Two Matrix Using Multi-dimensional Arrays diff --git a/Multiply Two Matrix Using Multi-dimensional Arrays b/Multiply Two Matrix Using Multi-dimensional Arrays new file mode 100644 index 00000000..d09ade57 --- /dev/null +++ b/Multiply Two Matrix Using Multi-dimensional Arrays @@ -0,0 +1,41 @@ +#include +using namespace std; +int main() { + int product[10][10], r1=2, c1=3, r2=3, c2=3, i, j, k; + int a[2][3] = { {2, 4, 1} , {2, 3, 9} }; + int b[3][3] = { {1, 2, 3} , {3, 6, 1} , {2, 9, 7} }; + if (c1 != r2) { + cout<<"Column of first matrix should be equal to row of second matrix"; + } else { + cout<<"The first matrix is:"< Date: Fri, 16 Oct 2020 17:46:39 +0530 Subject: [PATCH 193/781] Convert Binary Number to Decimal and vice-versa C Language To Convert Binary Number to Decimal and vice-versa --- Binary Number to Decimal and vice-versa | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Binary Number to Decimal and vice-versa diff --git a/Binary Number to Decimal and vice-versa b/Binary Number to Decimal and vice-versa new file mode 100644 index 00000000..6b73a730 --- /dev/null +++ b/Binary Number to Decimal and vice-versa @@ -0,0 +1,21 @@ +#include +#include +int convert(long long n); +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +int convert(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From 4f5681e74fc831ecc535330f693938a80c6b72cf Mon Sep 17 00:00:00 2001 From: Kunal Jat <72978297+Kunal-Jat@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:48:57 +0530 Subject: [PATCH 194/781] Find Power of a Number C Language To Find Power of a Number --- Find Power of a Number | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Find Power of a Number diff --git a/Find Power of a Number b/Find Power of a Number new file mode 100644 index 00000000..57efad14 --- /dev/null +++ b/Find Power of a Number @@ -0,0 +1,24 @@ +/* C Program to find Power of a Number using For Loop */ + +#include + +int main() +{ + int i, Number, Exponent; + long Power = 1; + + printf("\n Please Enter any Number : "); + scanf(" %d", &Number); + + printf("\n Please Enter the Exponent Vlaue: "); + scanf(" %d", &Exponent); + + for(i = 1; i <= Exponent; i++) + { + Power = Power * Number; + } + + printf("\n The Final result of %d Power %d = %ld", Number, Exponent, Power); + + return 0; +} From f15701c1a2e54e04c0045b55777571f834a9813b Mon Sep 17 00:00:00 2001 From: Hafeezur Rahman <53285091+Hafeezistic@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:49:08 +0530 Subject: [PATCH 195/781] Create Program to print Fibonnaci Series.js --- Program to print Fibonnaci Series.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Program to print Fibonnaci Series.js diff --git a/Program to print Fibonnaci Series.js b/Program to print Fibonnaci Series.js new file mode 100644 index 00000000..db2a6661 --- /dev/null +++ b/Program to print Fibonnaci Series.js @@ -0,0 +1,12 @@ +// fibonacci series + +let inputNum = prompt('Enter a Number:'); +let num1 = 0, n2 = 1, nextVal; + +nextVal = n1 + n2; + +while(nextVal <= inputNum) { + num1 = num2; + n2 = nextVal; + nextVal = n1 + n2; +} From 35847a830767f85306c81d1fea88750fd8e584f8 Mon Sep 17 00:00:00 2001 From: Kunal Jat <72978297+Kunal-Jat@users.noreply.github.com> Date: Fri, 16 Oct 2020 17:50:46 +0530 Subject: [PATCH 196/781] Print ASCII Value of a Character C Language to Print ASCII Value of a Character --- Print ASCII Value of a Character | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Print ASCII Value of a Character diff --git a/Print ASCII Value of a Character b/Print ASCII Value of a Character new file mode 100644 index 00000000..a40f3ee8 --- /dev/null +++ b/Print ASCII Value of a Character @@ -0,0 +1,16 @@ +/* + * C Program to print ASCII value of a character + */ +#include +#include + +int main() { + char c; + printf("Enter a Character\n"); + scanf("%c",&c); + /*Prints the ASCII value of character as integer */ + printf("ASCII value of %c = %d",c,c); + + getch(); + return 0; +} From 7d3d46bb4cbaf5f6b6d9ab3c4e78dfc778eae143 Mon Sep 17 00:00:00 2001 From: Tanishq Agarwal <55459142+Tanishq987@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:00:58 +0530 Subject: [PATCH 197/781] Counting vowels and consonants optimized and easily understandable way --- ...g vowels and consonants in a random input string | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 counting vowels and consonants in a random input string diff --git a/counting vowels and consonants in a random input string b/counting vowels and consonants in a random input string new file mode 100644 index 00000000..311b1ccb --- /dev/null +++ b/counting vowels and consonants in a random input string @@ -0,0 +1,13 @@ +s = input() # taking input string +l = len(s) # calculate length of string +# creating list of vowels +num = ['a','A','e','E','i','I','o','O','u','U'] +count_vowels = 0 +count_consonants = 0 +for i in s: + if i in num: + count_vowels += 1 + elif 64 Date: Fri, 16 Oct 2020 18:03:50 +0530 Subject: [PATCH 198/781] Adding two matrices feasible solution --- Adding two matrices using python | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Adding two matrices using python diff --git a/Adding two matrices using python b/Adding two matrices using python new file mode 100644 index 00000000..24bbb99e --- /dev/null +++ b/Adding two matrices using python @@ -0,0 +1,18 @@ +# taking input for size of matrix1 row,column +n1,m1 = map(int,input().split()) +# taking matrix1 input +l1 = [list(map(int,input().split())) for i in range(n1)] +# taking input for size of matrix2 row,column +n2,m2 = map(int,input().split()) +# taking matrix2 input +l2 = [list(map(int,input().split())) for i in range(n2)] +if n1!=n2 or m1!=m2: + print("Matrices can't be added") +else: + # adding elments of matrices + for i in range(n1): + for j in range(m1): + l1[i][j] += l2[i][j] + # print updated matrix + for i in l1: + print(*i) From eace7763ea24fc47380d363f938144bf97fc9297 Mon Sep 17 00:00:00 2001 From: Tanishq Agarwal <55459142+Tanishq987@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:05:18 +0530 Subject: [PATCH 199/781] Subtract two matrices Feasible solution --- Subtract two matrices using python | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Subtract two matrices using python diff --git a/Subtract two matrices using python b/Subtract two matrices using python new file mode 100644 index 00000000..225e69e7 --- /dev/null +++ b/Subtract two matrices using python @@ -0,0 +1,18 @@ +# taking input for size of matrix1 row,column +n1,m1 = map(int,input().split()) +# taking matrix1 input +l1 = [list(map(int,input().split())) for i in range(n1)] +# taking input for size of matrix2 row,column +n2,m2 = map(int,input().split()) +# taking matrix2 input +l2 = [list(map(int,input().split())) for i in range(n2)] +if n1!=n2 or m1!=m2: + print("Matrices can't be subtracted") +else: + # subtracting elments of matrices + for i in range(n1): + for j in range(m1): + l1[i][j] += l2[i][j] + # print updated matrix + for i in l1: + print(*i) From f706f54b52f78ce3eeb788e3d8d53ded48a974c3 Mon Sep 17 00:00:00 2001 From: Tanishq Agarwal <55459142+Tanishq987@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:07:06 +0530 Subject: [PATCH 200/781] printing power of a number Feasible way --- Printing power of a number using python | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Printing power of a number using python diff --git a/Printing power of a number using python b/Printing power of a number using python new file mode 100644 index 00000000..6671644c --- /dev/null +++ b/Printing power of a number using python @@ -0,0 +1,5 @@ +n = int(input()) # taking input of number +# taking input power value to be counted of n +p = int(input()) +# printing power +print(n**p) From a9b4b5a2dde8c2fab06e146ec6fd148fa6eeed93 Mon Sep 17 00:00:00 2001 From: Tanishq Agarwal <55459142+Tanishq987@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:08:32 +0530 Subject: [PATCH 201/781] Reversing array Feasible way --- Reversing array using python | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Reversing array using python diff --git a/Reversing array using python b/Reversing array using python new file mode 100644 index 00000000..edc3b4ad --- /dev/null +++ b/Reversing array using python @@ -0,0 +1,5 @@ +# taking input of array +l = list(map(int,input().split())) +# reversing the array +l = l[::-1] +print(l) From 7e45e364566518d24bd896ebf946f710e5963aa3 Mon Sep 17 00:00:00 2001 From: akshaypatidar5 <64529430+akshaypatidar5@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:09:49 +0530 Subject: [PATCH 202/781] Fibonacci_series Write a c program to print fibonacci series without using recursion and using recursion. --- Fibonacci_series | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Fibonacci_series diff --git a/Fibonacci_series b/Fibonacci_series new file mode 100644 index 00000000..cd8dcb20 --- /dev/null +++ b/Fibonacci_series @@ -0,0 +1,16 @@ +include +int main() +{ + int n1=0,n2=1,n3,i,number; + printf("Enter the number of elements:"); + scanf("%d",&number); + printf("\n%d %d",n1,n2);//printing 0 and 1 + for(i=2;i Date: Fri, 16 Oct 2020 18:15:09 +0530 Subject: [PATCH 203/781] Prime_number Write a c program to check prime number. --- Prime_number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Prime_number diff --git a/Prime_number b/Prime_number new file mode 100644 index 00000000..ed9d702e --- /dev/null +++ b/Prime_number @@ -0,0 +1,19 @@ +#include +int main(){ +int n,i,m=0,flag=0; +printf("Enter the number to check prime:"); +scanf("%d",&n); +m=n/2; +for(i=2;i<=m;i++) +{ +if(n%i==0) +{ +printf("Number is not prime"); +flag=1; +break; +} +} +if(flag==0) +printf("Number is prime"); +return 0; + } From 041f1432f827b1c666f13081375a1d550293b482 Mon Sep 17 00:00:00 2001 From: akshaypatidar5 <64529430+akshaypatidar5@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:18:28 +0530 Subject: [PATCH 204/781] Palindrome_number Write a c program to check palindrome number. --- Palindrome_number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Palindrome_number diff --git a/Palindrome_number b/Palindrome_number new file mode 100644 index 00000000..9a3edbd7 --- /dev/null +++ b/Palindrome_number @@ -0,0 +1,19 @@ +#include +int main() +{ +int n,r,sum=0,temp; +printf("enter the number="); +scanf("%d",&n); +temp=n; +while(n>0) +{ +r=n%10; +sum=(sum*10)+r; +n=n/10; +} +if(temp==sum) +printf("palindrome number "); +else +printf("not palindrome"); +return 0; +} From 990ebf40ad27add28e2a63a48eb713746e3956ce Mon Sep 17 00:00:00 2001 From: akshaypatidar5 <64529430+akshaypatidar5@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:19:37 +0530 Subject: [PATCH 205/781] Armstrong_number Write a c program to check armstrong number --- Armstrong_number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Armstrong_number diff --git a/Armstrong_number b/Armstrong_number new file mode 100644 index 00000000..a3c2d76d --- /dev/null +++ b/Armstrong_number @@ -0,0 +1,19 @@ +#include + int main() +{ +int n,r,sum=0,temp; +printf("enter the number="); +scanf("%d",&n); +temp=n; +while(n>0) +{ +r=n%10; +sum=sum+(r*r*r); +n=n/10; +} +if(temp==sum) +printf("armstrong number "); +else +printf("not armstrong number"); +return 0; +} From 234d3d1b26572267f4ff8b98d8b548da07d307fd Mon Sep 17 00:00:00 2001 From: Rahul Raj <63979293+IM-RAHUL-RAJ@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:25:32 +0530 Subject: [PATCH 206/781] Create Arrays: Left Rotation Competitive code for left rotation of array --- Arrays: Left Rotation | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Arrays: Left Rotation diff --git a/Arrays: Left Rotation b/Arrays: Left Rotation new file mode 100644 index 00000000..ade267a3 --- /dev/null +++ b/Arrays: Left Rotation @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(){ +int x,d,n,i,a[1000000],j; + +scanf("%d",&n); + +scanf("%d",&d); + +for(i=0;i Date: Fri, 16 Oct 2020 18:26:18 +0530 Subject: [PATCH 207/781] Create Python Program to Find Factorial of Number Using Recursion example of Python Program to Find Factorial of Number Using Recursion --- ... to Find Factorial of Number Using Recursion | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Python Program to Find Factorial of Number Using Recursion diff --git a/Python Program to Find Factorial of Number Using Recursion b/Python Program to Find Factorial of Number Using Recursion new file mode 100644 index 00000000..bd73658d --- /dev/null +++ b/Python Program to Find Factorial of Number Using Recursion @@ -0,0 +1,17 @@ +# Factorial of a number using recursion + +def recur_factorial(n): + if n == 1: + return n + else: + return n*recur_factorial(n-1) + +num = 7 + +# check if the number is negative +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + print("The factorial of", num, "is", recur_factorial(num)) From ac6ae107d9daf3d737af5407054b1e3c6ad46f72 Mon Sep 17 00:00:00 2001 From: Rahul Raj <63979293+IM-RAHUL-RAJ@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:27:45 +0530 Subject: [PATCH 208/781] Create Counting valleys in c --- Counting valleys in c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Counting valleys in c diff --git a/Counting valleys in c b/Counting valleys in c new file mode 100644 index 00000000..66326fe9 --- /dev/null +++ b/Counting valleys in c @@ -0,0 +1,35 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(){ + int n,i,u=1,d=-1,sum=0,countv=0,counth=0; + + scanf("%d",&n); + char steps[n]; + + scanf("%s",steps); + + for(i=0;i Date: Fri, 16 Oct 2020 18:33:58 +0530 Subject: [PATCH 209/781] ASCCI Value of Character using Kotlin --- ASCCI Value of Character | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 ASCCI Value of Character diff --git a/ASCCI Value of Character b/ASCCI Value of Character new file mode 100644 index 00000000..7b99efbb --- /dev/null +++ b/ASCCI Value of Character @@ -0,0 +1,10 @@ +Using Kotlin Language + +fun main(args: Array) { + val c = 'a' + val ascii = c.toInt() + println("The ASCII value of $c is: $ascii") +} + +Output +The ASCII Value of a is : 65 From 2889b312faa772bd2a7c283efce78c9edf8da841 Mon Sep 17 00:00:00 2001 From: tanyaa29 <65448818+tanyaa29@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:37:11 +0530 Subject: [PATCH 210/781] Create Find the smallest number in a given array This program is written using java --- Find the smallest number in a given array | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Find the smallest number in a given array diff --git a/Find the smallest number in a given array b/Find the smallest number in a given array new file mode 100644 index 00000000..ba0dbd52 --- /dev/null +++ b/Find the smallest number in a given array @@ -0,0 +1,17 @@ +import java.io.*; +import java.util.*; +public class smallest +{ +public static void main(string args[]) +{ +int arr[]={2,4,5,7,34,67,89,45,32,14}; +int min=arr[0]; +int l=arr.length; +for(int i=0;i Date: Fri, 16 Oct 2020 18:38:26 +0530 Subject: [PATCH 211/781] Create Sales by match hackerrank in c hackerrank problem done in c --- Sales by match hackerrank in c | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Sales by match hackerrank in c diff --git a/Sales by match hackerrank in c b/Sales by match hackerrank in c new file mode 100644 index 00000000..91528eff --- /dev/null +++ b/Sales by match hackerrank in c @@ -0,0 +1,67 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + + +// Complete the sockMerchant function below. +int sockMerchant(int n, int* ar) { + int i,j,result=0,count=0,c=0,div=0; + // int *b; + + + for(i=0;i Date: Fri, 16 Oct 2020 18:43:50 +0530 Subject: [PATCH 212/781] Factorial of a Given number using Kotlin --- Factorial of a Given Number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Factorial of a Given Number diff --git a/Factorial of a Given Number b/Factorial of a Given Number new file mode 100644 index 00000000..28ea0c46 --- /dev/null +++ b/Factorial of a Given Number @@ -0,0 +1,19 @@ +fun findFactorial(num: Int): Long { + if (num < 1) { + println("Enter the Non Negative Number") + } + var factorial: Long = 1 + for (i in num downTo 2) { + factorial = factorial * i + } + return factorial +} + +fun main(args: Array) { + val num = 3 + println("Factorial of " + num + " is : " + findFactorial(num)) +} + + +Output +Factorial of 3 is : 6 From ba110d44c98d3a30664b228b3fea4f27f6864890 Mon Sep 17 00:00:00 2001 From: tanyaa29 <65448818+tanyaa29@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:48:15 +0530 Subject: [PATCH 213/781] Create java Program for factorial of a number --- java Program for factorial of a number | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 java Program for factorial of a number diff --git a/java Program for factorial of a number b/java Program for factorial of a number new file mode 100644 index 00000000..de045537 --- /dev/null +++ b/java Program for factorial of a number @@ -0,0 +1,15 @@ +import java.io.*; +import java.utils.*; +public class factorial +{ + public static void main(String args[]) + { + Scanner sc= new Scanner(System.in); + int n= sc.nextInt(); + int fact=1; + for(int i=1;i<=n;i++) + fact=fact*i; + System.out.println("the factorial is"+fact); + } +} + From 7a9061e0b777f191da08f286f7cae694ad7081d6 Mon Sep 17 00:00:00 2001 From: Adithyan P Lal <31040537+adithya1997@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:48:17 +0530 Subject: [PATCH 214/781] Program to print Fibonnaci Series using Kotlin --- Program to print Fibonnaci Series using Kotlin | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Program to print Fibonnaci Series using Kotlin diff --git a/Program to print Fibonnaci Series using Kotlin b/Program to print Fibonnaci Series using Kotlin new file mode 100644 index 00000000..7dbd98c8 --- /dev/null +++ b/Program to print Fibonnaci Series using Kotlin @@ -0,0 +1,18 @@ +fun main(args: Array) { + + val fibCount = 5 + val feb = IntArray(fibCount) + fib[0] = 0 + fib[1] = 1 + for (i in 2 until fibCount) { + fib[i] = fib[i - 1] + fib[i - 2] + } + + for (i in 0 until fibCount) { + print(fib[i].toString() + " ") + } +} + + +Output +0 1 1 2 3 From 1482d2760525ac497707cdfbf0013d8de2f983cd Mon Sep 17 00:00:00 2001 From: ns9737787107 <72914154+ns9737787107@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:52:40 +0530 Subject: [PATCH 215/781] Create Remove Characters in String Except Alphabets example of Remove Characters in String Except Alphabets --- Remove Characters in String Except Alphabets | 26 ++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Remove Characters in String Except Alphabets diff --git a/Remove Characters in String Except Alphabets b/Remove Characters in String Except Alphabets new file mode 100644 index 00000000..c71cfc56 --- /dev/null +++ b/Remove Characters in String Except Alphabets @@ -0,0 +1,26 @@ +#include +int main() { + char line[150]; + + printf("Enter a string: "); + fgets(line, sizeof(line), stdin); // take input + + + for (int i = 0, j; line[i] != '\0'; ++i) { + + // enter the loop if the character is not an alphabet + // and not the null character + while (!(line[i] >= 'a' && line[i] <= 'z') && !(line[i] >= 'A' && line[i] <= 'Z') && !(line[i] == '\0')) { + for (j = i; line[j] != '\0'; ++j) { + + // if jth element of line is not an alphabet, + // assign the value of (j+1)th element to the jth element + line[j] = line[j + 1]; + } + line[j] = '\0'; + } + } + printf("Output String: "); + puts(line); + return 0; +} From a0df31689550f201015bde3fedc5e6f263f68478 Mon Sep 17 00:00:00 2001 From: Adithyan P Lal <31040537+adithya1997@users.noreply.github.com> Date: Fri, 16 Oct 2020 18:54:10 +0530 Subject: [PATCH 216/781] Power / Exponent of a number using Kotlin --- Power of a number | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Power of a number diff --git a/Power of a number b/Power of a number new file mode 100644 index 00000000..a5fb3bd4 --- /dev/null +++ b/Power of a number @@ -0,0 +1,15 @@ +fun main(args: Array) { + val baseValue = 2 + var exponentVAlue = 3 + var result: Long = 1 + + while (exponentValue != 0) { + result *= baseValue.toLong() + --exponentValue + } + + println("Answer = $result") +} + +Output +Answer = 8 From 714736ee41bea8a9ed8e246d9cd8ef2f43650d15 Mon Sep 17 00:00:00 2001 From: ns9737787107 <72914154+ns9737787107@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:00:17 +0530 Subject: [PATCH 217/781] Create From a C-style string example of From a C-style string --- From a C-style string | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 From a C-style string diff --git a/From a C-style string b/From a C-style string new file mode 100644 index 00000000..d12cc7b5 --- /dev/null +++ b/From a C-style string @@ -0,0 +1,42 @@ +#include +using namespace std; + +int main() +{ + char line[150]; + int vowels, consonants, digits, spaces; + + vowels = consonants = digits = spaces = 0; + + cout << "Enter a line of string: "; + cin.getline(line, 150); + for(int i = 0; line[i]!='\0'; ++i) + { + if(line[i]=='a' || line[i]=='e' || line[i]=='i' || + line[i]=='o' || line[i]=='u' || line[i]=='A' || + line[i]=='E' || line[i]=='I' || line[i]=='O' || + line[i]=='U') + { + ++vowels; + } + else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z')) + { + ++consonants; + } + else if(line[i]>='0' && line[i]<='9') + { + ++digits; + } + else if (line[i]==' ') + { + ++spaces; + } + } + + cout << "Vowels: " << vowels << endl; + cout << "Consonants: " << consonants << endl; + cout << "Digits: " << digits << endl; + cout << "White spaces: " << spaces << endl; + + return 0; +} From c398f57027fcf85e61a43a7581295d744ecf9ce3 Mon Sep 17 00:00:00 2001 From: tanyaa29 <65448818+tanyaa29@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:03:23 +0530 Subject: [PATCH 218/781] largest no in array using java using java --- largest no in array using java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 largest no in array using java diff --git a/largest no in array using java b/largest no in array using java new file mode 100644 index 00000000..62c59050 --- /dev/null +++ b/largest no in array using java @@ -0,0 +1,20 @@ +import java.io.*; +public class largest +{ +public static void main(String args[]) +{ +Scanner sc= new Scanner(System.in) +{ +int n=sc.nextInt() //size of array +int arr[]= new int[n] //array creation +for(int i=0;imax) +max=arr[i]; +} +System.out.println("the maximum no is"+max); +} +} From 40b2145d1901060658d269a68ee480d8e57b94a5 Mon Sep 17 00:00:00 2001 From: Rahul Raj <63979293+IM-RAHUL-RAJ@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:04:45 +0530 Subject: [PATCH 219/781] Create gcd-lcm c++ program for gcd-lcm --- gcd-lcm | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 gcd-lcm diff --git a/gcd-lcm b/gcd-lcm new file mode 100644 index 00000000..6a8d9484 --- /dev/null +++ b/gcd-lcm @@ -0,0 +1,27 @@ + +#include +#include +int main() +{ + int x,y; + std::cout<<"Enter the first number: "; + std::cin>>x; + std::cout<<"Enter the 2nd number: "; + std::cin>>y; + int a,b,rem; + + a=x; + b=y; + while(b!=0){ + rem=a%b; + a=b; + b=rem; + } + int gcd,lcm; + + gcd=a; + lcm=(x*y)/gcd; + std::cout< Date: Fri, 16 Oct 2020 19:05:31 +0530 Subject: [PATCH 220/781] Create find power of number optimized a code to find power of any number in python --- find power of number | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 find power of number diff --git a/find power of number b/find power of number new file mode 100644 index 00000000..f3fc8f14 --- /dev/null +++ b/find power of number @@ -0,0 +1,8 @@ +def power(base,exp): + if(exp==1): + return(base) + if(exp!=1): + return(base*power(base,exp-1)) +base=int(input("Enter base: ")) +exp=int(input("Enter exponential value: ")) +print("Result:",power(base,exp)) From 2a50cf8efa00ec028eb5886edcf60a6104e68f02 Mon Sep 17 00:00:00 2001 From: tanyaa29 <65448818+tanyaa29@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:06:44 +0530 Subject: [PATCH 221/781] Create factorial of number java factorial of a number using java --- factorial of number java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 factorial of number java diff --git a/factorial of number java b/factorial of number java new file mode 100644 index 00000000..c156c1f7 --- /dev/null +++ b/factorial of number java @@ -0,0 +1,14 @@ +import java.io.*; +public class factorial +{ +public static void main(String args[]) +{ +Scanner sc= new Scanner(System.in) +{ +int n=sc.nextInt() //size of array +int fact=1; +for(int i=0;i Date: Fri, 16 Oct 2020 19:12:00 +0530 Subject: [PATCH 222/781] Create java Program to count sum of all numbers in array --- ...Program to count sum of all numbers in array | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 java Program to count sum of all numbers in array diff --git a/java Program to count sum of all numbers in array b/java Program to count sum of all numbers in array new file mode 100644 index 00000000..6b5fe696 --- /dev/null +++ b/java Program to count sum of all numbers in array @@ -0,0 +1,17 @@ +import java.utils.*; +public class sum +{ +public static void main(String args[]) +{ +Scanner sc= new Scanner(System.in); +int n= sc.nextInt(); //size +int arr[]= new int[n]; +count=0; +for(int i=0;i Date: Fri, 16 Oct 2020 19:13:55 +0530 Subject: [PATCH 223/781] Create program to reverse an array optimixzed code to reverse an array easily using python --- program to reverse an array | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 program to reverse an array diff --git a/program to reverse an array b/program to reverse an array new file mode 100644 index 00000000..5ec9fb89 --- /dev/null +++ b/program to reverse an array @@ -0,0 +1,14 @@ +# Python program to reverse an array + +def reverseList(A, start, end): + while start < end: + A[start], A[end] = A[end], A[start] + start += 1 + end -= 1 + +# Input To check above function +A = [1, 2, 3, 4, 5, 6] +print(A) +reverseList(A, 0, 5) +print("Reversed list is") +print(A) From 2f0ae47925cd0a5dc60b48793947906dbe25d909 Mon Sep 17 00:00:00 2001 From: Faizal Mansuri <44287703+FaizalM0317@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:18:49 +0530 Subject: [PATCH 224/781] Create Python program to add matrices simple python program to add two matrices using zip method in python --- Python program to add matrices | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Python program to add matrices diff --git a/Python program to add matrices b/Python program to add matrices new file mode 100644 index 00000000..f3a01780 --- /dev/null +++ b/Python program to add matrices @@ -0,0 +1,13 @@ +# Program to add two matrices + +X = [[1,2,3], + [4 ,5,6], + [7 ,8,9]] + +Y = [[9,8,7], + [6,5,4], + [3,2,1]] + +result = [map(sum, zip(*t)) for t in zip(X, Y)] + +print(result) From 1618a8257c30c46ea033e0f72b1d5fa6f3c3979d Mon Sep 17 00:00:00 2001 From: Hafeezur Rahman <53285091+Hafeezistic@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:19:30 +0530 Subject: [PATCH 225/781] Create a Program to find factorial of a number --- Program to find factorial in JavaScript | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program to find factorial in JavaScript diff --git a/Program to find factorial in JavaScript b/Program to find factorial in JavaScript new file mode 100644 index 00000000..eb719217 --- /dev/null +++ b/Program to find factorial in JavaScript @@ -0,0 +1,19 @@ +// take input from the user +let number = parseInt(prompt('Enter a positive integer: ')); + +// if negative +if (number < 0) { + console.log('Error! Factorial for negative number does not exist.'); +} + +else if (number === 0) { + console.log(`The factorial of ${number} is 1.`); +} + +else { + let fact = 1; + for (i = 1; i <= number; i++) { + fact *= i; + } + console.log(`The factorial of ${number} is ${fact}.`); +} From a6ac0d60b9877e845286c4999f241118e6229fe9 Mon Sep 17 00:00:00 2001 From: Hafeezur Rahman <53285091+Hafeezistic@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:20:27 +0530 Subject: [PATCH 226/781] Create Program to find factorial in JavaScript.js --- Program to find factorial in JavaScript.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program to find factorial in JavaScript.js diff --git a/Program to find factorial in JavaScript.js b/Program to find factorial in JavaScript.js new file mode 100644 index 00000000..eb719217 --- /dev/null +++ b/Program to find factorial in JavaScript.js @@ -0,0 +1,19 @@ +// take input from the user +let number = parseInt(prompt('Enter a positive integer: ')); + +// if negative +if (number < 0) { + console.log('Error! Factorial for negative number does not exist.'); +} + +else if (number === 0) { + console.log(`The factorial of ${number} is 1.`); +} + +else { + let fact = 1; + for (i = 1; i <= number; i++) { + fact *= i; + } + console.log(`The factorial of ${number} is ${fact}.`); +} From 3db7ee015b42eba175ea860a86e880ce6c5429a6 Mon Sep 17 00:00:00 2001 From: Faizal Mansuri <44287703+FaizalM0317@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:23:35 +0530 Subject: [PATCH 227/781] Create python program to print ascii value a simple python program to find ascii value of any character using python --- python program to print ascii value | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 python program to print ascii value diff --git a/python program to print ascii value b/python program to print ascii value new file mode 100644 index 00000000..29316095 --- /dev/null +++ b/python program to print ascii value @@ -0,0 +1,5 @@ +# ASCII Value of Character + +c = 'g' +# print the ASCII value of assigned character in c +print("The ASCII value of '" + c + "' is", ord(c)) From ba8a5cadef9cffc9a4b548af3d4e98365f24db78 Mon Sep 17 00:00:00 2001 From: Abhay Singh <58264237+q225@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:26:32 +0530 Subject: [PATCH 228/781] Create Count the no. of setbits in a number This program is about to calculating the number of setbits in the binary representation of a decimal number using all possible methods. --- Count the no. of setbits in a number | 37 ++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Count the no. of setbits in a number diff --git a/Count the no. of setbits in a number b/Count the no. of setbits in a number new file mode 100644 index 00000000..020ef312 --- /dev/null +++ b/Count the no. of setbits in a number @@ -0,0 +1,37 @@ +#include +using namespace std; +// Counting the number of setbits using AND opreator(&) and Bitshift(>>) +int countsetbits(int n) +{ + int ans; + while(n!=0){ + ans+=(n&1); + n=n>>1;//using right shift +} + return ans; +} +// More faster approach +int countsetbitsfaster (int n) +{ + int a; + while(n>0) + { + n=n&(n-1);//removes the set bit from right to left + a++; + } + +return a; +} +int main() +{ + int n = 13; + + cout< Date: Fri, 16 Oct 2020 19:46:06 +0545 Subject: [PATCH 229/781] Create Factorial program Optimized code for getting factorial. --- Factorial program | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Factorial program diff --git a/Factorial program b/Factorial program new file mode 100644 index 00000000..4094bc8f --- /dev/null +++ b/Factorial program @@ -0,0 +1,23 @@ +#include + +int main() + +{ + + int i,fact=1,number; + + printf("Enter a number: "); + + scanf("%d",&number); + + for(i=1;i<=number;i++){ + + fact=fact*i; + + } + + printf("Factorial of %d is: %d",number,fact); + +return 0; + +} From b26fadf81b9de762ea308797b56724d9ca2cdb85 Mon Sep 17 00:00:00 2001 From: Eduardo Bernardino <38435762+dudubernardino@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:01:57 -0300 Subject: [PATCH 230/781] Matriz.py Matriz in python --- matriz in python | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 matriz in python diff --git a/matriz in python b/matriz in python new file mode 100644 index 00000000..bf61c2d7 --- /dev/null +++ b/matriz in python @@ -0,0 +1,11 @@ +matriz = []; +quantidade_linhas = 2; +quantidade_colunas = 2; + +for l in range(quantidade_linhas): + colunas = []; + for c in range(quantidade_colunas): + quantidade = int(input("Informe o elemento [{}][{}]:".format(l, c))); + colunas.append(quantidade); + + matriz.append(colunas); From 487ef86437e26ced6393b4363685d05d0089336d Mon Sep 17 00:00:00 2001 From: Ashishkhakural <43742188+Ashishkhakural@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:49:35 +0545 Subject: [PATCH 231/781] Create Prime number program in c Optimized code to find prime number --- Prime number program in c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Prime number program in c diff --git a/Prime number program in c b/Prime number program in c new file mode 100644 index 00000000..61c336b1 --- /dev/null +++ b/Prime number program in c @@ -0,0 +1,37 @@ +#include + +int main(){ + +int n,i,m=0,flag=0; + +printf("Enter the number to check prime:"); + +scanf("%d",&n); + +m=n/2; + +for(i=2;i<=m;i++) + +{ + +if(n%i==0) + +{ + +printf("Number is not prime"); + +flag=1; + +break; + +} + +} + +if(flag==0) + +printf("Number is prime"); + +return 0; + + } From 4d990b46a25406b59772a177cb4d1bc2f9f29204 Mon Sep 17 00:00:00 2001 From: Abhay Singh <58264237+q225@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:37:24 +0530 Subject: [PATCH 232/781] Create Count the maximum unit of water trapped in between the buildings It is the easiest way to calculate the amount of trapped water in between buildings. --- ... of water trapped in between the buildings | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Count the maximum unit of water trapped in between the buildings diff --git a/Count the maximum unit of water trapped in between the buildings b/Count the maximum unit of water trapped in between the buildings new file mode 100644 index 00000000..e0922e56 --- /dev/null +++ b/Count the maximum unit of water trapped in between the buildings @@ -0,0 +1,52 @@ +Problem Statement : +You are give a N numver of buildings with may be simmilar or different heights and an array denoting the all heights. + + +\\\\\\\\\\\\\\\\\\\\\\\ + +#include +#include +using namespace std; +int main() +{ + int n;//there are n buildings + cin>>n; + int arr[n];//array to store the size of n buldings + for(int i=0;i>arr[i]; + + } + int left[n],right[n]; //these are the two arrays which whicha are used to precompute the height of the leftmost highest and the rightmost highest buildings + int s=arr[0]; + for(int i=0;i=0;i--) + { + if(arr[i]>d) + { + d=arr[i]; + } + right[i]=d; + + } + + int water = 0; // denotes the maximum amout of trapped water + + for(int i=0;i Date: Fri, 16 Oct 2020 19:53:05 +0545 Subject: [PATCH 233/781] Create Reverse a Number using a while loop in Java Code to reverse a number using java --- Reverse a Number using a while loop in Java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Reverse a Number using a while loop in Java diff --git a/Reverse a Number using a while loop in Java b/Reverse a Number using a while loop in Java new file mode 100644 index 00000000..840b430c --- /dev/null +++ b/Reverse a Number using a while loop in Java @@ -0,0 +1,21 @@ +public class ReverseNumber { + + public static void main(String[] args) { + + int num = 1234, reversed = 0; + + while(num != 0) { + + int digit = num % 10; + + reversed = reversed * 10 + digit; + + num /= 10; + + } + + System.out.println("Reversed Number: " + reversed); + + } + +} From d08d5c99ccdcd6fbdb99a75388b6a95cfa6fc715 Mon Sep 17 00:00:00 2001 From: Ashishkhakural <43742188+Ashishkhakural@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:56:24 +0545 Subject: [PATCH 234/781] Create Convert decimal to binary using java Code to convert decimal to binary using java --- Convert decimal to binary using java | 41 ++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 Convert decimal to binary using java diff --git a/Convert decimal to binary using java b/Convert decimal to binary using java new file mode 100644 index 00000000..e25b7d73 --- /dev/null +++ b/Convert decimal to binary using java @@ -0,0 +1,41 @@ +public class DecimalToBinaryExample2{ + +public static void toBinary(int decimal){ + + int binary[] = new int[40]; + + int index = 0; + + while(decimal > 0){ + + binary[index++] = decimal%2; + + decimal = decimal/2; + + } + + for(int i = index-1;i >= 0;i--){ + + System.out.print(binary[i]); + + } + +System.out.println();//new line + +} + +public static void main(String args[]){ + +System.out.println("Decimal of 10 is: "); + +toBinary(10); + +System.out.println("Decimal of 21 is: "); + +toBinary(21); + +System.out.println("Decimal of 31 is: "); + +toBinary(31); + +}} From c57de7ac3a941acb71f6599e8b854f5d0487fba7 Mon Sep 17 00:00:00 2001 From: Igor Melo <47428695+irdevp@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:11:25 -0300 Subject: [PATCH 235/781] Create Reverse the array [Python] --- Reverse the array [Python] | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 Reverse the array [Python] diff --git a/Reverse the array [Python] b/Reverse the array [Python] new file mode 100644 index 00000000..f42f0abd --- /dev/null +++ b/Reverse the array [Python] @@ -0,0 +1,3 @@ +array=[0,1,30,10,2,42,22,8,41,90,23,5,9] +arrayReversed = list(reversed(array)) +print(f"Array reversed\n{arrayReversed}") From 068b4fb8e1666f0853510185878b612d05519fee Mon Sep 17 00:00:00 2001 From: Abhay Singh <58264237+q225@users.noreply.github.com> Date: Fri, 16 Oct 2020 19:43:13 +0530 Subject: [PATCH 236/781] Create Euler's Method to find the highest common factor of two numbers This is the best method of finding the greatest common divisor of two numbers --- ...o find the highest common factor of two numbers | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Euler's Method to find the highest common factor of two numbers diff --git a/Euler's Method to find the highest common factor of two numbers b/Euler's Method to find the highest common factor of two numbers new file mode 100644 index 00000000..24b35734 --- /dev/null +++ b/Euler's Method to find the highest common factor of two numbers @@ -0,0 +1,14 @@ +#include +using namespace std; + +int hcf(int a,int b) +{ + +return b==0?a:hcf(b,a%b); +} +int main() +{ + int a,b; + cin>>a>>b; + cout< Date: Fri, 16 Oct 2020 19:43:51 +0530 Subject: [PATCH 237/781] Telegram_Bot --- .../Telegram_Bot_Using_Sytaxdb_Api/Token.py | 26 +++++++++ .../Telegram_bot.py | 54 +++++++++++++++++++ Telegram_Bot_Using_Syntaxdb_api/Token.py | 26 +++++++++ .../syntaxdb_api.py | 41 ++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 Telegram_Bot_Using_Syntaxdb_api/Telegram_Bot_Using_Sytaxdb_Api/Token.py create mode 100644 Telegram_Bot_Using_Syntaxdb_api/Telegram_bot.py create mode 100644 Telegram_Bot_Using_Syntaxdb_api/Token.py create mode 100644 Telegram_Bot_Using_Syntaxdb_api/syntaxdb_api.py diff --git a/Telegram_Bot_Using_Syntaxdb_api/Telegram_Bot_Using_Sytaxdb_Api/Token.py b/Telegram_Bot_Using_Syntaxdb_api/Telegram_Bot_Using_Sytaxdb_Api/Token.py new file mode 100644 index 00000000..35e9a011 --- /dev/null +++ b/Telegram_Bot_Using_Syntaxdb_api/Telegram_Bot_Using_Sytaxdb_Api/Token.py @@ -0,0 +1,26 @@ +from options import * +import os + +if __name__=='__main__': + TOKEN = '' + PORT = int(os.environ.get('PORT', '8443')) + + updater = Updater(TOKEN) + + + + #logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',level=logging.INFO) + + #logger = logging.getLogger(__name__) + + updater = Updater(token=TOKEN) + + dispatcher = updater.dispatcher + + dispatcher.add_handler(CommandHandler('start',start)) + + dispatcher.add_handler(CommandHandler('help',help)) + + dispatcher.add_handler(CommandHandler('search', search, pass_args = True)) + + updater.start_polling() \ No newline at end of file diff --git a/Telegram_Bot_Using_Syntaxdb_api/Telegram_bot.py b/Telegram_Bot_Using_Syntaxdb_api/Telegram_bot.py new file mode 100644 index 00000000..992ac4e1 --- /dev/null +++ b/Telegram_Bot_Using_Syntaxdb_api/Telegram_bot.py @@ -0,0 +1,54 @@ +from telegram.ext import CommandHandler, Updater +from telegram import * +import syntaxdb + + +def start(bot, update): + bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING) + + bot.sendMessage(chat_id = update.message.chat_id, text = ''' + Hey %s %s! Welcome to SyntaxDB Bot! Type /help for more information regarding the functionalities of this particular bot. + ''' %(update.message.from_user.first_name,update.message.from_user.last_name)) + +def search(bot, update, args): + topic = "" + i = 0 + count = 0 + if(len(args) == 0): + bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING) + bot.sendMessage(chat_id = update.message.chat_id, text = ''' + Please make sure that you enter a valid search query for me to help you. + ''') + for arg in args: + if(i < (len(args) - 1)): + topic += arg + " " + else: + topic += arg + i += 1 + print("\""+ topic + "\"") + syntax = syntaxdb.Syntaxdb(choice = 0, search_query = topic, language = "") + content = syntax.getContent() + + for i in range(0,len(content)): + print("here") + count += 1 + bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING) + bot.sendMessage(chat_id = update.message.chat_id, text = content[i]) + + if(count==0): + bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING) + bot.sendMessage(chat_id = update.message.chat_id, text = ''' + There are no related searches to the topic you entered! Make sure your search query was right and try again! Check for spelling mistakes and follow the format in /help + ''') + + + +def help(bot, update): + bot.sendChatAction(chat_id = update.message.chat_id, action = ChatAction.TYPING) + bot.sendMessage(chat_id = update.message.chat_id, text = ''' + To use this bot, look at the format below! + /search + Example : Suppose you want to use how to use the concept for in java, + /search for in java + ''') + diff --git a/Telegram_Bot_Using_Syntaxdb_api/Token.py b/Telegram_Bot_Using_Syntaxdb_api/Token.py new file mode 100644 index 00000000..126526fa --- /dev/null +++ b/Telegram_Bot_Using_Syntaxdb_api/Token.py @@ -0,0 +1,26 @@ +from options import * +import os + +if __name__=='__main__': + TOKEN = '<809112078:AAEOBQvRY0eIJVNyMdXQjZwYQy-K_RfZs38>' + PORT = int(os.environ.get('PORT', '8443')) + + updater = Updater(TOKEN) + + + + #logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',level=logging.INFO) + + #logger = logging.getLogger(__name__) + + updater = Updater(token=TOKEN) + + dispatcher = updater.dispatcher + + dispatcher.add_handler(CommandHandler('start',start)) + + dispatcher.add_handler(CommandHandler('help',help)) + + dispatcher.add_handler(CommandHandler('search', search, pass_args = True)) + + updater.start_polling() \ No newline at end of file diff --git a/Telegram_Bot_Using_Syntaxdb_api/syntaxdb_api.py b/Telegram_Bot_Using_Syntaxdb_api/syntaxdb_api.py new file mode 100644 index 00000000..bb32eb5b --- /dev/null +++ b/Telegram_Bot_Using_Syntaxdb_api/syntaxdb_api.py @@ -0,0 +1,41 @@ +import requests +import json + +class Syntaxdb(): + def __init__(self, choice=0, search_query="",language=""): + '''choice = 0 => concepts in any language''' + '''choice = 1 => all concepts of particular language''' + if(choice == 0): + self.url = "https://syntaxdb.com/api/v1/concepts/search?q="+search_query + else: + self.url = "https://syntaxdb.com/api/v1/languages/"+language+"/concepts" + + def getResponse(self): + '''Returns the reponse got from the url''' + return requests.get(self.url) + + def getJson(self,response): + '''Pass in the requests reponse and returns the json data''' + return response.json() + + def getContent(self): + '''Pass the json data and returns list''' + '''if choice is concept, the summary will have only one item in list''' + '''if choice is is 1, the summary will have multiple items in list''' + response = self.getResponse() + json_response = self.getJson(response) + summary = [] + for data in json_response: + concept = data['concept_search'] + syntax = data['syntax'] + description = data['description'] + notes = data['notes'] + example = data['example'] + summary+=["\nCONCEPT\n"+concept+"\n\nSYNTAX\n"+syntax+"\n\nDESCRIPTION\n"+ description+"\n\nNOTES\n"+notes+"\n\nEXAMPLE\n"+example] + return summary + + def getAllConcepts(self): + '''Pass the langauge and a list of all concepts are returned''' + response = self.getResponse() + json_response = self.getJson(response) + return self.getContent(json_response) \ No newline at end of file From 844acde1dbb279be312571f75abfe5349d7cbfe5 Mon Sep 17 00:00:00 2001 From: ujwal475 <72316262+ujwal475@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:04:23 +0530 Subject: [PATCH 238/781] Create Fibonacii series --- Fibonacii series | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Fibonacii series diff --git a/Fibonacii series b/Fibonacii series new file mode 100644 index 00000000..45bc37d3 --- /dev/null +++ b/Fibonacii series @@ -0,0 +1,16 @@ +#include +int fib(int m){ +if(m==0||m==1) + return m; +else + return (fib(m-1)+fib(m-2)); +} + +int main() +{ + int n; + printf("Enter the number"); + scanf("%d",&n); + int res=fib(n); + printf("%d",res); +} From 7b34eca8be85af3b1d248b5b4427351ce4a36cfe Mon Sep 17 00:00:00 2001 From: sagar2s Date: Fri, 16 Oct 2020 20:25:49 +0545 Subject: [PATCH 239/781] Python Socket Programming --- Python_SocketProramming.py | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Python_SocketProramming.py diff --git a/Python_SocketProramming.py b/Python_SocketProramming.py new file mode 100644 index 00000000..fd4c1f8b --- /dev/null +++ b/Python_SocketProramming.py @@ -0,0 +1,56 @@ +import socket # Import socket module + +port = 60000 # Reserve a port for your service. +s = socket.socket() # Create a socket object +host = socket.gethostname() # Get local machine name +s.bind((host, port)) # Bind to the port +s.listen(5) # Now wait for client connection. + +print 'Server listening....' + +while True: + conn, addr = s.accept() # Establish connection with client. + print 'Got connection from', addr + data = conn.recv(1024) + print('Server received', repr(data)) + + filename='mytext.txt' + f = open(filename,'rb') + l = f.read(1024) + while (l): + conn.send(l) + print('Sent ',repr(l)) + l = f.read(1024) + f.close() + + print('Done sending') + conn.send('Thank you for connecting') + conn.close() + + +# client.py + +import socket # Import socket module + +s = socket.socket() # Create a socket object +host = socket.gethostname() # Get local machine name +port = 60000 # Reserve a port for your service. + +s.connect((host, port)) +s.send("Hello server!") + +with open('received_file', 'wb') as f: + print 'file opened' + while True: + print('receiving data...') + data = s.recv(1024) + print('data=%s', (data)) + if not data: + break + # write data to a file + f.write(data) + +f.close() +print('Successfully get the file') +s.close() +print('connection closed') From 7b5db593536961a15191d72a41bf8fb5ee4a044b Mon Sep 17 00:00:00 2001 From: ujwal475 <72316262+ujwal475@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:19:30 +0530 Subject: [PATCH 240/781] Create Create Fibonacci series Optimized code for fibonacci series --- Create Fibonacci series | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Create Fibonacci series diff --git a/Create Fibonacci series b/Create Fibonacci series new file mode 100644 index 00000000..612791d3 --- /dev/null +++ b/Create Fibonacci series @@ -0,0 +1,14 @@ +#include +int fib(int m){ +if(m==0||m==1) + return m; +else + return(fib(m-1)+fib(m-2)); +} +int main(){ + int n; + scanf("%d",&n); + int res=fib(n); + printf("%d",res); + return 0; + } From 004420d9c9a10390edb56d7962d69c7e33e87e7f Mon Sep 17 00:00:00 2001 From: Igor Melo <47428695+irdevp@users.noreply.github.com> Date: Fri, 16 Oct 2020 11:51:17 -0300 Subject: [PATCH 241/781] Create Convert binary to octal, hexadecimal and decimal number [Python] --- ...binary to octal, hexadecimal and decimal number [Python] | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Convert binary to octal, hexadecimal and decimal number [Python] diff --git a/Convert binary to octal, hexadecimal and decimal number [Python] b/Convert binary to octal, hexadecimal and decimal number [Python] new file mode 100644 index 00000000..2b85718f --- /dev/null +++ b/Convert binary to octal, hexadecimal and decimal number [Python] @@ -0,0 +1,6 @@ +inpt = str(input("Enter binary number\n")) + +print("The binary value of", inpt, "is:") +print(int(inpt, 2),"in decimal") +print(oct(int(inpt)), "in octal.") +print(hex(int(inpt)), "in hexadecimal.") From a000b7e80565ae5d7ab566531b48ac9d7f953331 Mon Sep 17 00:00:00 2001 From: Abhay Singh <58264237+q225@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:30:04 +0530 Subject: [PATCH 242/781] Create How Operator Overloading Works ? This is a program which completely explains how operators can be overloaded, by taking an example of subtraction operator (-) --- How Operator Overloading Works ? | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 How Operator Overloading Works ? diff --git a/How Operator Overloading Works ? b/How Operator Overloading Works ? new file mode 100644 index 00000000..03504b36 --- /dev/null +++ b/How Operator Overloading Works ? @@ -0,0 +1,37 @@ +// operator overloading using member function program + + +#include +#include +using namespace std; +class number +{ + private: + int x,y,z; + public: + number(int n,int n1, int n2) + { + x=n; + y=n1; + z=n2; + } + void operator -() + { x=-x; + y=-y; + z=-z; + } + void showdata() + { cout<<"\n x="< Date: Fri, 16 Oct 2020 20:37:01 +0530 Subject: [PATCH 243/781] Create java program to check vowel or not optimised simple java programme code to display the entered word is vowel or not --- java program to check vowel or not | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 java program to check vowel or not diff --git a/java program to check vowel or not b/java program to check vowel or not new file mode 100644 index 00000000..5360b7d1 --- /dev/null +++ b/java program to check vowel or not @@ -0,0 +1,33 @@ +import java.util.Scanner; +class JavaExample +{ + public static void main(String[ ] arg) + { + boolean isVowel=false;; + Scanner scanner=new Scanner(System.in); + System.out.println("Enter a character : "); + char ch=scanner.next().charAt(0); + scanner.close(); + switch(ch) + { + case 'a' : + case 'e' : + case 'i' : + case 'o' : + case 'u' : + case 'A' : + case 'E' : + case 'I' : + case 'O' : + case 'U' : isVowel = true; + } + if(isVowel == true) { + System.out.println(ch+" is a Vowel"); + } + else { + if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) + System.out.println(ch+" is a Consonant"); + else + System.out.println("Input is not an alphabet"); + } + } From 6c57112814d49b25012eb70b57903b920f036fd9 Mon Sep 17 00:00:00 2001 From: Abhay Singh <58264237+q225@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:39:33 +0530 Subject: [PATCH 244/781] Create How to print Swastic Pattern This is programmatic way that how swastic pattern can be printed But there is a condition that the value of N must be odd. --- How to print Swastic Pattern | 82 ++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 How to print Swastic Pattern diff --git a/How to print Swastic Pattern b/How to print Swastic Pattern new file mode 100644 index 00000000..d89205e3 --- /dev/null +++ b/How to print Swastic Pattern @@ -0,0 +1,82 @@ +Source Code : +///////////////// + +#include +using namespace std; +int main() +{ + int n; + cin>>n; + cout<<"*"; + for(int i=0;i<(n-3)/2;i++) + { + cout<<" "; + } + for(int i=0;i<(n+1)/2;i++) + { + cout<<"*"; +} + cout< Date: Fri, 16 Oct 2020 12:12:58 -0300 Subject: [PATCH 245/781] Create Find power of any number[Python] --- Find power of any number[Python] | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Find power of any number[Python] diff --git a/Find power of any number[Python] b/Find power of any number[Python] new file mode 100644 index 00000000..da4cac99 --- /dev/null +++ b/Find power of any number[Python] @@ -0,0 +1,8 @@ +import math + +number = int(input("Enter any Positive Integer : ")) +exponent = int(input("Enter Exponent Value : ")) + +power = math.pow(number, exponent) + +print("{0} Power {1} = {2}".format(number, exponent, power)) From 1c2947d3ff1314eef7550ea6dc99c38698e030c6 Mon Sep 17 00:00:00 2001 From: Utkarsh1520 <72489678+Utkarsh1520@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:46:12 +0530 Subject: [PATCH 246/781] Multiplication Of 3D Matrice. --- 3D.java | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 3D.java diff --git a/3D.java b/3D.java new file mode 100644 index 00000000..7344fbb4 --- /dev/null +++ b/3D.java @@ -0,0 +1,49 @@ +public static void main(String[] args) { + Scanner getIt = new Scanner(System.in); + System.out.println("Input 1 integer n: "); + int n = getIt.nextInt(); + if (n > 0){ + final double M[][][] = new double[n][n][n]; + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + for (int k = 0; k < n; k++) + M[i][j][k] = 3.0; + System.out.println("Input 1 integer p: "); + int p = getIt.nextInt(); + if(p > 0){ + for(int q = 1; q <= p; q++){ + for (int i = 0; i < n; i++){ + for (int j = 0; j < n; j++){ + for (int k = 0; k < n; k++){ + System.out.printf("%f ", Math.pow(matrixMult(M[i], M[i])[j][k], q)); + } + System.out.println("\n"); + } + + } + System.out.println("xxxxxxxxxxxxxxxxxxxxx"); + } + } + else{ + System.out.println("Woops, you entered a negative p."); + } + } + else{ + System.out.println("Woops, you entered a negative n."); + } +} + +public static double[][] matrixMult(double a[][], double b[][]) { + int aRows = a.length; + int aCols = a[0].length; + int bCols = b[0].length; + double[][] result = new double[aRows][bCols]; + for(int i = 0; i < aRows; i++){ + for(int j = 0; j < bCols; j++){ + for(int k = 0; k < aCols; k++){ + result[i][j] += a[i][k] * b[k][j]; + } + } + } + return result; +} From 7567e646cc3b46804f4f5b9c28b542b3198d0450 Mon Sep 17 00:00:00 2001 From: Abhay Singh <58264237+q225@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:48:05 +0530 Subject: [PATCH 247/781] Create Application of Josephus Problem This is a problem where two inputs are given N and k where N is the number of peoples standing in a circle and K is the number of people you skip in each turn. --- Application of Josephus Problem | 43 +++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Application of Josephus Problem diff --git a/Application of Josephus Problem b/Application of Josephus Problem new file mode 100644 index 00000000..06749795 --- /dev/null +++ b/Application of Josephus Problem @@ -0,0 +1,43 @@ + +This is a problem where two inputs are given N and k where N is the number of peoples standing in a circle and K is the number of people you skip in each turn. + + + +#include +#define ll long long +using namespace std; +void solve(int arr[],int n,int k,int index) +{ + + int t=n/k; + while(t--) + { + + + arr[index]=0; + index=(index + (k))%n; + + + } +} +int main() +{ + int t=0; + cin>>t; + while(t--) + { + int n=0; + int k=0,x=0,y=0; + cin>>n>>k>>x>>y; + int arr[n]; + + + if(arr[y-1]==0) + cout<<"YES"; + else + cout<<"NO"; +cout<<"\n"; + + } + return 0; +} From 4741267ca7a3e4163e8e998b09e8ac910645a9bc Mon Sep 17 00:00:00 2001 From: Abhay Singh <58264237+q225@users.noreply.github.com> Date: Fri, 16 Oct 2020 20:53:05 +0530 Subject: [PATCH 248/781] Create Count the occurrence of distinct characters in a string This code is about to find the frequency of each distinct character in a string --- ...urrence of distinct characters in a string | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Count the occurrence of distinct characters in a string diff --git a/Count the occurrence of distinct characters in a string b/Count the occurrence of distinct characters in a string new file mode 100644 index 00000000..9137b372 --- /dev/null +++ b/Count the occurrence of distinct characters in a string @@ -0,0 +1,29 @@ +#include +#include +#include +#include +using namespace std; +int main() +{ + +string s; +cin>>s; +int arr[26]; +memset(arr,0,sizeof(arr)); +int n=s.length(); +for(int i=0;i0) + { + cout< Date: Fri, 16 Oct 2020 20:57:15 +0530 Subject: [PATCH 249/781] Create Python program for Fibonnaci Series An optimal python code using recursion to find the Fibonacci series of the input positive number. --- Python program for Fibonnaci Series | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Python program for Fibonnaci Series diff --git a/Python program for Fibonnaci Series b/Python program for Fibonnaci Series new file mode 100644 index 00000000..6a2d20d0 --- /dev/null +++ b/Python program for Fibonnaci Series @@ -0,0 +1,22 @@ +# Python3 script to print Fibonacci series + + +def fib(num): + if num == 1: + return 0 + elif num == 2: + return 1 + else: + return fib(num - 1) + fib(num - 2) + + +while True: + try: + n = int(input("Enter your number:\t")) + if n > 0: + print("The fibonacci series number is: ", fib(n)) + break + else: + raise Exception("Invalid Input. Try Again") + except Exception as e: + pass From 79473818f14c75a093e7ddf9532035f68d2fbf5c Mon Sep 17 00:00:00 2001 From: Abhay Singh <58264237+q225@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:12:18 +0530 Subject: [PATCH 250/781] Create How to calculate Factorial of Large Numbers using array ? Finding the factorial of the large numbers like 100 easily --- ...e Factorial of Large Numbers using array ? | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 How to calculate Factorial of Large Numbers using array ? diff --git a/How to calculate Factorial of Large Numbers using array ? b/How to calculate Factorial of Large Numbers using array ? new file mode 100644 index 00000000..f6bf4130 --- /dev/null +++ b/How to calculate Factorial of Large Numbers using array ? @@ -0,0 +1,50 @@ +#include +using namespace std; +#define max 500 +int multiply(int x,int res[],int size) +{ + int carry=0; + for(int i=0;i=0;i--) + { + cout<>n; + factorial(n); + return 0; + +} + +Input: + +N = 100 + +Output: + +93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000 From 1c4042073e8a06a43a1f98c3ee7eaf4baab71e62 Mon Sep 17 00:00:00 2001 From: satyanarayan verma <52845970+snverma1409@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:24:00 +0530 Subject: [PATCH 251/781] Create Kotlin ASCCI Value of Character Kotlin ASCII value of a Character --- Kotlin ASCCI Value of Character | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Kotlin ASCCI Value of Character diff --git a/Kotlin ASCCI Value of Character b/Kotlin ASCCI Value of Character new file mode 100644 index 00000000..7b99efbb --- /dev/null +++ b/Kotlin ASCCI Value of Character @@ -0,0 +1,10 @@ +Using Kotlin Language + +fun main(args: Array) { + val c = 'a' + val ascii = c.toInt() + println("The ASCII value of $c is: $ascii") +} + +Output +The ASCII Value of a is : 65 From 11f356824a2de87ede84e01e8049b2827c041e93 Mon Sep 17 00:00:00 2001 From: satyanarayan verma <52845970+snverma1409@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:30:55 +0530 Subject: [PATCH 252/781] Create BS in C++ Language Code for BS in C++ --- BS in C++ Language | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 BS in C++ Language diff --git a/BS in C++ Language b/BS in C++ Language new file mode 100644 index 00000000..03dc859c --- /dev/null +++ b/BS in C++ Language @@ -0,0 +1,42 @@ +// C++ program to implement recursive Binary Search +#include +using namespace std; + +// A recursive binary search function. It returns +// location of x in given array arr[l..r] is present, +// otherwise -1 +int binarySearch(int arr[], int l, int r, int x) +{ + if (r >= l) { + int mid = l + (r - l) / 2; + + // If the element is present at the middle + // itself + if (arr[mid] == x) + return mid; + + // If element is smaller than mid, then + // it can only be present in left subarray + if (arr[mid] > x) + return binarySearch(arr, l, mid - 1, x); + + // Else the element can only be present + // in right subarray + return binarySearch(arr, mid + 1, r, x); + } + + // We reach here when element is not + // present in array + return -1; +} + +int main(void) +{ + int arr[] = { 2, 3, 4, 10, 40 }; + int x = 10; + int n = sizeof(arr) / sizeof(arr[0]); + int result = binarySearch(arr, 0, n - 1, x); + (result == -1) ? cout << "Element is not present in array" + : cout << "Element is present at index " << result; + return 0; +} From 0bfdc3bf0e4a2ea965099c147db3e5fdb334c284 Mon Sep 17 00:00:00 2001 From: rbirkaur23 <64214931+rbirkaur23@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:33:07 +0530 Subject: [PATCH 253/781] Create factorial.py --- factorial.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 factorial.py diff --git a/factorial.py b/factorial.py new file mode 100644 index 00000000..07df8ef3 --- /dev/null +++ b/factorial.py @@ -0,0 +1,5 @@ +n=int(input("Enter number ")) +fact=1 +for i in range(1,n+1): + fact=fact*i +print("Factorial is ",fact) From 1fd91b9e9406accb17e5468cd573a33e3684e41d Mon Sep 17 00:00:00 2001 From: satyanarayan verma <52845970+snverma1409@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:35:44 +0530 Subject: [PATCH 254/781] Create C language program to find length of a string C language program to find the length of a string --- C language program to find length of a string | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 C language program to find length of a string diff --git a/C language program to find length of a string b/C language program to find length of a string new file mode 100644 index 00000000..c90dfe30 --- /dev/null +++ b/C language program to find length of a string @@ -0,0 +1,17 @@ +#include +#include + +int main() +{ + char Str[100]; + int Length; + + printf("\n Please Enter any String \n"); + gets (Str); + + Length = strlen(Str); + + printf("Length of a String = %d\n", Length); + + return 0; +} From 32c87d8cdf0a21fb3bf8ebcf809d172c557a8ec7 Mon Sep 17 00:00:00 2001 From: satyanarayan verma <52845970+snverma1409@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:42:28 +0530 Subject: [PATCH 255/781] Create C language program Fibonacci series C language program Fibonacci series --- C language program Fibonacci series | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 C language program Fibonacci series diff --git a/C language program Fibonacci series b/C language program Fibonacci series new file mode 100644 index 00000000..612791d3 --- /dev/null +++ b/C language program Fibonacci series @@ -0,0 +1,14 @@ +#include +int fib(int m){ +if(m==0||m==1) + return m; +else + return(fib(m-1)+fib(m-2)); +} +int main(){ + int n; + scanf("%d",&n); + int res=fib(n); + printf("%d",res); + return 0; + } From d974235721337f608ef8dc4236c86e66d1fc09d5 Mon Sep 17 00:00:00 2001 From: rbirkaur23 <64214931+rbirkaur23@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:43:46 +0530 Subject: [PATCH 256/781] Created fibonacci _series.py --- fibonacci_series.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 fibonacci_series.py diff --git a/fibonacci_series.py b/fibonacci_series.py new file mode 100644 index 00000000..fcc98ccb --- /dev/null +++ b/fibonacci_series.py @@ -0,0 +1,11 @@ +n=int(input("Enter limit : ")) +f=0 +s=1 +print(f,end=' ') +print(s,end=' ') +for i in range(1,limit-1): + t=f+s + print(t,end=' ') + f=s + s=t + From ebc2e7fcc52e98b76ab8ea6c659fff48da2b96c2 Mon Sep 17 00:00:00 2001 From: rbirkaur23 <64214931+rbirkaur23@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:50:05 +0530 Subject: [PATCH 257/781] Create arithmetic operations --- arithmetic operations | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 arithmetic operations diff --git a/arithmetic operations b/arithmetic operations new file mode 100644 index 00000000..2e394f66 --- /dev/null +++ b/arithmetic operations @@ -0,0 +1,14 @@ +a=int(input("Enter number 1 : ")) +b=int(input("Enter number 2 : ")) +s=a+b +m=a-b; +multi=a*b +div=a/b +mod=a%b +p=a//b +print("Sum : ",s) +print("Subtraction : ",m) +print("Multiplication : ",multi) +print("Division : ",div); +print("Modulus operator(gives remainder) : ",mod) +print("Floor division : ",p) From cdff55cb8c602a74a03ec12e985a892d235e0edf Mon Sep 17 00:00:00 2001 From: him-kaus <72623413+him-kaus@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:55:23 +0530 Subject: [PATCH 258/781] Create reverse an array. By this code, we can reverse an array. --- reverse an array. | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 reverse an array. diff --git a/reverse an array. b/reverse an array. new file mode 100644 index 00000000..53823671 --- /dev/null +++ b/reverse an array. @@ -0,0 +1,23 @@ +//reverse of an array +#include +int main() +{ + int a[5],i,j,t; + printf("enter 6 values"); + for(i=0;i<=4;i++) + { + scanf("%d",&a[i]); + } + for(i=0,j=4;i"); + for(i=0;i<=4;i++) + { + printf("%d\n",a[i]); + } + return 0; +} From 0f0534afc3d0bbfea335ce57e2257785bafd352c Mon Sep 17 00:00:00 2001 From: rbirkaur23 <64214931+rbirkaur23@users.noreply.github.com> Date: Fri, 16 Oct 2020 21:56:20 +0530 Subject: [PATCH 259/781] Create matrices_multiplication --- matrices_multiplication | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 matrices_multiplication diff --git a/matrices_multiplication b/matrices_multiplication new file mode 100644 index 00000000..5c5b8779 --- /dev/null +++ b/matrices_multiplication @@ -0,0 +1,16 @@ +A=[[2,3,4],[5,6,2],[1,2,1]] +print("First matrix:") +for x in A: + print(x) +B=[[1,1,2],[2,2,2],[4,0,2]] +print("Second matrix: ") +for x in B: + print(x) +Product=[[0,0,0],[0,0,0],[0,0,0]] +for i in range(len(A)): + for j in range(len(B[0])): + for k in range(len(B)): + Product[i][j]+=A[i][k]*B[k][j] +print("Product of two matrices: ") +for x in Product: + print(x) From bff83f022425d6106ed61a56067f6b43e3c38098 Mon Sep 17 00:00:00 2001 From: StutiSingh876 <71888966+StutiSingh876@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:00:07 +0530 Subject: [PATCH 260/781] Create Python program to find Area of triangle In this program, area of the triangle is calculated when three sides are given using Heron's formula. --- Python program to find Area of triangle | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Python program to find Area of triangle diff --git a/Python program to find Area of triangle b/Python program to find Area of triangle new file mode 100644 index 00000000..800dfba3 --- /dev/null +++ b/Python program to find Area of triangle @@ -0,0 +1,12 @@ +# Python Program to find the area of triangle + +a = float(input('Enter first side: ')) +b = float(input('Enter second side: ')) +c = float(input('Enter third side: ')) + +# calculate the semi-perimeter +s = (a + b + c) / 2 + +# calculate the area +area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 +print('The area of the triangle is %0.2f' %area) From b42afffc20b22cf9017bc4829d69c06c35578b76 Mon Sep 17 00:00:00 2001 From: Tarun <53346586+Tarun0047@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:01:14 +0530 Subject: [PATCH 261/781] Added 0/1 Knapsack Problem C++ --- 01knapsack(A.V).cpp | 124 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 01knapsack(A.V).cpp diff --git a/01knapsack(A.V).cpp b/01knapsack(A.V).cpp new file mode 100644 index 00000000..ada47d6a --- /dev/null +++ b/01knapsack(A.V).cpp @@ -0,0 +1,124 @@ +#include +using namespace std; + +int max(int a, int b) +{ + return (a > b) ? a : b; +} +int knapsack(int wt[], int val[], int W, int N, int** tb) + { + if(N<=0 || W==0) + { + return 0; + } + if(tb[N][W]!=-1) + { //Memoization + return tb[N][W]; + } + + if(wt[N-1]<=W) + { + return tb[N][W]=max(val[N-1] + knapsack(wt, val, W-wt[N-1],N-1, tb), knapsack(wt, val, W, N-1, tb)); + } + else if(wt[N-1]>W) + { + return tb[N][W]=knapsack(wt, val, W, N-1, tb); + } + } + int knapSackR(int W, int wt[], int val[], int n) + { + // double pointer to declare the + // table dynamically + int** dp; + dp = new int*[n]; + + // loop to create the table dynamically + for (int i = 0; i < n; i++) + dp[i] = new int[W + 1]; + + // loop to initially filled the + // table with -1 + for (int i = 0; i < n; i++) + for (int j = 0; j < W + 1; j++) + dp[i][j] = -1; + return knapsack(wt, val, W, n, dp); +} +int main(){ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + int t,N,W,x; + cin>>t; //t=[1,100] + while(t--) + { + cin>>N; //N=[1,1000] + cin>>W; //W=[1,1000] + int wt[W]; //wt[i]=[1,1000] + int val[N]; //val[i]=[1,1000] + + for (int i = 0; i >x; + val[i]=x; + } + + for (int i = 0; i >x; + wt[i]=x; + } + int n = sizeof(val) / sizeof(val[0]); + cout << knapSackR(W, wt, val, n); + } + } + + //top down approach + #include +using namespace std; + + +void knap(int n, int w, int val[],int weight[]) +{ + int t[n+1][w+1]; + + + //fill 0th rows and coloumns with zero. + for(int i=0;i<=n;i++) + t[i][0]=0; + + for(int j=0;j<=w;j++) + t[0][j]=0; + + + for(int i=1;i<=n;i++) + { + for(int j=1;j<=w;j++) + { + if(j>y; +while(y--) +{ int n; cin>>n; + int w; cin>>w; + int val[n];int weight[n]; + + for(int i=1;i<=n;i++) + cin>>val[i]; + + for(int i=1;i<=n;i++) + cin>>weight[i]; + + knap(n,w,val,weight); + +} +return 0; +} \ No newline at end of file From 677f3e321a8eaaac371dd2deb8623ec72a554da4 Mon Sep 17 00:00:00 2001 From: StutiSingh876 <71888966+StutiSingh876@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:03:41 +0530 Subject: [PATCH 262/781] Create Python program to find Simple Instrest Algorithm:- 1. Take in the values for principle amount, rate and time. 2. Using the formula, compute the simple interest. 3. Print the value for the computed interest. 4. Exit. --- Python program to find Simple Instrest | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Python program to find Simple Instrest diff --git a/Python program to find Simple Instrest b/Python program to find Simple Instrest new file mode 100644 index 00000000..f31a1ad2 --- /dev/null +++ b/Python program to find Simple Instrest @@ -0,0 +1,5 @@ +principle=float(input("Enter the principle amount:")) +time=int(input("Enter the time(years):")) +rate=float(input("Enter the rate:")) +simple_interest=(principle*time*rate)/100 +print("The simple interest is:",simple_interest) From 6329b3d7cb4dae179b8ef4878da2d3cc16b95377 Mon Sep 17 00:00:00 2001 From: StutiSingh876 <71888966+StutiSingh876@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:05:57 +0530 Subject: [PATCH 263/781] Create Python program to find Compound Interest The below formula is used to find compound interest : A = P (1 + R/(100 * n))^nt Here, A = The final amount i.e. intial amount + compound interest P = Principal amount or initial amount R = The yearly rate of interest n = Number of compounding periods yearly t = Number of years --- Python program to find Compound Interest | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Python program to find Compound Interest diff --git a/Python program to find Compound Interest b/Python program to find Compound Interest new file mode 100644 index 00000000..db53bcc6 --- /dev/null +++ b/Python program to find Compound Interest @@ -0,0 +1,13 @@ +def findCompoundInterest(P, R, t, n): + return P * pow((1 + R/(100 * n)), n*t); + + +P = float(input("Enter principal amount : ")) +R = float(input("Enter annual rate of interest : ")) +t = float(input("Enter time in years : ")) +n = float(input("Enter number of compounding periods per year : ")) + +A = findCompoundInterest(P,R,t,n) + +print("Total amount : {}".format(A)) +print("Compound interest : {}".format(A-P)) From e56205475aad6baef233b7cb3ca9237407a04bb3 Mon Sep 17 00:00:00 2001 From: StutiSingh876 <71888966+StutiSingh876@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:09:43 +0530 Subject: [PATCH 264/781] Create Pattern printing Equilateral Triangle Printing equilateral triangle using star. --- Pattern printing Equilateral Triangle | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Pattern printing Equilateral Triangle diff --git a/Pattern printing Equilateral Triangle b/Pattern printing Equilateral Triangle new file mode 100644 index 00000000..9deda316 --- /dev/null +++ b/Pattern printing Equilateral Triangle @@ -0,0 +1,11 @@ +print("Print equilateral triangle Pyramid using stars ") +size = 7 +m = (2 * size) - 2 +for i in range(0, size): + for j in range(0, m): + print(end=" ") + m = m - 1 # decrementing m after each loop + for j in range(0, i + 1): + # printing full Triangle pyramid using stars + print("* ", end=' ') + print(" ") From 30e461e15f14d82ad59e255ae8890be9f6125b36 Mon Sep 17 00:00:00 2001 From: rbirkaur23 <64214931+rbirkaur23@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:13:03 +0530 Subject: [PATCH 265/781] Create Program to find the power of any number --- Program to find the power of any number | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Program to find the power of any number diff --git a/Program to find the power of any number b/Program to find the power of any number new file mode 100644 index 00000000..a18f4f09 --- /dev/null +++ b/Program to find the power of any number @@ -0,0 +1,6 @@ +n=int(input("Enter number : ")) +exp=int(input("Enter power : ")) +ans=1 +for i in range(1,exp+1): + ans=ans*n +print("Value of ",n," raised to the power ",exp," is ",ans) From 68318903843180c9145ce8521efe0f546c6900ca Mon Sep 17 00:00:00 2001 From: Deep santani Date: Fri, 16 Oct 2020 22:16:55 +0530 Subject: [PATCH 266/781] Program to count sum of all numbers --- Program to count sum of all numbers in array_using_python | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Program to count sum of all numbers in array_using_python diff --git a/Program to count sum of all numbers in array_using_python b/Program to count sum of all numbers in array_using_python new file mode 100644 index 00000000..b513638d --- /dev/null +++ b/Program to count sum of all numbers in array_using_python @@ -0,0 +1,7 @@ +def _sum(arr,n): + return(sum(arr)) +arr=[] +arr = [12, 3, 4, 15] +n = len(arr) +ans = _sum(arr,n) +print ('Sum of the array is ',ans) From b2284cdbed1bb7045aa44ca42353b64adbb83ea7 Mon Sep 17 00:00:00 2001 From: shefalichaurasia11 <49951388+shefalichaurasia11@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:26:15 +0530 Subject: [PATCH 267/781] Create Factorial of number Optimized code for factorial of number quickly in python. --- Factorial of number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Factorial of number diff --git a/Factorial of number b/Factorial of number new file mode 100644 index 00000000..8d3bafcd --- /dev/null +++ b/Factorial of number @@ -0,0 +1,14 @@ +# change the value for a different result +num = 9 + +factorial = 3 + +# check if the number is negative, positive or zero +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(3,num + 3): + factorial = factorial*i + print("The factorial of",num,"is",factorial) From 0a3c28a4d452b081b8c4b2c47c7fdb3bad724fe5 Mon Sep 17 00:00:00 2001 From: him-kaus <72623413+him-kaus@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:33:05 +0530 Subject: [PATCH 268/781] Create Program to reverse the array. program to reverse the array. --- Program to reverse the array. | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Program to reverse the array. diff --git a/Program to reverse the array. b/Program to reverse the array. new file mode 100644 index 00000000..53823671 --- /dev/null +++ b/Program to reverse the array. @@ -0,0 +1,23 @@ +//reverse of an array +#include +int main() +{ + int a[5],i,j,t; + printf("enter 6 values"); + for(i=0;i<=4;i++) + { + scanf("%d",&a[i]); + } + for(i=0,j=4;i"); + for(i=0;i<=4;i++) + { + printf("%d\n",a[i]); + } + return 0; +} From ba24bfed141a764e58f862d2297c1e2242f9c185 Mon Sep 17 00:00:00 2001 From: shefalichaurasia11 <49951388+shefalichaurasia11@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:35:45 +0530 Subject: [PATCH 269/781] Create Fibonacci Series python Optimized code for Fibonacci series in python. --- Fibonacci Series python | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Fibonacci Series python diff --git a/Fibonacci Series python b/Fibonacci Series python new file mode 100644 index 00000000..5bfb2a79 --- /dev/null +++ b/Fibonacci Series python @@ -0,0 +1,20 @@ +jterms = int(input("How many terms? ")) + +# first two terms +j1, j2 = 0, 1 +count = 0 + +if jterms <= 0: + print("Please enter a positive integer") +elif jterms == 1: + print("Fibonacci sequence upto",jterms,":") + print(j1) +else: + print("Fibonacci sequence:") + while count < jterms: + print(j1) + jth = j1 + j2 + # update values + j1 = j2 + j2 = jth + count += 1 From c1ec2caa2459206f742abb255e11423296577045 Mon Sep 17 00:00:00 2001 From: Mansi-1120 <71720551+Mansi-1120@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:39:07 +0530 Subject: [PATCH 270/781] Create Program to multiply 2D or 3D Matrices in c Pls marge it --- Program to multiply 2D or 3D Matrices in c | 100 +++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 Program to multiply 2D or 3D Matrices in c diff --git a/Program to multiply 2D or 3D Matrices in c b/Program to multiply 2D or 3D Matrices in c new file mode 100644 index 00000000..2bc95559 --- /dev/null +++ b/Program to multiply 2D or 3D Matrices in c @@ -0,0 +1,100 @@ +programming topics: + +C Arrays +C Multidimensional Arrays +This program asks the user to enter the size (rows and columns) of two matrices. + +To multiply two matrices, the number of columns of the first matrix should be equal to the number of rows of the second matrix. + +The program below asks for the number of rows and columns of two matrices until the above condition is satisfied. + +Then, the multiplication of two matrices is performed, and the result is displayed on the screen. + +To perform this, we have created three functions: + +getMatrixElements() - to take matrix elements input from the user. +multiplyMatrices() - to multiply two matrices. +display() - to display the resultant matrix after multiplication. +Multiply Matrices by Passing it to a Function +#include + +// function to get matrix elements entered by the user +void getMatrixElements(int matrix[][10], int row, int column) { + + printf("\nEnter elements: \n"); + + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("Enter a%d%d: ", i + 1, j + 1); + scanf("%d", &matrix[i][j]); + } + } +} + +// function to multiply two matrices +void multiplyMatrices(int first[][10], + int second[][10], + int result[][10], + int r1, int c1, int r2, int c2) { + + // Initializing elements of matrix mult to 0. + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + result[i][j] = 0; + } + } + + // Multiplying first and second matrices and storing it in result + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + for (int k = 0; k < c1; ++k) { + result[i][j] += first[i][k] * second[k][j]; + } + } + } +} + +// function to display the matrix +void display(int result[][10], int row, int column) { + + printf("\nOutput Matrix:\n"); + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("%d ", result[i][j]); + if (j == column - 1) + printf("\n"); + } + } +} + +int main() { + int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2; + printf("Enter rows and column for the first matrix: "); + scanf("%d %d", &r1, &c1); + printf("Enter rows and column for the second matrix: "); + scanf("%d %d", &r2, &c2); + + // Taking input until + // 1st matrix columns is not equal to 2nd matrix row + while (c1 != r2) { + printf("Error! Enter rows and columns again.\n"); + printf("Enter rows and columns for the first matrix: "); + scanf("%d%d", &r1, &c1); + printf("Enter rows and columns for the second matrix: "); + scanf("%d%d", &r2, &c2); + } + + // get elements of the first matrix + getMatrixElements(first, r1, c1); + + // get elements of the second matrix + getMatrixElements(second, r2, c2); + + // multiply two matrices. + multiplyMatrices(first, second, result, r1, c1, r2, c2); + + // display the result + display(result, r1, c2); + + return 0; +} From d83ddd54ee2afb5e4f6e1185929a1a35f5e6331a Mon Sep 17 00:00:00 2001 From: Mansi-1120 <71720551+Mansi-1120@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:45:59 +0530 Subject: [PATCH 271/781] Create Program to find lenght of a string in c Pls accept it --- Program to find lenght of a string in c | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program to find lenght of a string in c diff --git a/Program to find lenght of a string in c b/Program to find lenght of a string in c new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/Program to find lenght of a string in c @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 0f60e878f954b4ba7e821987a0fe5d543da95589 Mon Sep 17 00:00:00 2001 From: Mansi-1120 <71720551+Mansi-1120@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:49:05 +0530 Subject: [PATCH 272/781] Create Program to add 2D or 3D Matrices in c Pls accept it --- Program to add 2D or 3D Matrices in c | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Program to add 2D or 3D Matrices in c diff --git a/Program to add 2D or 3D Matrices in c b/Program to add 2D or 3D Matrices in c new file mode 100644 index 00000000..136681df --- /dev/null +++ b/Program to add 2D or 3D Matrices in c @@ -0,0 +1,40 @@ +#include +int main() { + int r, c, a[100][100], b[100][100], sum[100][100], i, j; + printf("Enter the number of rows (between 1 and 100): "); + scanf("%d", &r); + printf("Enter the number of columns (between 1 and 100): "); + scanf("%d", &c); + + printf("\nEnter elements of 1st matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &a[i][j]); + } + + printf("Enter elements of 2nd matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &b[i][j]); + } + + // adding two matrices + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + sum[i][j] = a[i][j] + b[i][j]; + } + + // printing the result + printf("\nSum of two matrices: \n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("%d ", sum[i][j]); + if (j == c - 1) { + printf("\n\n"); + } + } + + return 0; +} From 0541353b5998a15e4bfbaab63f6cf8779e273079 Mon Sep 17 00:00:00 2001 From: shefalichaurasia11 <49951388+shefalichaurasia11@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:57:03 +0530 Subject: [PATCH 273/781] Create Calculate power of number Optimized code for calculate the power of number in python. --- Calculate power of number | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Calculate power of number diff --git a/Calculate power of number b/Calculate power of number new file mode 100644 index 00000000..59f8573c --- /dev/null +++ b/Calculate power of number @@ -0,0 +1,7 @@ +import math + +base_number = float(input("Enter the base number")) +exponent = float(input("Enter the exponent")) + +power = math.pow(base_number,exponent) +print("Power is =",power) From d5e3177fcddd53b2e0dcb31d479774fe9c3fc371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davi=20Lu=C3=ADs?= <44652121+davizardb@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:29:02 -0300 Subject: [PATCH 274/781] Create diceRolle.js Enter x times that the dice will roll with y sided dice --- diceRoller.js | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 diceRoller.js diff --git a/diceRoller.js b/diceRoller.js new file mode 100644 index 00000000..eb8abd04 --- /dev/null +++ b/diceRoller.js @@ -0,0 +1,9 @@ +const diceRoller = (x,y) =>{ + + const aux = []; + for (var i = 0; i < x; i++){ + aux.push(Math.floor((Math.random() * y)+1)); + } + console.log(aux); +} + diceRoller(4,20); From 9a18bf5cc93ae03dc087fad8f8ee9335826b1e24 Mon Sep 17 00:00:00 2001 From: Mansi-1120 <71720551+Mansi-1120@users.noreply.github.com> Date: Fri, 16 Oct 2020 22:59:51 +0530 Subject: [PATCH 275/781] Create Program to print prime numbers in given range in c Pls accept it --- ...to print prime numbers in given range in c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Program to print prime numbers in given range in c diff --git a/Program to print prime numbers in given range in c b/Program to print prime numbers in given range in c new file mode 100644 index 00000000..0dec61ad --- /dev/null +++ b/Program to print prime numbers in given range in c @@ -0,0 +1,30 @@ +#include +int main() +{ + int num1, num2, flag_var, i, j; + + /* Ask user to input the from/to range + * like 1 to 100, 10 to 1000 etc. + */ + printf("Enter two range(input integer numbers only):"); + //Store the range in variables using scanf + scanf("%d %d", &num1, &num2); + + //Display prime numbers for input range + printf("Prime numbers from %d and %d are:\n", num1, num2); + for(i=num1+1; i Date: Fri, 16 Oct 2020 23:05:41 +0530 Subject: [PATCH 276/781] Create ExecutionTimeInsertionSort.c --- ExecutionTimeInsertionSort.c | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 ExecutionTimeInsertionSort.c diff --git a/ExecutionTimeInsertionSort.c b/ExecutionTimeInsertionSort.c new file mode 100644 index 00000000..717831c4 --- /dev/null +++ b/ExecutionTimeInsertionSort.c @@ -0,0 +1,46 @@ +// Insertion Sort with Execution Time in C + +#include +#include +#include + +void insertionSort(int arr[], int n) +{ + int i, key, j; + for (i = 1; i < n; i++) { + key = arr[i]; + j = i - 1; + while (j >= 0 && arr[j] > key) { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; + } +} + +void printArray(int arr[], int n) +{ + int i; + for (i = 0; i < n; i++) + printf("%d ", arr[i]); + printf("\n"); +} + +int main() +{ + clock_t start,end; + double cpu_time_used; + + int arr[] = { 99,40,67,33,2 }; + printf("Old Array:- 99 40 67 33 2\n"); + int n = sizeof(arr) / sizeof(arr[0]); + start = clock(); + insertionSort(arr, n); + printf("Sorted Array:- "); + printArray(arr, n); + end = clock(); + cpu_time_used = ((double)(end - start))/CLOCKS_PER_SEC; + printf("Execution Time:- %lf",cpu_time_used); + + return 0; +} From a6c5cb1adbc81961ae28fc606a5df881118c97ed Mon Sep 17 00:00:00 2001 From: shefalichaurasia11 <49951388+shefalichaurasia11@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:09:29 +0530 Subject: [PATCH 277/781] Create All arithmetic operations Optimized code for all arithmetic operations in python. --- All arithmetic operations | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 All arithmetic operations diff --git a/All arithmetic operations b/All arithmetic operations new file mode 100644 index 00000000..2908bca7 --- /dev/null +++ b/All arithmetic operations @@ -0,0 +1,16 @@ +X = int(input('Enter First number: ')) +Y = int(input('Enter Second number ')) +add = X + Y +dif = X - Y +mul = X * Y +div = X / Y +floor_div = X // Y +power = X ** Y +modulus = X % Y +print('Sum of ',X ,'and' ,Y ,'is :',add) +print('Difference of ',X ,'and' ,Y ,'is :',dif) +print('Product of' ,X ,'and' ,Y ,'is :',mul) +print('Division of ',X ,'and' ,Y ,'is :',div) +print('Floor Division of ',X ,'and' ,Y ,'is :',floor_div) +print('Exponent of ',X ,'and' ,Y ,'is :',power) +print('Modulus of ',X ,'and' ,Y ,'is :',modulus) From 37b854433d413b0f1d0f9c7f1e3f525d32aca9c7 Mon Sep 17 00:00:00 2001 From: Filza zarin <66674556+Filzazarin@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:11:00 +0530 Subject: [PATCH 278/781] Create Program of queue in c Optimized program of queue in c --- Program of queue in c | 87 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 Program of queue in c diff --git a/Program of queue in c b/Program of queue in c new file mode 100644 index 00000000..0e5b66d8 --- /dev/null +++ b/Program of queue in c @@ -0,0 +1,87 @@ +#include +#include +struct queue +{ + int no; + struct queue *next; +}; +typedef struct queue q; +q*front=NULL,*rear=NULL; +void enque(); +void dequeue(); +void traverse(); +void main() +{ + int ch; + do{ + printf("\nPress 0 to close"); + printf("\nPress 1 to Add Element"); + printf("\nPress 2 to traverse elements"); + printf("\nPress 3 to remove "); + printf("\nEnter your choice"); + scanf("%d",&ch); + if(ch==1) + enque(); + else if (ch==2) + traverse(); + else if(ch==3) + break; + else + printf("Invalid choice"); + + + + }while(ch!=0); + +} +void enque() +{ + q*node; + node=(struct queue*)malloc(sizeof(struct queue)); + printf("Enter Number"); + scanf("%d",&node->no); + node->next=NULL; + if(front==NULL) + { + front=node; + rear=node; + + } + else{ + rear->next=node; + rear=node; + + } +} +void traverse() +{ + q *t; + if(rear==NULL) + printf("No element is in queue"); + else + { + for(t=front;t!=NULL;t=t->next) + { + printf("%d\n",t->no); + } +} +} +void dequeue() +{ + q*t; + if(front==NULL) + printf("No element in queue"); + else + { + t=front; + front=front->next; + free(t); + printf("\nElement is removed successfully"); + if(front==rear) + { + front==NULL; + rear==NULL; + } + } +} + From d5e48f0364539eaabb075a5b70b6e6f80362c0cd Mon Sep 17 00:00:00 2001 From: shreya924 <72240945+shreya924@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:12:05 +0530 Subject: [PATCH 279/781] Create factorial.py --- factorial1.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 factorial1.py diff --git a/factorial1.py b/factorial1.py new file mode 100644 index 00000000..9c436024 --- /dev/null +++ b/factorial1.py @@ -0,0 +1,10 @@ +num = int(input("Enter a number: ")) +factorial = 1 +if num < 0: + print("Error!!") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(1,num + 1): + factorial = factorial*i + print("The factorial of",num,"is",factorial) From f35940e42251bfeecbdd2286b02d77a1e8a02e99 Mon Sep 17 00:00:00 2001 From: yashprasad8 <71018659+yashprasad8@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:12:29 +0530 Subject: [PATCH 280/781] Create Python program for factorial Python program for factorial of a number --- Python program for factorial | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Python program for factorial diff --git a/Python program for factorial b/Python program for factorial new file mode 100644 index 00000000..3ffad650 --- /dev/null +++ b/Python program for factorial @@ -0,0 +1,19 @@ +# Python program to find the factorial of a number provided by the user. + + +num = 7 + +# To take input from the user +num = int(input("Enter a number: ")) + +factorial = 1 + +# check if the number is negative, positive or zero +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(1,num + 1): + factorial = factorial*i + print("The factorial of",num,"is",factorial) From 52e0eab36f83d780fb828265dce6ea145ef3f773 Mon Sep 17 00:00:00 2001 From: shreya924 <72240945+shreya924@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:14:01 +0530 Subject: [PATCH 281/781] Create LinkedList.c --- LinkedList.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 LinkedList.c diff --git a/LinkedList.c b/LinkedList.c new file mode 100644 index 00000000..34427a82 --- /dev/null +++ b/LinkedList.c @@ -0,0 +1,39 @@ +struct Node +{ + int data; + struct Node *next; +}; +void push(struct Node** head_ref, int new_data) +{ + struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); + new_node->data = new_data; + new_node->next = (*head_ref); + (*head_ref) = new_node; +} +void deleteNode(struct Node **head_ref, int position) +{ + if (*head_ref == NULL) + return; + struct Node* temp = *head_ref; + if (position == 0) + { + *head_ref = temp->next; + free(temp); + return; + } + for (int i=0; temp!=NULL && inext; + if (temp == NULL || temp->next == NULL) + return; + struct Node *next = temp->next->next; + free(temp->next); + temp->next = next; +} +void printList(struct Node *node) +{ + while (node != NULL) + { + printf(" %d ", node->data); + node = node->next; + } +} From 79564bebc57102278f42fa41d59d317ba80242e4 Mon Sep 17 00:00:00 2001 From: shreya924 <72240945+shreya924@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:15:50 +0530 Subject: [PATCH 282/781] Create bin_to_dec.cpp --- bin_to_dec.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 bin_to_dec.cpp diff --git a/bin_to_dec.cpp b/bin_to_dec.cpp new file mode 100644 index 00000000..a1c55f6d --- /dev/null +++ b/bin_to_dec.cpp @@ -0,0 +1,24 @@ +#include +using namespace std; +void BinaryToDecimal(int n) +{ + int decimal = 0; + int base = 1; + int temp = n; + while (temp) + { + int lastDigit = temp % 10; + temp = temp/10; + decimal += lastDigit*base; + base = base*2; + } + cout<<"Decimal conversion of "<>m; + BinaryToDecimal(m); + return 0; +} From 57892d0b23ffae50227551b3b8143410c31fb04a Mon Sep 17 00:00:00 2001 From: Ethan Wentworth <43764998+AwesomeSamIAm@users.noreply.github.com> Date: Fri, 16 Oct 2020 10:56:51 -0700 Subject: [PATCH 283/781] Create LeapYear.py A function that will find the current/future leap year that will work for the next 8 years. All it takes to fix is changing the dates in lines 5 and 7-8. --- LeapYear.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 LeapYear.py diff --git a/LeapYear.py b/LeapYear.py new file mode 100644 index 00000000..77f6a496 --- /dev/null +++ b/LeapYear.py @@ -0,0 +1,16 @@ +from datetime import date +today = date.today + +repeat = input("How many leap years do you want: ") +leapyear = 2020 +current_date = date.today() +if current_date.year != 2020: + leapyear = 2024 + +while (not repeat.isdigit() or (int(repeat) == 0)): + repeat = input("Error. Enter a number for how many leap years: ") + +print(leapyear) +for x in range (int(repeat)-1): + leapyear = leapyear + 4 + print(leapyear) From cd274d6afda0eba33134e171b9c0b63af4685d6b Mon Sep 17 00:00:00 2001 From: Rahul Roy <64432712+Roy0Anonymous@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:39:20 +0530 Subject: [PATCH 284/781] Create GuessingGame.cpp --- GuessingGame.cpp | 103 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 GuessingGame.cpp diff --git a/GuessingGame.cpp b/GuessingGame.cpp new file mode 100644 index 00000000..2a52a566 --- /dev/null +++ b/GuessingGame.cpp @@ -0,0 +1,103 @@ +#include +#include +#include +#include + +void play_game(int n) +{ + int random; + if(n==1) + random = rand() % 500; + else if(n==2) + random = rand() % 1000; + else + random = rand() % 10000; + int try1 = 10; + std::cout<> guess; + if(guess==random) + { + if(n==1) + { + std::cout << "\nಠ︵ಠ: HOW DARE YOU BEAT ME!! MY DAD WILL SEE YOU IN THE NEXT ROUND..\n"; + play_game(2); + } + else if(n==2) + { + std::cout << "\n༎ຶ ෴ ༎ຶ: AND I'LL BE GONE, GONE TONIGHT. THE GROUND BENEATH MY FEET IS OPEN WIDE. THE WAY THAT I BEEN HOLDIN' ON TOO TIGHT, WITH NOTHING IN BETWEEN... THE FINAL BOSS WILL SEE YOU SOON\n"; + play_game(3); + } + else + { + std::cout << "\n༼;´༎ຶ ۝ ༎ຶ༽: CONGRATULATIONS! I MEAN WHAT ELSE CAN I SAY? YOU BEAT THE GAME.\n" << "\n(ʘᴗʘ✿): NOICE\n"; + } + break; + } + else if (guessrandom-5) + std::cout << "(◕ᴗ◕✿): VERY CLOSE - Your Guess Is A Little Low\n"; + else + std::cout << "(◕ᴗ◕✿): Your Guess Is Too Low\n"; + std::cout << "tries left = " << try1--; + if(try1 < 0) + { + std::cout << "\n\nಠ‿ಠ: HAHA YOU LOST THE GAME\n"; + break; + } + else + std::cout << "\n\nTry again: "; + } + else + { + if(guess>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n"; + do + { + std::cout << "\n0. Quit" << std::endl << "1. start" << std::endl << "enter your choice: "; + std::cin >> choice; + switch (choice) + { + case 0: + std::cout << "(◕ᴗ◕✿): Thanks for playing\n"; + break; + case 1: + play_game(1); + break; + default: + std::cout << "\nwrong choice\n"; + break; + } + } + while(choice!=0); +} From fad4ccc10ee2bc0b1207b13be609b14ac202a153 Mon Sep 17 00:00:00 2001 From: shikhershukla <44021480+shikhershukla@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:43:20 +0530 Subject: [PATCH 285/781] Create NumberGuessingBinarySearch number guessing game that uses binary search algorithm --- NumberGuessingBinarySearch | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 NumberGuessingBinarySearch diff --git a/NumberGuessingBinarySearch b/NumberGuessingBinarySearch new file mode 100644 index 00000000..72f13e72 --- /dev/null +++ b/NumberGuessingBinarySearch @@ -0,0 +1,33 @@ +def guessNumber(startRange, endRange): + if startRange > endRange: + return True + mid = (startRange + endRange)//2 + print("Is the number is ", + mid, "?", end = " ") + user = input() + print(user) + if user == "Y" or user == "y": + print("Voila ! Successfully Guessed Number.") + return False + elif user == "N" or user == "n": + print("Actual number is greater than",mid, "?", end = " ") + user = input() + print(user) + if user == "Y" or user == "y": + return guessNumber(mid+1, endRange) + elif user == "N" or user == "n": + return guessNumber(startRange, mid-1) + else: + print("Invalid Input. Print 'Y'/'N'") + return guessNumber(startRange, endRange) + else: + print("Invalid Input. Print 'Y'/'N' ") + return guessNumber(startRange, endRange) +if __name__ == "__main__": + print("Number Guessing game in python") + startRange = 1 + endRange = 10 + print("Guess a number in range (1 to 10)") + out = guessNumber(startRange, endRange) + if out: + print("Bad Choices") From 8964e499832f8fe509b8920e685f9c664b8b4f89 Mon Sep 17 00:00:00 2001 From: 25zeeshan <64727067+25zeeshan@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:44:54 +0530 Subject: [PATCH 286/781] Create print all subsequence of a string Code for printing all subsequences of a string using recursion. --- print all subsequence of a string | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 print all subsequence of a string diff --git a/print all subsequence of a string b/print all subsequence of a string new file mode 100644 index 00000000..5a67bdff --- /dev/null +++ b/print all subsequence of a string @@ -0,0 +1,19 @@ +#include +using namespace std; + +void print_subs(string input, string output) { + if (input.length() == 0) { + cout << output << endl; + return; + } + + print_subs(input.substr(1), output); + print_subs(input.substr(1), output + input[0]); +} + +int main() { + string input; + cin >> input; + string output = ""; + print_subs(input, output); +} From 91bbb718d306464d7fe013f1921530410c69de90 Mon Sep 17 00:00:00 2001 From: Rahul Roy <64432712+Roy0Anonymous@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:53:11 +0530 Subject: [PATCH 287/781] Create MergeArray.cpp --- MergeArray.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 MergeArray.cpp diff --git a/MergeArray.cpp b/MergeArray.cpp new file mode 100644 index 00000000..a8d2f05c --- /dev/null +++ b/MergeArray.cpp @@ -0,0 +1,35 @@ +#include + +using namespace std; + +int *merge(int arr1[],int s1,int arr2[],int s2) +{ + int i,j,k; + i=j=k=0; + int *arr=new int[15]; + while(i Date: Sat, 17 Oct 2020 00:01:18 +0530 Subject: [PATCH 288/781] Create Selection sort in c --- Selection sort in c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Selection sort in c diff --git a/Selection sort in c b/Selection sort in c new file mode 100644 index 00000000..5af936d3 --- /dev/null +++ b/Selection sort in c @@ -0,0 +1,37 @@ +#include +void main(){ +void sw(int* , int* ); + int i,j,n,min,a[100]; + printf("enter number of elements"); + scanf("%d",&n); + printf("enter the elements"); + for (i = 0; i < n ; i++) + { + scanf("%d",&a[i]); + } + for ( i = 0; i < n ; i++) + { + min=i; + for ( j = i+1; j < n; j++) + { + if (a[j] Date: Sat, 17 Oct 2020 00:04:10 +0530 Subject: [PATCH 289/781] Create Binary_search in c --- Binary_search in c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Binary_search in c diff --git a/Binary_search in c b/Binary_search in c new file mode 100644 index 00000000..49eb580d --- /dev/null +++ b/Binary_search in c @@ -0,0 +1,37 @@ +#include +void main() +{ + int a[100],i,l,u,n,key,m; + printf("enter number of elements"); + scanf("%d",&n); + printf("enter the elements"); + for (i = 0; i < n ; i++) + { + scanf("%d",&a[i]); + } + printf("enter key value"); + scanf("%d",&key); + l=0; + u=n-1; + while (l<=u) + { + m=(l+u)/2; + if (a[m]==key) + { + printf("element found"); + break; + } + else if (a[m] Date: Sat, 17 Oct 2020 00:06:08 +0530 Subject: [PATCH 290/781] Create Linear_search in c --- Linear_search in c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Linear_search in c diff --git a/Linear_search in c b/Linear_search in c new file mode 100644 index 00000000..71f8e9f4 --- /dev/null +++ b/Linear_search in c @@ -0,0 +1,22 @@ +#include +void main(){ + int a[100],n,key,i; + printf("enter number of elements"); + scanf("%d",&n); + printf("enter the elements"); + for (i = 0; i < n ; i++) + { + scanf("%d",&a[i]); + } + printf("enter key value"); + scanf("%d",&key); + for (i = 0; i < n; i++) + { + + if (a[i]==key) + { + printf("element found at %d position",i+1); + } + } + +} From 1f5d29276e5859ceb7627a8348181e3da1f486be Mon Sep 17 00:00:00 2001 From: Akshith Vasa <55576223+akshith2426@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:06:45 +0530 Subject: [PATCH 291/781] Added Snake Game In C --- snake_game.c | 184 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 184 insertions(+) create mode 100644 snake_game.c diff --git a/snake_game.c b/snake_game.c new file mode 100644 index 00000000..2b556237 --- /dev/null +++ b/snake_game.c @@ -0,0 +1,184 @@ +#include +#include +#include +#include +#include +#include + +check(); +end(); +win(); +int m[500],n[500],con=20; +clock_t start,stop; + void main(void) +{ + +int gd=DETECT,gm,ch,maxx,maxy,x=13,y=14,p,q,spd=100; + +initgraph(&gd,&gm,"..\bgi"); + +setcolor(WHITE); +settextstyle(3,0,6); +outtextxy(200,2," SNAKE 2 "); +settextstyle(6,0,2); +outtextxy(20,80," Use Arrow Keys To Direct The Snake "); +outtextxy(20,140," Avoid The Head Of Snake Not To Hit Any Part Of Snake +"); +outtextxy(20,160," Pick The Beats Untill You Win The Game "); +outtextxy(20,200," Press 'Esc' Anytime To Exit "); +outtextxy(20,220," Press Any Key To Continue "); +ch=getch(); +if(ch==27) exit(0); +cleardevice(); +maxx=getmaxx(); +maxy=getmaxy(); + +randomize(); + +p=random(maxx); +int temp=p%13; +p=p-temp; +q=random(maxy); +temp=q%14; +q=q-temp; + + + + start=clock(); +int a=0,i=0,j,t; +while(1) +{ + + setcolor(WHITE); + setfillstyle(SOLID_FILL,con+5); + circle(p,q,5); + floodfill(p,q,WHITE); + + if( kbhit() ) + { + ch=getch(); if(ch==0) ch=getch(); + if(ch==72&& a!=2) a=1; + if(ch==80&& a!=1) a=2; + if(ch==75&& a!=4) a=3; + if(ch==77&& a!=3) a=4; + } + else + { + if(ch==27 + ) break; + } + + if(i<20){ + m[i]=x; + n[i]=y; + i++; + } + + if(i>=20) + + { + for(j=con;j>=0;j--){ + m[1+j]=m[j]; + n[1+j]=n[j]; + } + m[0]=x; + n[0]=y; + + setcolor(WHITE); + setfillstyle(SOLID_FILL,con); + circle(m[0],n[0],8); + floodfill(m[0],n[0],WHITE); + + setcolor(WHITE); + for(j=1;j=5) spd=spd-5; else spd=5; + if(con>490) win(); + p=random(maxx); temp=p%13; p=p-temp; + q=random(maxy); temp=q%14; q=q-temp; + } + if(a==1) y = y-14; if(y<0) { temp=maxy%14;y=maxy-temp;} + if(a==2) y = y+14; if(y>maxy) y=0; + if(a==3) x = x-13; if(x<0) { temp=maxx%13;x=maxx-temp;} + if(a==4) x = x+13; if(x>maxx) x=0; + if(a==0){ y = y+14 ; x=x+13; } + } + + } + + +check(){ + int a; + for(a=1;a Date: Sat, 17 Oct 2020 00:06:54 +0530 Subject: [PATCH 292/781] Create convert binarry number to decimel optimized code for binary to decimel --- convert binarry number to decimel | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 convert binarry number to decimel diff --git a/convert binarry number to decimel b/convert binarry number to decimel new file mode 100644 index 00000000..cc7b730b --- /dev/null +++ b/convert binarry number to decimel @@ -0,0 +1,35 @@ +// C++ program to convert binary to decimal +#include +using namespace std; + +// Function to convert binary to decimal +int binaryToDecimal(int n) +{ + int num = n; + int dec_value = 0; + + // Initializing base value to 1, i.e 2^0 + int base = 1; + + int temp = num; + while (temp) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base; + + base = base * 2; + } + + return dec_value; +} + +// Driver program to test above function +int main() +{ + int num; + cout<<"Enter the binary no. : "; + cin>>num; + + cout << binaryToDecimal(num) << endl; +} From 2fd976b64f60cf7b8eca8df3cffb4bb7057f1730 Mon Sep 17 00:00:00 2001 From: Faiqua Tahreen <72994459+Faiqua123@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:10:22 +0530 Subject: [PATCH 293/781] Create Binary search tree program in c++ optimized Binary search program in c++ --- Binary search tree program in c++ | 81 +++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Binary search tree program in c++ diff --git a/Binary search tree program in c++ b/Binary search tree program in c++ new file mode 100644 index 00000000..6adcd4b4 --- /dev/null +++ b/Binary search tree program in c++ @@ -0,0 +1,81 @@ +#include + +//variable to store maximum number of nodes +int complete_node=15; + +//Array to store the tree +char tree[]={'\0','D','A','F','E','B','R','T','G','Q','\0','\0','V','\0','J','L'}; + +int get_right_child(int index) +{ + + //node is not null + //and the result must lie within the number of nodes for a complete binary + if(tree[index]!='\0'&& ((2*index)+1)<=complete_node) + return(2*index)+1; + //right child doesn't exist + return -1; +} + int get_left_child(int index) + { + //node is not null + //and the result must lie within the number of nodes for a complete binary + if(tree[index]!='\0' && (2*index)<=complete_node) + return 2*index; + //left child doesn't exist + return -1; + } + + void preorder(int index) + { + + //checking for valid index and null node + if(index>0 && tree[index]!='\0') + { + printf("%c",tree[index]);//visiting root + preorder(get_left_child(index));//visitingleft subtree + preorder(get_right_child(index));//visiting right subtree + + } + + } + void postorder(int index) + { + //checking for void index and null node + if(index>0 && tree[index]!='\0') + { + + postorder(get_left_child(index));//visiting left subtree + postorder(get_right_child(index));//visiting right subtree + printf("%c",tree[index]);//visiting root + + } + } + void inorder(int index) + { + //checking for valid index and null node + if(index>0 && tree[index]!='\0') + { + + inorder(get_left_child(index));//visiting left subtree + printf("%c",tree[index]);//visiting root + inorder(get_right_child(index));//visiting right subtree + } + + } + + +int main() +{ + printf("Preorder:\n"); + preorder(1); + printf("\nPostorder:\n"); + postorder(1); + printf("\nInorder:\n"); + inorder(1); + printf("\n"); + return 0; +} + + + From 48c9db557b879de336da5b8f592a81954d4dc180 Mon Sep 17 00:00:00 2001 From: dev valecha <71969867+iamdevvalecha@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:14:32 +0530 Subject: [PATCH 294/781] Add files via upload kadane's algorithm --- kandale algo.txt | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 kandale algo.txt diff --git a/kandale algo.txt b/kandale algo.txt new file mode 100644 index 00000000..6d4fb7e3 --- /dev/null +++ b/kandale algo.txt @@ -0,0 +1,40 @@ +Lets take the example: + {-2, -3, 4, -1, -2, 1, 5, -3} + + max_so_far = max_ending_here = 0 + + for i=0, a[0] = -2 + max_ending_here = max_ending_here + (-2) + Set max_ending_here = 0 because max_ending_here < 0 + + for i=1, a[1] = -3 + max_ending_here = max_ending_here + (-3) + Set max_ending_here = 0 because max_ending_here < 0 + + for i=2, a[2] = 4 + max_ending_here = max_ending_here + (4) + max_ending_here = 4 + max_so_far is updated to 4 because max_ending_here greater + than max_so_far which was 0 till now + + for i=3, a[3] = -1 + max_ending_here = max_ending_here + (-1) + max_ending_here = 3 + + for i=4, a[4] = -2 + max_ending_here = max_ending_here + (-2) + max_ending_here = 1 + + for i=5, a[5] = 1 + max_ending_here = max_ending_here + (1) + max_ending_here = 2 + + for i=6, a[6] = 5 + max_ending_here = max_ending_here + (5) + max_ending_here = 7 + max_so_far is updated to 7 because max_ending_here is + greater than max_so_far + + for i=7, a[7] = -3 + max_ending_here = max_ending_here + (-3) + max_ending_here = 4 \ No newline at end of file From 0f0daf2b31a53923ba9449464d4f39205f50bf39 Mon Sep 17 00:00:00 2001 From: Tushar Singh <56396090+mr-sing@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:14:47 +0530 Subject: [PATCH 295/781] Create binary search in c++ --- binary search in c++ | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 binary search in c++ diff --git a/binary search in c++ b/binary search in c++ new file mode 100644 index 00000000..03dc859c --- /dev/null +++ b/binary search in c++ @@ -0,0 +1,42 @@ +// C++ program to implement recursive Binary Search +#include +using namespace std; + +// A recursive binary search function. It returns +// location of x in given array arr[l..r] is present, +// otherwise -1 +int binarySearch(int arr[], int l, int r, int x) +{ + if (r >= l) { + int mid = l + (r - l) / 2; + + // If the element is present at the middle + // itself + if (arr[mid] == x) + return mid; + + // If element is smaller than mid, then + // it can only be present in left subarray + if (arr[mid] > x) + return binarySearch(arr, l, mid - 1, x); + + // Else the element can only be present + // in right subarray + return binarySearch(arr, mid + 1, r, x); + } + + // We reach here when element is not + // present in array + return -1; +} + +int main(void) +{ + int arr[] = { 2, 3, 4, 10, 40 }; + int x = 10; + int n = sizeof(arr) / sizeof(arr[0]); + int result = binarySearch(arr, 0, n - 1, x); + (result == -1) ? cout << "Element is not present in array" + : cout << "Element is present at index " << result; + return 0; +} From db86a9fbc3d1dd485c912d10affa444e0794f54b Mon Sep 17 00:00:00 2001 From: Tushar Singh <56396090+mr-sing@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:16:45 +0530 Subject: [PATCH 296/781] Create c program to find lenght of text --- c program to find lenght of text | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 c program to find lenght of text diff --git a/c program to find lenght of text b/c program to find lenght of text new file mode 100644 index 00000000..c90dfe30 --- /dev/null +++ b/c program to find lenght of text @@ -0,0 +1,17 @@ +#include +#include + +int main() +{ + char Str[100]; + int Length; + + printf("\n Please Enter any String \n"); + gets (Str); + + Length = strlen(Str); + + printf("Length of a String = %d\n", Length); + + return 0; +} From 073cbfcfffbdbea186ff4e701618c823065a0548 Mon Sep 17 00:00:00 2001 From: Tushar Singh <56396090+mr-sing@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:18:03 +0530 Subject: [PATCH 297/781] Create power of a number in python --- power of a number in python | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 power of a number in python diff --git a/power of a number in python b/power of a number in python new file mode 100644 index 00000000..59f8573c --- /dev/null +++ b/power of a number in python @@ -0,0 +1,7 @@ +import math + +base_number = float(input("Enter the base number")) +exponent = float(input("Enter the exponent")) + +power = math.pow(base_number,exponent) +print("Power is =",power) From 8672d64db549b95c7c32148c67c7aae0e49dc956 Mon Sep 17 00:00:00 2001 From: Utkarsh1520 <72489678+Utkarsh1520@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:23:37 +0530 Subject: [PATCH 298/781] Create Arthematic.py --- Arthematic.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Arthematic.py diff --git a/Arthematic.py b/Arthematic.py new file mode 100644 index 00000000..44cdcc63 --- /dev/null +++ b/Arthematic.py @@ -0,0 +1,21 @@ +# Store input numbers: +num1 = input('Enter first number: ') +num2 = input('Enter second number: ') + +# Add two numbers +sum = float(num1) + float(num2) +# Subtract two numbers +min = float(num1) - float(num2) +# Multiply two numbers +mul = float(num1) * float(num2) +#Divide two numbers +div = float(num1) / float(num2) +# Display the sum +print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) + +# Display the subtraction +print('The subtraction of {0} and {1} is {2}'.format(num1, num2, min)) +# Display the multiplication +print('The multiplication of {0} and {1} is {2}'.format(num1, num2, mul)) +# Display the division +print('The division of {0} and {1} is {2}'.format(num1, num2, div)) From de5715019f662a0f3c472032c337f765bd898603 Mon Sep 17 00:00:00 2001 From: tavolafourcade <63257157+tavolafourcade@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:06:28 -0500 Subject: [PATCH 299/781] Create findFactorialNumber Find the factorial number on Javascript --- findFactorialNumber | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 findFactorialNumber diff --git a/findFactorialNumber b/findFactorialNumber new file mode 100644 index 00000000..6d7fb23b --- /dev/null +++ b/findFactorialNumber @@ -0,0 +1,20 @@ +function factorialNumber(num){ + + // If the number is less than 0, reject it. + if (num < 0) + return -1; + + else if (num==1) + return 1; + + else{ + return num * factorialNumber(num-1); + } + + +} + +// test = factorialNumber(10); +number = 10; +finalFactorial=factorialNumber(number); +console.log(finalFactorial); From 2a797b499c12aa8e1fcd35c07b0582491c548396 Mon Sep 17 00:00:00 2001 From: Saumya Bathla <51361448+saumyabathla@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:38:18 +0530 Subject: [PATCH 300/781] Create C++ program to reverse an array Code to reverse an array using iterative way. The time complexity of this program is O(n). --- C++ program to reverse an array | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 C++ program to reverse an array diff --git a/C++ program to reverse an array b/C++ program to reverse an array new file mode 100644 index 00000000..2b5eb6a6 --- /dev/null +++ b/C++ program to reverse an array @@ -0,0 +1,41 @@ +#include +using namespace std; + + +void rvereseArray(int arr[], int start, int end) +{ + while (start < end) + { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } +} + +void printArray(int arr[], int size) +{ + for (int i = 0; i < size; i++) + cout << arr[i] << " "; + + cout << endl; +} + + +int main() +{ + int arr[] = {1, 2, 3, 4, 5, 6}; + + int n = sizeof(arr) / sizeof(arr[0]); + + // To print original array + printArray(arr, n); + + // Function calling + rvereseArray(arr, 0, n-1); + + cout << "Reversed array is" << endl; + + // To print the Reversed array + printArray(arr, n); From 934f97b399e6c954f84eb766347e2c698fa566f2 Mon Sep 17 00:00:00 2001 From: Tushar Singh <56396090+mr-sing@users.noreply.github.com> Date: Sat, 17 Oct 2020 00:45:43 +0530 Subject: [PATCH 301/781] Create calculate aveg of array in c --- calculate aveg of array in c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 calculate aveg of array in c diff --git a/calculate aveg of array in c b/calculate aveg of array in c new file mode 100644 index 00000000..11d2e663 --- /dev/null +++ b/calculate aveg of array in c @@ -0,0 +1,24 @@ +#include +int main() { + int n, i; + float num[100], sum = 0.0, avg; + + printf("Enter the numbers of elements: "); + scanf("%d", &n); + + while (n > 100 || n < 1) { + printf("Error! number should in range of (1 to 100).\n"); + printf("Enter the number again: "); + scanf("%d", &n); + } + + for (i = 0; i < n; ++i) { + printf("%d. Enter number: ", i + 1); + scanf("%f", &num[i]); + sum += num[i]; + } + + avg = sum / n; + printf("Average = %.2f", avg); + return 0; +} From 75381973fe750bb05cfe84811802719c9450c6bd Mon Sep 17 00:00:00 2001 From: tavolafourcade <63257157+tavolafourcade@users.noreply.github.com> Date: Fri, 16 Oct 2020 14:58:18 -0500 Subject: [PATCH 302/781] Create findLasgestElementArray Find the largest element in an array using Javascript --- findLasgestElementArray | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 findLasgestElementArray diff --git a/findLasgestElementArray b/findLasgestElementArray new file mode 100644 index 00000000..3f77e5ff --- /dev/null +++ b/findLasgestElementArray @@ -0,0 +1,18 @@ +function maxValue(array){ + //console.log(array.length); + max = array[0]; + //console.log(max); + for (i=0; i max) { + max = array[i]; + } + + } + return max; +} + +//Testing +const array = [1,2,4,3,12,8,4,9]; +maxx= maxValue(array); +console.log(maxx); From f0c74f4985130e4f0b411dd114e3e4bfa41c72ea Mon Sep 17 00:00:00 2001 From: Reshmaselvaraj <64559017+Reshmaselvaraj@users.noreply.github.com> Date: Sat, 17 Oct 2020 01:34:50 +0530 Subject: [PATCH 303/781] Create Program To Check whether a Triangle is Equilateral, Isosceles or Scalene optimized program to check whether a Triangle is Equilateral, Isosceles or Scalene --- ...angle is Equilateral, Isosceles or Scalene | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Program To Check whether a Triangle is Equilateral, Isosceles or Scalene diff --git a/Program To Check whether a Triangle is Equilateral, Isosceles or Scalene b/Program To Check whether a Triangle is Equilateral, Isosceles or Scalene new file mode 100644 index 00000000..01843f7b --- /dev/null +++ b/Program To Check whether a Triangle is Equilateral, Isosceles or Scalene @@ -0,0 +1,28 @@ +# Python program + +# Function to check if the triangle +# is equilateral or isosceles or scalene +def checkTriangle(x, y, z): + + # _Check for equilateral triangle + if x == y == z: + print("Equilateral Triangle") + + # Check for isoceles triangle + elif x == y or y == z or z == x: + print("Isoceles Triangle") + + # Otherwise scalene triangle + else: + print("Scalene Triangle") + + +# Driver Code + +# Given sides of triangle +x = 8 +y = 7 +z = 9 + +# Function Call +checkTriangle(x, y, z) From d2acbe2a8b8e075ee4fce908e189f126e7d225fa Mon Sep 17 00:00:00 2001 From: tavolafourcade <63257157+tavolafourcade@users.noreply.github.com> Date: Fri, 16 Oct 2020 15:11:32 -0500 Subject: [PATCH 304/781] Create findSmallestElementArray Find the smallest number in an array using Javascript. --- findSmallestElementArray | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 findSmallestElementArray diff --git a/findSmallestElementArray b/findSmallestElementArray new file mode 100644 index 00000000..09517409 --- /dev/null +++ b/findSmallestElementArray @@ -0,0 +1,18 @@ +function minValue(array){ + //console.log(array.length); + min = array[0]; + //console.log(min); + for (i=0; i Date: Sat, 17 Oct 2020 01:46:12 +0530 Subject: [PATCH 305/781] Create Factorial_Python Optimized Code To Find Factorial. --- Factorial_Python | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Factorial_Python diff --git a/Factorial_Python b/Factorial_Python new file mode 100644 index 00000000..60d09f1a --- /dev/null +++ b/Factorial_Python @@ -0,0 +1,19 @@ +# Python program to find the factorial of a number provided by the user. + +# change the value for a different result +num = 7 + +# To take input from the user +#num = int(input("Enter a number: ")) + +factorial = 1 + +# check if the number is negative, positive or zero +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(1,num + 1): + factorial = factorial*i + print("The factorial of",num,"is",factorial) From e722a8d28f606b02b4ff88f7c43bb32280eac426 Mon Sep 17 00:00:00 2001 From: amitmandalhf <72998879+amitmandalhf@users.noreply.github.com> Date: Sat, 17 Oct 2020 01:47:32 +0530 Subject: [PATCH 306/781] Create Find the Largest Element in an array Optimized Code For Finding the Largest Element in an array --- Find the Largest Element in an array | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Find the Largest Element in an array diff --git a/Find the Largest Element in an array b/Find the Largest Element in an array new file mode 100644 index 00000000..98a77125 --- /dev/null +++ b/Find the Largest Element in an array @@ -0,0 +1,22 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + // storing the largest number to arr[0] + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From 90b4d807fcb4488f116319ddb4e40a19a14d4086 Mon Sep 17 00:00:00 2001 From: amitmandalhf <72998879+amitmandalhf@users.noreply.github.com> Date: Sat, 17 Oct 2020 01:54:44 +0530 Subject: [PATCH 307/781] Create Find the Largest Element in an array in C Lang Optimized Code For Find the Largest Element in an array in C Lang --- ... the Largest Element in an array in C Lang | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Find the Largest Element in an array in C Lang diff --git a/Find the Largest Element in an array in C Lang b/Find the Largest Element in an array in C Lang new file mode 100644 index 00000000..98a77125 --- /dev/null +++ b/Find the Largest Element in an array in C Lang @@ -0,0 +1,22 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + // storing the largest number to arr[0] + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From d005345d009e3998d8b5e24fec59137a94d1b9bc Mon Sep 17 00:00:00 2001 From: amitmandalhf <72998879+amitmandalhf@users.noreply.github.com> Date: Sat, 17 Oct 2020 01:57:35 +0530 Subject: [PATCH 308/781] Create Calculate Length of String without Using strlen() Function in C Lang Optimized Code For Calculate Length of String without Using strlen() Function in C Lang --- ...of String without Using strlen() Function in C Lang | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Calculate Length of String without Using strlen() Function in C Lang diff --git a/Calculate Length of String without Using strlen() Function in C Lang b/Calculate Length of String without Using strlen() Function in C Lang new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/Calculate Length of String without Using strlen() Function in C Lang @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From b1318180862f0243c448b65d4c9bc04b4b30877d Mon Sep 17 00:00:00 2001 From: Rohit Raj <43220855+r0hitraj@users.noreply.github.com> Date: Sat, 17 Oct 2020 01:58:46 +0530 Subject: [PATCH 309/781] Create Fibonaci_DP.cpp fibonacci series with dynamic programing --- Fibonnaci Series/Fibonaci_DP.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Fibonnaci Series/Fibonaci_DP.cpp diff --git a/Fibonnaci Series/Fibonaci_DP.cpp b/Fibonnaci Series/Fibonaci_DP.cpp new file mode 100644 index 00000000..408d1f58 --- /dev/null +++ b/Fibonnaci Series/Fibonaci_DP.cpp @@ -0,0 +1,22 @@ +#include +using namspace std; +vectorarr; +int main() +{ +long long int val; //upto which term +cin>>val; +arr.push_back(1); +arr.push_back(1); +for(long long int i=2;i<=val;i++;) +{ +arr.push_back(arr[i-1]+arr[i-2]); +} +for(long long int i=1;i<=val;i++;) +{ + cout<<" "< Date: Sat, 17 Oct 2020 02:00:54 +0530 Subject: [PATCH 310/781] Create find the sum of all element of array Optimized Code for C program to find sum of all elements of array --- find the sum of all element of array | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 find the sum of all element of array diff --git a/find the sum of all element of array b/find the sum of all element of array new file mode 100644 index 00000000..54f92e0b --- /dev/null +++ b/find the sum of all element of array @@ -0,0 +1,28 @@ +#include +#define MAX_SIZE 100 + +int main() +{ + int arr[MAX_SIZE]; + int i, n, sum=0; + + /*input size of the array*/ + printf("Enter size of the array: "); + scanf("%d", &n); + + /*input element in array*/ + printf("Enter %d element in the aray: ",n); + for(i=0; i Date: Fri, 16 Oct 2020 15:33:31 -0500 Subject: [PATCH 311/781] Create findStringLength Program to find the length of a word using javascript --- findStringLength | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 findStringLength diff --git a/findStringLength b/findStringLength new file mode 100644 index 00000000..717f85de --- /dev/null +++ b/findStringLength @@ -0,0 +1,9 @@ +function stringLength(string){ + + len = string.length; + console.log(len); +} + +//Testing +const string= "string"; +stringLength(string); From fa1114b8eb38b718d0e3e72f5e875bd6076aa75a Mon Sep 17 00:00:00 2001 From: Qh3xg3m Date: Sat, 17 Oct 2020 03:34:42 +0700 Subject: [PATCH 312/781] Create xepdiem.py --- xepdiem.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 xepdiem.py diff --git a/xepdiem.py b/xepdiem.py new file mode 100644 index 00000000..5e8e02db --- /dev/null +++ b/xepdiem.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + + +definition = { + "0":6, + "1":2, + "2":5, + "3":5, + "4":4, + "5":5, + "6":6, + "7":3, + "8":7, + "9":6, + "+":2, + "-":1, + "=":2 +} + +bienThe = { + "0":[0,6,8,9], + "1":[1,7], + "2":[2,3], + "3":[2,3,5,9], + "4":[4], + "5":[3,5,6,9], + "6":[0,5,6,8,9], + "7":[1,7], + "8":[0,6,8,9], + "9":[0,3,5,6,8,9] +} + +def soDiem(data): + queDiem = 0 + for char in data: + if char in definition : + queDiem = queDiem + definition[char] + return(queDiem) + +def demKiTu(x): + number = [] + for i in data: + try: + if i in definition: + number.append(i) + except: + continue + return(number) + +def soSanh(a,b): + for i in a: + if i in b: + b.remove(i) + if len(b) in [1,2]: + return(True) + else: + return(False) + +print("\t\t\t","Author: Qh3xg3m") + +while True: + print() + data = str(input("\t> Input: ")) + output = [] + for i in bienThe[demKiTu(data)[0]]: + for j in bienThe[demKiTu(data)[2]]: + String = "{0} {1} {2} = {3}".format(i,"+",j,i+j) + if i+j in range(10): + output.append(String) + String = "{0} {1} {2} = {3}".format(i,"-",j,i-j) + if i-j in range(10): + output.append(String) + for i in output: + temp = i.split(" ") + if soDiem(data)==soDiem(i) and soSanh(data,temp)==True: + print("\t",i) + else: + continue + From fd4c423d983e863edc22c8b0cc92a172235b3a06 Mon Sep 17 00:00:00 2001 From: Rohit Raj <43220855+r0hitraj@users.noreply.github.com> Date: Sat, 17 Oct 2020 02:05:04 +0530 Subject: [PATCH 313/781] Create factorial_dp.cpp factorial with dp and fast factorial --- factorial_dp.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 factorial_dp.cpp diff --git a/factorial_dp.cpp b/factorial_dp.cpp new file mode 100644 index 00000000..1298ea9d --- /dev/null +++ b/factorial_dp.cpp @@ -0,0 +1,20 @@ +#include +using namspace std; +vectorarr; +int main() +{ +long long int val; //upto which term +cin>>val; +arr.push_back(1); + +for(long long int i=1;i Date: Sat, 17 Oct 2020 02:09:37 +0530 Subject: [PATCH 314/781] Create Program to find factorial In C Language Code To Find The Factorial of a Number --- Program to find factorial In C Language | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program to find factorial In C Language diff --git a/Program to find factorial In C Language b/Program to find factorial In C Language new file mode 100644 index 00000000..07b09ea2 --- /dev/null +++ b/Program to find factorial In C Language @@ -0,0 +1,19 @@ +#include +int main() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows error if the user enters a negative integer + if (n < 0) + printf("Error! Factorial of a negative number doesn't exist."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + return 0; +} From d0c8947d7d2ce55da9bd16aecfe50257b8e0b103 Mon Sep 17 00:00:00 2001 From: sayanlodhab <72999636+sayanlodhab@users.noreply.github.com> Date: Sat, 17 Oct 2020 02:14:04 +0530 Subject: [PATCH 315/781] Create Program to find largest element in array In C_Lang Optimized Code To Find The largest Element In Array In C_lang --- ...to find largest element in array In C_Lang | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Program to find largest element in array In C_Lang diff --git a/Program to find largest element in array In C_Lang b/Program to find largest element in array In C_Lang new file mode 100644 index 00000000..98a77125 --- /dev/null +++ b/Program to find largest element in array In C_Lang @@ -0,0 +1,22 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + // storing the largest number to arr[0] + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From 9f8425e7dcf76dd776314c89af575047d491043d Mon Sep 17 00:00:00 2001 From: sayanlodhab <72999636+sayanlodhab@users.noreply.github.com> Date: Sat, 17 Oct 2020 02:17:02 +0530 Subject: [PATCH 316/781] Create Program to find smallest element in array In C_Lang I Created a Code to find smallest element in array --- ...o find smallest element in array In C_Lang | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Program to find smallest element in array In C_Lang diff --git a/Program to find smallest element in array In C_Lang b/Program to find smallest element in array In C_Lang new file mode 100644 index 00000000..fadd0c00 --- /dev/null +++ b/Program to find smallest element in array In C_Lang @@ -0,0 +1,26 @@ +#include + +int main() { + int a[30], i, num, smallest; + + printf("\nEnter no of elements :"); + scanf("%d", &num); + + //Read n elements in an array + for (i = 0; i < num; i++) + scanf("%d", &a[i]); + + //Consider first element as smallest + smallest = a[0]; + + for (i = 0; i < num; i++) { + if (a[i] < smallest) { + smallest = a[i]; + } + } + + // Print out the Result + printf("\nSmallest Element : %d", smallest); + + return (0); + } From 9f024acd8569e2a2ee84b85d8d5386ff3143d213 Mon Sep 17 00:00:00 2001 From: sayanlodhab <72999636+sayanlodhab@users.noreply.github.com> Date: Sat, 17 Oct 2020 02:20:28 +0530 Subject: [PATCH 317/781] Create Length Of the String In C_Lang I Created a Code To Find The Length Of the String --- Length Of the String In C_Lang | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Length Of the String In C_Lang diff --git a/Length Of the String In C_Lang b/Length Of the String In C_Lang new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/Length Of the String In C_Lang @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 7be2f76b99dad1af607c9ebf84f3acd8b63dcd5f Mon Sep 17 00:00:00 2001 From: pantnitiin99 <50806054+pantnitiin99@users.noreply.github.com> Date: Sat, 17 Oct 2020 03:17:28 +0530 Subject: [PATCH 318/781] Create Factorial of a given number This finds a factorial for a given number --- Factorial of a given number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Factorial of a given number diff --git a/Factorial of a given number b/Factorial of a given number new file mode 100644 index 00000000..f1426e56 --- /dev/null +++ b/Factorial of a given number @@ -0,0 +1,19 @@ +#include +using namespace std; + +int main() +{ + unsigned int input; + unsigned long long fact = 1; + + cout << "Enter a positive integer: "; + cin >> input; + + for(int i = 1; i <=n; ++i) + { + fact *= i; + } + + cout << "Factorial of " << input << " = " << fact; + return 0; +} From a0df7d184e90dfac86935079c55c4793b3d2007a Mon Sep 17 00:00:00 2001 From: DHRUV SHARMA <53833190+Dhruv1881@users.noreply.github.com> Date: Sat, 17 Oct 2020 03:21:26 +0530 Subject: [PATCH 319/781] Added the FizzBuzz Problem solution in cpp --- FizzBuzzProblem.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 FizzBuzzProblem.cpp diff --git a/FizzBuzzProblem.cpp b/FizzBuzzProblem.cpp new file mode 100644 index 00000000..29e06732 --- /dev/null +++ b/FizzBuzzProblem.cpp @@ -0,0 +1,23 @@ +#include +int main(void) +{ + int i; + for (i = 1; i <= 100; i++) + { + + if (i % 15 == 0) + printf ("FizzBuzz\t"); + + else if ((i % 3) == 0) + printf("Fizz\t"); + + else if ((i % 5) == 0) + printf("Buzz\t"); + + else + printf("%d\t", i); + + } + + return 0; +} From b05add8f9257c42c38de0938905a1a95c40a67f1 Mon Sep 17 00:00:00 2001 From: devil-py <73006951+devil-py@users.noreply.github.com> Date: Sat, 17 Oct 2020 07:53:05 +0530 Subject: [PATCH 320/781] Create Sum_of_AP_series --- Sum_of_AP_series | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Sum_of_AP_series diff --git a/Sum_of_AP_series b/Sum_of_AP_series new file mode 100644 index 00000000..cd92e8c7 --- /dev/null +++ b/Sum_of_AP_series @@ -0,0 +1,9 @@ +a = int(input("Please Enter First Number of an A.P Series: : ")) +n = int(input("Please Enter the Total Numbers in this A.P Series: : ")) +d = int(input("Please Enter the Common Difference : ")) + +total = (n * (2 * a + (n - 1) * d)) / 2 +tn = a + (n - 1) * d + +print("\nThe Sum of Arithmetic Progression Series = " , total) +print("The tn Term of Arithmetic Progression Series = " , tn) From 9389616b1ce2b72c0e5524055954558ee3f09dcb Mon Sep 17 00:00:00 2001 From: devil-py <73006951+devil-py@users.noreply.github.com> Date: Sat, 17 Oct 2020 07:54:51 +0530 Subject: [PATCH 321/781] Create Powe_of_a_number --- Powe_of_a_number | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Powe_of_a_number diff --git a/Powe_of_a_number b/Powe_of_a_number new file mode 100644 index 00000000..52a8a085 --- /dev/null +++ b/Powe_of_a_number @@ -0,0 +1,11 @@ +number = int(input(" Please Enter any Positive Integer : ")) +exponent = int(input(" Please Enter Exponent Value : ")) + +power = 1 +i = 1 + +while(i <= exponent): + power = power * number + i = i + 1 + +print("The Result of {0} Power {1} = {2}".format(number, exponent, power)) From 1152a4851c3b3bb292ffe5d6cea82d6065d084f2 Mon Sep 17 00:00:00 2001 From: devil-py <73006951+devil-py@users.noreply.github.com> Date: Sat, 17 Oct 2020 07:56:49 +0530 Subject: [PATCH 322/781] Create counting_of_words_in_a_string --- counting_of_words_in_a_string | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 counting_of_words_in_a_string diff --git a/counting_of_words_in_a_string b/counting_of_words_in_a_string new file mode 100644 index 00000000..d34366fa --- /dev/null +++ b/counting_of_words_in_a_string @@ -0,0 +1,8 @@ +string = input("Please enter any String : ") +words = [] + +words = string.split() +frequency = [words.count(i) for i in words] + +myDict = dict(zip(words, frequency)) +print("Dictionary Items : ", myDict) From 4896c5dc72e93374479c61f474f483853d9e39bd Mon Sep 17 00:00:00 2001 From: devil-py <73006951+devil-py@users.noreply.github.com> Date: Sat, 17 Oct 2020 07:58:21 +0530 Subject: [PATCH 323/781] Create Count_vowels_in_a_string --- Count_vowels_in_a_string | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Count_vowels_in_a_string diff --git a/Count_vowels_in_a_string b/Count_vowels_in_a_string new file mode 100644 index 00000000..cec89bc9 --- /dev/null +++ b/Count_vowels_in_a_string @@ -0,0 +1,9 @@ +str1 = input("Please Enter Your Own String : ") +vowels = 0 + +for i in str1: + if(i == 'a' or i == 'e' or i == 'i' or i == 'o' or i == 'u' or i == 'A' + or i == 'E' or i == 'I' or i == 'O' or i == 'U'): + vowels = vowels + 1 + +print("Total Number of Vowels in this String = ", vowels) From 9fc208174f3f366c4ef59ee846cb3de6efd90c19 Mon Sep 17 00:00:00 2001 From: Nakul Dhawale <58903446+Nakul4998@users.noreply.github.com> Date: Sat, 17 Oct 2020 08:23:03 +0530 Subject: [PATCH 324/781] Create Program to convert a number from binary to octal --- ...m to convert a number from binary to octal | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Program to convert a number from binary to octal diff --git a/Program to convert a number from binary to octal b/Program to convert a number from binary to octal new file mode 100644 index 00000000..0151cbc8 --- /dev/null +++ b/Program to convert a number from binary to octal @@ -0,0 +1,37 @@ +#include +#include + +int binary_to_octal(long int binary) +{ +int octal = 0, decimal = 0, i = 0; + +while(binary != 0) +{ +decimal += (binary%10) * pow(2,i); +++i; +binary/=10; +} + +i = 1; + +while (decimal != 0) +{ +octal += (decimal % 8) * i; +decimal /= 8; +i *= 10; +} + +return octal; +} + +int main() +{ +long int binary; + +printf(“\nEnter a binary number: “); +scanf(“%lld”, &binary); + +printf(“\nOctal Equivalent : %d\n”, binary_to_octal(binary)); + +return 0; +} From 7417b256fc01279140f50ee434c08cb964260f0c Mon Sep 17 00:00:00 2001 From: Nakul Dhawale <58903446+Nakul4998@users.noreply.github.com> Date: Sat, 17 Oct 2020 08:39:26 +0530 Subject: [PATCH 325/781] Create Program to Check Triangle is Equilateral Isosceles or Scalene --- ...iangle is Equilateral Isosceles or Scalene | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Program to Check Triangle is Equilateral Isosceles or Scalene diff --git a/Program to Check Triangle is Equilateral Isosceles or Scalene b/Program to Check Triangle is Equilateral Isosceles or Scalene new file mode 100644 index 00000000..f71123c1 --- /dev/null +++ b/Program to Check Triangle is Equilateral Isosceles or Scalene @@ -0,0 +1,25 @@ +/* C Program to Check Triangle is Equilateral Isosceles or Scalene */ + +#include + +int main() +{ + int side1, side2, side3; + + printf("\n Please Enter Three Sides of a Triangle : "); + scanf("%d%d%d", &side1, &side2, &side3); + + if(side1 == side2 && side2 == side3) + { + printf("\n This is an Equilateral Triangle"); + } + else if(side1 == side2 || side2 == side3 || side1 == side3) + { + printf("\n This is an Isosceles Triangle"); + } + else + { + printf("\n This is a Scalene Triangle"); + } + return 0; + } From 14a27aa7e92c8ceb94a69578af01986f9a2a937a Mon Sep 17 00:00:00 2001 From: Ayush Aman <51491868+modi4651@users.noreply.github.com> Date: Sat, 17 Oct 2020 08:40:39 +0530 Subject: [PATCH 326/781] Create Code to find factorial of a number This is a optimized code to find factorial of a number. --- Code to find factorial of a number | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Code to find factorial of a number diff --git a/Code to find factorial of a number b/Code to find factorial of a number new file mode 100644 index 00000000..07b09ea2 --- /dev/null +++ b/Code to find factorial of a number @@ -0,0 +1,19 @@ +#include +int main() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows error if the user enters a negative integer + if (n < 0) + printf("Error! Factorial of a negative number doesn't exist."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + return 0; +} From ebb39d60bb8976acb8d759a1fb238013681163cf Mon Sep 17 00:00:00 2001 From: ashutoshcs-python <72990939+ashutoshcs-python@users.noreply.github.com> Date: Sat, 17 Oct 2020 08:44:03 +0530 Subject: [PATCH 327/781] Add files via upload --- voice assistance like google and alexa.py | 150 ++++++++++++++++++++++ 1 file changed, 150 insertions(+) create mode 100644 voice assistance like google and alexa.py diff --git a/voice assistance like google and alexa.py b/voice assistance like google and alexa.py new file mode 100644 index 00000000..e1d52eca --- /dev/null +++ b/voice assistance like google and alexa.py @@ -0,0 +1,150 @@ +import pyttsx3 +import webbrowser +import smtplib +import random +import speech_recognition as sr +import wikipedia +import datetime +import os +import sys + + + +engine = pyttsx3.init('sapi5') +voices = engine.getProperty('voices') +engine.setProperty('voices',voices[0].id) + +def speak(audio): + engine.say(audio) + engine.runAndWait() + + +def wishme(): + time=int(datetime.datetime.now().hour) + if time>=0 and time<12: + speak("good morning sir") + elif time>=12 and time<18: + speak("good afternoon sir") + else: + speak("good evening sir") + speak( "I am your virtual assistant jarvis . please tell me how may i help you") + + +def takeCommand(): + r=sr.Recognizer() + with sr.Microphone() as source: + print("listening.....") + r.pause_threshold=1 + r.adjust_for_ambient_noise(source, duration=5) + audio=r.listen(source) + + try: + print("Recognizing.....") + stat=r.recognize_google(audio, language="en-in") + print(f"User said:> {stat}\n") + + except Exception as e: + #print(e) + + print("Say that again please!!") + return "None" + return stat +def sendemail(to,content): + e_mail=lib.smtplib.SMTP('smtp.gmail.com',587) + e_mail.ehlo() + e_mail.starttls() + e_mail.login('tggv9986@gmail.com', 'mypass') + e_mail.sendemail('tggv9986@gmail.com',to,content) + e_mail.close() +if __name__ == "__main__": + wishme() + while True: + stat=takeCommand().lower() + + if 'wikipedia' in stat: + speak('searching wikipedia') + stat=stat.replace('wikipedia' , "") + results=wikipedia.summary(stat, sentences=3) + speak('According to wikipedia') + print(results) + speak(results) + + elif 'open youtube' in stat: + speak('okay') + webbrowser.open('youtube.com') + + elif 'my youtube channel' in stat: + speak("okay") + webbrowser.open('youtube.com/c/thegreatgrandvideos') + + elif 'google classroom' in stat: + speak("okay") + webbrowser.open('https://classroom.google.com/c/NjQzNTUyODU0MTFa') + + elif 'google' in stat: + speak("okay") + webbrowser.open('www.google.co.in') + + elif 'play music' in stat: + musicfile='"E:\\YouTube\\NCS Music & Sound Effect' + songs=os.listdir(musicfile) + print(songs) + os.startfile(os.path.join(musicfile ,songs[0])) + + elif'time' in stat: + ntime=datetime.datetime().strftime('%H:%M:%S') + + elif"open vs code" in stat: + vscode='C:\\Users\\ABHISHEK RANJAN\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Visual Studio Code\\Visual Studio Code.lnk' + os.startfile(vscode) + + elif'open filmora' in stat: + filmora="C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Wondershare\\Filmora9\\Wondershare Filmora9.lnk" + os.startfile(filmora) + + elif'open zoom' in stat: + zoomm="C:\\Users\\ABHISHEK RANJAN\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Zoom\\Start Zoom.lnk" + os.startfile(zoomm) + + elif 'open droidcam' in stat: + d_cam="C:\\Users\\ABHISHEK RANJAN\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\DroidCam\\DroidCam Client.lnk" + os.startfile(d_cam) + + elif "what's up" in stat or 'how are you' in stat: + stMsgs = ['Just doing my thing!', 'I am fine!', 'I am nice and full of energy'] + speak(random.choice(stMsgs)) + + elif 'nothing' in stat or 'abort' in stat or 'stop' in stat: + speak('okay') + speak('Bye Sir, have a good day.') + sys.exit() + + elif 'hello' in stat: + speak('Hello Sir') + + + elif'email to ashutosh' in stat: + try: + speak("what should i mail") + mes=takeCommand() + to='ashuranjan567@gmail.com' + sendemail(to, mes) + except Exception as e: + #print(e) + speak("sorry sir email has not been send i committed a mistake") + + + + + + + + + + + + + + + + \ No newline at end of file From 8e715555a111aa99eb15cabbb954326a4ae0648d Mon Sep 17 00:00:00 2001 From: Ayush Aman <51491868+modi4651@users.noreply.github.com> Date: Sat, 17 Oct 2020 08:55:59 +0530 Subject: [PATCH 328/781] Create code to print Fibonacci series This is my optimized code to print Fibonacci series of a number. --- code to print Fibonacci series | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 code to print Fibonacci series diff --git a/code to print Fibonacci series b/code to print Fibonacci series new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/code to print Fibonacci series @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From e341e47ef1f553a204c5dcf2ddb5cb683a6c744f Mon Sep 17 00:00:00 2001 From: Ayush Aman <51491868+modi4651@users.noreply.github.com> Date: Sat, 17 Oct 2020 08:59:39 +0530 Subject: [PATCH 329/781] Create Program to find largest array element in C Optimized code to find largest array element in C --- Program to find largest array element in C | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program to find largest array element in C diff --git a/Program to find largest array element in C b/Program to find largest array element in C new file mode 100644 index 00000000..7df4e3f4 --- /dev/null +++ b/Program to find largest array element in C @@ -0,0 +1,19 @@ +Live Demo + +#include + +int main() { + int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + int loop, largest; + + largest = array[0]; + + for(loop = 1; loop < 10; loop++) { + if( largest < array[loop] ) + largest = array[loop]; + } + + printf("Largest element of array is %d", largest); + + return 0; +} From 8fdf31c0037ae06fdd43ba85d8fd4908c75023c0 Mon Sep 17 00:00:00 2001 From: Ayush Aman <51491868+modi4651@users.noreply.github.com> Date: Sat, 17 Oct 2020 09:03:35 +0530 Subject: [PATCH 330/781] Create C Program to Find Smallest Element in Array Optimized code to find smallest element in array --- C Program to Find Smallest Element in Array | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 C Program to Find Smallest Element in Array diff --git a/C Program to Find Smallest Element in Array b/C Program to Find Smallest Element in Array new file mode 100644 index 00000000..441e2ce4 --- /dev/null +++ b/C Program to Find Smallest Element in Array @@ -0,0 +1,26 @@ +#include + +int main() { + int a[30], i, num, smallest; + + printf("\nEnter no of elements :"); + scanf("%d", &num); + + //Read n elements in an array + for (i = 0; i < num; i++) + scanf("%d", &a[i]); + + //Consider first element as smallest + smallest = a[0]; + + for (i = 0; i < num; i++) { + if (a[i] < smallest) { + smallest = a[i]; + } + } + + // Print out the Result + printf("\nSmallest Element : %d", smallest); + + return (0); +} From 972aa047123beb43d556249f9df8afbe0396104d Mon Sep 17 00:00:00 2001 From: Nakul Dhawale <58903446+Nakul4998@users.noreply.github.com> Date: Sat, 17 Oct 2020 09:12:30 +0530 Subject: [PATCH 331/781] Create Program to calculate area and perimeter of equilateral triangle --- ...area and perimeter of equilateral triangle | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Program to calculate area and perimeter of equilateral triangle diff --git a/Program to calculate area and perimeter of equilateral triangle b/Program to calculate area and perimeter of equilateral triangle new file mode 100644 index 00000000..debb74de --- /dev/null +++ b/Program to calculate area and perimeter of equilateral triangle @@ -0,0 +1,33 @@ +// Java Program to find area and +// perimeter of equilateral triangle +import java.io.*; + +class GFG +{ + // Function to calculate + // Area of equilateral triangle + static float area_equi_triangle(float side) + { + + return (float)(((Math.sqrt(3)) / 4) * + side * side); + } + + // Function to calculate + // Perimeter of equilateral + // triangle + static float peri_equi_triangle(float side) + { + return 3 * side; + } + + // Driver Code + public static void main(String arg[]) + { + float side = 4; + System.out.print("Area of Equilateral Triangle:"); + System.out.println(area_equi_triangle(side)); + System.out.print("Perimeter of Equilateral Triangle:"); + System.out.println(peri_equi_triangle(side)); + } +} From ae3b3ba7b50a6a3e67d7a8f917add26fdd2b99f2 Mon Sep 17 00:00:00 2001 From: Nakul Dhawale <58903446+Nakul4998@users.noreply.github.com> Date: Sat, 17 Oct 2020 09:14:44 +0530 Subject: [PATCH 332/781] Create linear search --- linear search | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 linear search diff --git a/linear search b/linear search new file mode 100644 index 00000000..412fdcf7 --- /dev/null +++ b/linear search @@ -0,0 +1,18 @@ +def linear_search(alist, key): + """Return index of key in alist. Return -1 if key not present.""" + for i in range(len(alist)): + if alist[i] == key: + return i + return -1 + + +alist = input('Enter the list of numbers: ') +alist = alist.split() +alist = [int(x) for x in alist] +key = int(input('The number to search for: ')) + +index = linear_search(alist, key) +if index < 0: + print('{} was not found.'.format(key)) +else: + print('{} was found at index {}.'.format(key, index)) From d3d94aa421d1b1885e50afdf45ab064298b5bbf2 Mon Sep 17 00:00:00 2001 From: Alok kumar <44169791+alokku6@users.noreply.github.com> Date: Sat, 17 Oct 2020 09:45:06 +0530 Subject: [PATCH 333/781] print a factorial number in c --- print a factorial number in c | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 print a factorial number in c diff --git a/print a factorial number in c b/print a factorial number in c new file mode 100644 index 00000000..44bca104 --- /dev/null +++ b/print a factorial number in c @@ -0,0 +1,13 @@ +void main() +{ + int a, b, n, fact; + int i, j; + printf("Enter the number"); + scanf("%d %d",&a,&b); + for(i=0;i Date: Sat, 17 Oct 2020 09:56:38 +0530 Subject: [PATCH 334/781] Create find factorial of number optimize solution for "Program to find factorial of number" in c++ --- find factorial of number | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 find factorial of number diff --git a/find factorial of number b/find factorial of number new file mode 100644 index 00000000..6ca575ce --- /dev/null +++ b/find factorial of number @@ -0,0 +1,13 @@ +#include +using namespace std; +int main() +{ + int i,fact=1,number; + cout<<"Enter any Number: "; + cin>>number; + for(i=1;i<=number;i++){ + fact=fact*i; + } + cout<<"Factorial of " < Date: Sat, 17 Oct 2020 10:40:40 +0530 Subject: [PATCH 335/781] Create ASCII hacktoberfest --- ASCII | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 ASCII diff --git a/ASCII b/ASCII new file mode 100644 index 00000000..e84fc638 --- /dev/null +++ b/ASCII @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + char x; + cin>>x; + + cout<<"the ASCII value of "< Date: Sat, 17 Oct 2020 10:43:25 +0530 Subject: [PATCH 336/781] Create add 2 array hacktoberfest --- add 2 array | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 add 2 array diff --git a/add 2 array b/add 2 array new file mode 100644 index 00000000..e84fc638 --- /dev/null +++ b/add 2 array @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + char x; + cin>>x; + + cout<<"the ASCII value of "< Date: Sat, 17 Oct 2020 10:44:49 +0530 Subject: [PATCH 337/781] Create fibonacci series using recursion --- fibonacci series using recursion | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 fibonacci series using recursion diff --git a/fibonacci series using recursion b/fibonacci series using recursion new file mode 100644 index 00000000..428f5d5d --- /dev/null +++ b/fibonacci series using recursion @@ -0,0 +1,16 @@ +//Fibonacci Series using Recursion +#include +int fib(int n) +{ + if (n <= 1) + return n; + return fib(n-1) + fib(n-2); +} + +int main () +{ + int n = 9; + printf("%d", fib(n)); + getchar(); + return 0; +} From b9bdfe9ba253a4f719b41f235506b4b2efcc12c6 Mon Sep 17 00:00:00 2001 From: Tushar Singh <56396090+mr-sing@users.noreply.github.com> Date: Sat, 17 Oct 2020 10:47:15 +0530 Subject: [PATCH 338/781] Create add two array hacktoberfest --- add two array | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 add two array diff --git a/add two array b/add two array new file mode 100644 index 00000000..884ed640 --- /dev/null +++ b/add two array @@ -0,0 +1,27 @@ +#include +using namespace std; +int main() +{ + int first[20], second[20], sum[20], c, n; + + cout << "Enter the number of elements in the array "; + cin >> n; + + cout << "Enter elements of first array" << endl; + + for (c = 0; c < n; c++) + cin >> first[c]; + + cout << "Enter elements of second array" << endl; + + for (c = 0; c < n; c++) + cin >> second[c]; + + cout << "Sum of elements of the arrays:" << endl; + + for (c = 0; c < n; c++) { + sum[c] = first[c] + second[c]; + cout << sum[c] << endl; + } + return 0; +} From eb23acad1843f5e94db678183684bc98990669e3 Mon Sep 17 00:00:00 2001 From: Khushi Singh Date: Sat, 17 Oct 2020 10:48:20 +0530 Subject: [PATCH 339/781] Create fibonacci series in python using recursion --- fibonacci series in python using recursion | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 fibonacci series in python using recursion diff --git a/fibonacci series in python using recursion b/fibonacci series in python using recursion new file mode 100644 index 00000000..be9335c8 --- /dev/null +++ b/fibonacci series in python using recursion @@ -0,0 +1,17 @@ +# Python program to display the Fibonacci sequence + +def recur_fibo(n): + if n <= 1: + return n + else: + return(recur_fibo(n-1) + recur_fibo(n-2)) + +nterms = 10 + +# check if the number of terms is valid +if nterms <= 0: + print("Plese enter a positive integer") +else: + print("Fibonacci sequence:") + for i in range(nterms): + print(recur_fibo(i)) From 74105c320267985436ca3227ed5fd95717b7e52b Mon Sep 17 00:00:00 2001 From: pavankalyanimadabathini <48764540+pavankalyanimadabathini@users.noreply.github.com> Date: Sat, 17 Oct 2020 10:48:55 +0530 Subject: [PATCH 340/781] Matrices Program to multiply 2D or 3D Matrices --- Multipy matrices | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Multipy matrices diff --git a/Multipy matrices b/Multipy matrices new file mode 100644 index 00000000..927090e4 --- /dev/null +++ b/Multipy matrices @@ -0,0 +1,39 @@ +# 4x4 matrix multiplication using Python3 +# Function definition +def matrix_multiplication(M, N): + # List to store matrix multiplication result + R = [[0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0], + [0, 0, 0, 0]] + + for i in range(0, 4): + for j in range(0, 4): + for k in range(0, 4): + R[i][j] += M[i][k] * N[k][j] + + for i in range(0, 4): + for j in range(0, 4): + # if we use print(), by default cursor moves to next line each time, + # Now we can explicitly define ending character or sequence passing + # second parameter as end ="" + # syntax: print(, end ="") + # Here space (" ") is used to print a gape after printing + # each element of R + print(R[i][j], end =" ") + print("\n", end ="") + +# First matrix. M is a list +M = [[1, 1, 1, 1], + [2, 2, 2, 2], + [3, 3, 3, 3], + [4, 4, 4, 4]] + +# Second matrix. N is a list +N = [[1, 1, 1, 1], + [2, 2, 2, 2], + [3, 3, 3, 3], + [4, 4, 4, 4]] + +# Call matrix_multiplication function +matrix_multiplication(M, N) From 46922ab34ae96a6ee9ed168d376700c2daa403be Mon Sep 17 00:00:00 2001 From: Khushi Singh Date: Sat, 17 Oct 2020 10:49:46 +0530 Subject: [PATCH 341/781] Create fibonacci series in c++ using recursion --- fibonacci series in c++ using recursion | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 fibonacci series in c++ using recursion diff --git a/fibonacci series in c++ using recursion b/fibonacci series in c++ using recursion new file mode 100644 index 00000000..cb212a0c --- /dev/null +++ b/fibonacci series in c++ using recursion @@ -0,0 +1,20 @@ +#include +using namespace std; +int fib(int x) { + if((x==1)||(x==0)) { + return(x); + }else { + return(fib(x-1)+fib(x-2)); + } +} +int main() { + int x , i=0; + cout << "Enter the number of terms of series : "; + cin >> x; + cout << "\nFibonnaci Series : "; + while(i < x) { + cout << " " << fib(i); + i++; + } + return 0; +} From 40f7fc45a5e5ef7d80678dc546ac1206c21c049a Mon Sep 17 00:00:00 2001 From: Tushar Singh <56396090+mr-sing@users.noreply.github.com> Date: Sat, 17 Oct 2020 10:50:59 +0530 Subject: [PATCH 342/781] Create find a small element in array hacktoverfest --- find a small element in array | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 find a small element in array diff --git a/find a small element in array b/find a small element in array new file mode 100644 index 00000000..441e2ce4 --- /dev/null +++ b/find a small element in array @@ -0,0 +1,26 @@ +#include + +int main() { + int a[30], i, num, smallest; + + printf("\nEnter no of elements :"); + scanf("%d", &num); + + //Read n elements in an array + for (i = 0; i < num; i++) + scanf("%d", &a[i]); + + //Consider first element as smallest + smallest = a[0]; + + for (i = 0; i < num; i++) { + if (a[i] < smallest) { + smallest = a[i]; + } + } + + // Print out the Result + printf("\nSmallest Element : %d", smallest); + + return (0); +} From fefb71fd22314cb7585311c5054b830b2ba6e80d Mon Sep 17 00:00:00 2001 From: Khushi Singh Date: Sat, 17 Oct 2020 10:52:01 +0530 Subject: [PATCH 343/781] Create fibonacci series in java using recursion --- fibonacci series in java using recursion | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 fibonacci series in java using recursion diff --git a/fibonacci series in java using recursion b/fibonacci series in java using recursion new file mode 100644 index 00000000..46cd166f --- /dev/null +++ b/fibonacci series in java using recursion @@ -0,0 +1,19 @@ +//Using Recursion +public class FibonacciCalc{ + public static int fibonacciRecursion(int n){ + if(n == 0){ + return 0; + } + if(n == 1 || n == 2){ + return 1; + } + return fibonacciRecursion(n-2) + fibonacciRecursion(n-1); + } + public static void main(String args[]) { + int maxNumber = 10; + System.out.print("Fibonacci Series of "+maxNumber+" numbers: "); + for(int i = 0; i < maxNumber; i++){ + System.out.print(fibonacciRecursion(i) +" "); + } + } +} From f1a4a35f77587992b3b0ed67d9aac92e56cbf999 Mon Sep 17 00:00:00 2001 From: Rishn99 <40461721+Rishn99@users.noreply.github.com> Date: Sat, 17 Oct 2020 10:57:26 +0530 Subject: [PATCH 344/781] Create A Program for 2D Matrices --- A Program for 2D Matrices | 40 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 A Program for 2D Matrices diff --git a/A Program for 2D Matrices b/A Program for 2D Matrices new file mode 100644 index 00000000..136681df --- /dev/null +++ b/A Program for 2D Matrices @@ -0,0 +1,40 @@ +#include +int main() { + int r, c, a[100][100], b[100][100], sum[100][100], i, j; + printf("Enter the number of rows (between 1 and 100): "); + scanf("%d", &r); + printf("Enter the number of columns (between 1 and 100): "); + scanf("%d", &c); + + printf("\nEnter elements of 1st matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &a[i][j]); + } + + printf("Enter elements of 2nd matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &b[i][j]); + } + + // adding two matrices + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + sum[i][j] = a[i][j] + b[i][j]; + } + + // printing the result + printf("\nSum of two matrices: \n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("%d ", sum[i][j]); + if (j == c - 1) { + printf("\n\n"); + } + } + + return 0; +} From ea795b71c911cb57488dffa585dadd9e9dcefe44 Mon Sep 17 00:00:00 2001 From: pavankalyanimadabathini <48764540+pavankalyanimadabathini@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:04:16 +0530 Subject: [PATCH 345/781] ASCII C Program to print ASCII value of given character --- C Program to print ASCII value of given character | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 C Program to print ASCII value of given character diff --git a/C Program to print ASCII value of given character b/C Program to print ASCII value of given character new file mode 100644 index 00000000..78a9e039 --- /dev/null +++ b/C Program to print ASCII value of given character @@ -0,0 +1,7 @@ +#include +int main() +{ + char c = 'k'; + printf("The ASCII value of %c is %d", c, c); + return 0; +} From 5c3cbd713d1e74d00e558b83b46be21032033392 Mon Sep 17 00:00:00 2001 From: sidtiwari2712 <53444701+sidtiwari2712@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:10:15 +0530 Subject: [PATCH 346/781] Create Reverse an array --- Reverse an array | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Reverse an array diff --git a/Reverse an array b/Reverse an array new file mode 100644 index 00000000..f0d5339a --- /dev/null +++ b/Reverse an array @@ -0,0 +1,44 @@ +#include +using namespace std; + +void rvereseArray(int arr[], int start, int end) +{ + while (start < end) + { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } +} + +/* Utility function to print an array */ +void printArray(int arr[], int size) +{ + for (int i = 0; i < size; i++) + cout << arr[i] << " "; + + cout << endl; +} + +/* Driver function to test above functions */ +int main() +{ + int arr[] = {1, 2, 3, 4, 5, 6}; + + int n = sizeof(arr) / sizeof(arr[0]); + + // To print original array + printArray(arr, n); + + // Function calling + rvereseArray(arr, 0, n-1); + + cout << "Reversed array is" << endl; + + // To print the Reversed array + printArray(arr, n); + + return 0; +} From 43b56dd22f42714f4114cae6b0a5e13ef4c8303f Mon Sep 17 00:00:00 2001 From: Darshan Jogad <64198730+dmjogad@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:18:31 +0530 Subject: [PATCH 347/781] Code for Factorial of number --- code for factorial of number | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 code for factorial of number diff --git a/code for factorial of number b/code for factorial of number new file mode 100644 index 00000000..aa3ff769 --- /dev/null +++ b/code for factorial of number @@ -0,0 +1,16 @@ + +num = int(input("Enter number: ")) + +factorial = 1 + +if (num < 0): + print("factorial of negative numberis npt possible") + +elif (num == 0): + print("factorial of", num, "is 1") + +else: + for i in range (1,num+1): + factorial = factorial * i + + print("factorial of", num, "is", factorial) From 0113d284a3ed27ace8459002f24d5fb3772c44a6 Mon Sep 17 00:00:00 2001 From: Abhay Agrahary Date: Sat, 17 Oct 2020 11:30:43 +0530 Subject: [PATCH 348/781] Create Program to convert binary digits to decimal digitsnumber optimize code for conversion of binary to decimal for hactoberfest-request --- ...rt binary digits to decimal digitsnumber | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Program to convert binary digits to decimal digitsnumber diff --git a/Program to convert binary digits to decimal digitsnumber b/Program to convert binary digits to decimal digitsnumber new file mode 100644 index 00000000..c95dbfdb --- /dev/null +++ b/Program to convert binary digits to decimal digitsnumber @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +using namespace std; + +int main() +{ + int b,d=0,i=0,s; + cin>>b; + while(b!=0) + { + + s=b%10; + b/=10; + if(s!=0&&s!=1) + { + break; + } + d=d+(s*pow(2,i++)); + } + if(s!=0&&s!=1) + cout<<"not a binary"; + else + cout<<"Decimal Conversion is : "< Date: Sat, 17 Oct 2020 11:31:01 +0530 Subject: [PATCH 349/781] Create Fibonacci Series (Type-Hard) Fibonacci Series using recursion in java --- Fibonacci Series (Type-Hard) | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Fibonacci Series (Type-Hard) diff --git a/Fibonacci Series (Type-Hard) b/Fibonacci Series (Type-Hard) new file mode 100644 index 00000000..557b188c --- /dev/null +++ b/Fibonacci Series (Type-Hard) @@ -0,0 +1,17 @@ +class FibonacciExample2{ + static int n1=0,n2=1,n3=0; + static void printFibonacci(int count){ + if(count>0){ + n3 = n1 + n2; + n1 = n2; + n2 = n3; + System.out.print(" "+n3); + printFibonacci(count-1); + } + } + public static void main(String args[]){ + int count=10; + System.out.print(n1+" "+n2);//printing 0 and 1 + printFibonacci(count-2);//n-2 because 2 numbers are already printed + } +} From 9fafd71106a0fe220217b3442d0c03c78960b15b Mon Sep 17 00:00:00 2001 From: sidtiwari2712 <53444701+sidtiwari2712@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:35:29 +0530 Subject: [PATCH 350/781] Create sum of even number --- sum of even number | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 sum of even number diff --git a/sum of even number b/sum of even number new file mode 100644 index 00000000..0f54ef56 --- /dev/null +++ b/sum of even number @@ -0,0 +1,28 @@ + +# python 3 implementation to +# find sum of even numbers +# at even indices + +# Function to calculate sum +# of even numbers at even indices +def sum_even_and_even_index(arr,n): + + i = 0 + sum = 0 + +# calculating sum of even +# number at even index + for i in range(0,n,2): + if (arr[i] % 2 == 0) : + sum += arr[i] + + # required sum + return sum + + +# Driver program to test above +arr = [5, 6, 12, 1, 18, 8] +n = len(arr) +print("Sum of even numbers at ", + "even indices is ", + sum_even_and_even_index(arr, n)) From abe4966eecd2f3da7415b02bf23975c643032873 Mon Sep 17 00:00:00 2001 From: yogii7664 <72780894+yogii7664@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:38:10 +0530 Subject: [PATCH 351/781] Create Binary to Decimal (Type-Hard) Program for Binary to Decimal Using Recursion in Java --- Binary to Decimal (Type-Hard) | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Binary to Decimal (Type-Hard) diff --git a/Binary to Decimal (Type-Hard) b/Binary to Decimal (Type-Hard) new file mode 100644 index 00000000..511fb7c0 --- /dev/null +++ b/Binary to Decimal (Type-Hard) @@ -0,0 +1,32 @@ +// Recursive Java program to convert binary +// decimal + + +class GFG +{ + static int toDecimal(String binary,int i) + { + // If we reached last character + int n = binary.length(); + if (i == n-1) + return binary.charAt(i) - '0'; + + // Add current tern and recur for + // remaining terms + return ((binary.charAt(i) - '0') << (n-i-1)) + + toDecimal(binary, i+1); + } + + // Driver code + public static void main(String []args) + { + String binary = "1010"; + int i=0; + System.out.println(toDecimal(binary,i)); + + } + +} + +// This code is contributed +// by Yogii7664 (Yogesh Soni) From 1e4011d4bf3da1a984971eebe82bdb691f155c79 Mon Sep 17 00:00:00 2001 From: yogii7664 <72780894+yogii7664@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:40:31 +0530 Subject: [PATCH 352/781] Create Binary to Octal (Type-Hard) Java Program to Convert Binary Number to Octal --- Binary to Octal (Type-Hard) | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Binary to Octal (Type-Hard) diff --git a/Binary to Octal (Type-Hard) b/Binary to Octal (Type-Hard) new file mode 100644 index 00000000..ab9f4637 --- /dev/null +++ b/Binary to Octal (Type-Hard) @@ -0,0 +1,31 @@ +public class BinaryOctal { + + public static void main(String[] args) { + long binary = 101001; + int octal = convertBinarytoOctal(binary); + System.out.printf("%d in binary = %d in octal", binary, octal); + } + + public static int convertBinarytoOctal(long binaryNumber) + { + int octalNumber = 0, decimalNumber = 0, i = 0; + + while(binaryNumber != 0) + { + decimalNumber += (binaryNumber % 10) * Math.pow(2, i); + ++i; + binaryNumber /= 10; + } + + i = 1; + + while (decimalNumber != 0) + { + octalNumber += (decimalNumber % 8) * i; + decimalNumber /= 8; + i *= 10; + } + + return octalNumber; + } +} From 4fd4a4daa5fbbabc5f7d282e660018aaf9e3076f Mon Sep 17 00:00:00 2001 From: yogii7664 <72780894+yogii7664@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:43:05 +0530 Subject: [PATCH 353/781] Create Check Triangle is Equilateral, Isosceles or Scalene (Type-Hard) Program To Check whether a Triangle is Equilateral, Isosceles or Scalene in Java --- ...ilateral, Isosceles or Scalene (Type-Hard) | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Check Triangle is Equilateral, Isosceles or Scalene (Type-Hard) diff --git a/Check Triangle is Equilateral, Isosceles or Scalene (Type-Hard) b/Check Triangle is Equilateral, Isosceles or Scalene (Type-Hard) new file mode 100644 index 00000000..8c13667b --- /dev/null +++ b/Check Triangle is Equilateral, Isosceles or Scalene (Type-Hard) @@ -0,0 +1,34 @@ +// Java program for the above approach +class GFG{ + +// Function to check if the triangle +// is equilateral or isosceles or scalene +static void checkTriangle(int x, int y, int z) +{ + + // Check for equilateral triangle + if (x == y && y == z ) + System.out.println("Equilateral Triangle"); + + // Check for isoceles triangle + else if (x == y || y == z || z == x ) + System.out.println("Isoceles Triangle"); + + // Otherwise scalene triangle + else + System.out.println("Scalene Triangle"); +} + +// Driver Code +public static void main(String[] args) +{ + + // Given sides of triangle + int x = 8, y = 7, z = 9; + + // Function call + checkTriangle(x, y, z); +} +} + +// This code is contributed by jana_sayantan From 29aea4bcc9da82b619b1597fa1301938c4c3fcb4 Mon Sep 17 00:00:00 2001 From: ANURAG2RANJAN <73010455+ANURAG2RANJAN@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:48:20 +0530 Subject: [PATCH 354/781] Create length_of_string optimised string length --- length_of_string | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 length_of_string diff --git a/length_of_string b/length_of_string new file mode 100644 index 00000000..77f67220 --- /dev/null +++ b/length_of_string @@ -0,0 +1,2 @@ +sl = str(input("Enter string:")) +print('Length of',sl,'is',len(sl)) From a20e29d5f63d3df62e08206652ff823e4d22ae4b Mon Sep 17 00:00:00 2001 From: ANURAG2RANJAN <73010455+ANURAG2RANJAN@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:13:41 +0530 Subject: [PATCH 355/781] Create largest_element_in_1Darray optimised user input array largest element --- largest_element_in_1Darray | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 largest_element_in_1Darray diff --git a/largest_element_in_1Darray b/largest_element_in_1Darray new file mode 100644 index 00000000..1dd2a78b --- /dev/null +++ b/largest_element_in_1Darray @@ -0,0 +1,17 @@ +lst = [] +# number of elements as input +n = int(input("Enter number of elements : ")) +# iterating till the range +for i in range(0, n): + ele = int(input()) + + lst.append(ele) # adding the element +def largest(lst,n): + # Initialize maximum element + max = lst[0] + for i in range(1, n): + if lst[i] > max: + max = lst[i] + return max +Ans = largest(lst,n) +print ("Largest in given array is",Ans) From eb975f1e519134e5cdb5f4c0f174fd82ffd4c53b Mon Sep 17 00:00:00 2001 From: ANURAG2RANJAN <73010455+ANURAG2RANJAN@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:26:29 +0530 Subject: [PATCH 356/781] Create Smallest_element_in_1Darray optimised smallest element in 1D array --- Smallest_element_in_1Darray | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Smallest_element_in_1Darray diff --git a/Smallest_element_in_1Darray b/Smallest_element_in_1Darray new file mode 100644 index 00000000..9c5cc31a --- /dev/null +++ b/Smallest_element_in_1Darray @@ -0,0 +1,17 @@ +lst = [] +# number of elements as input +n = int(input("Enter number of elements : ")) +# iterating till the range +for i in range(0, n): + ele = int(input()) + + lst.append(ele) # adding the element +def smallest(lst,n): + # Initialize smallest element + min = lst[0] + for i in range(1, n): + if lst[i] < min: + min = lst[i] + return min +Ans = smallest(lst,n) +print ("Smallest in given array is",Ans) From a8d0bfb7e3715eaf7e33ab277e019360a1644c84 Mon Sep 17 00:00:00 2001 From: bhargava53929 <72983345+bhargava53929@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:27:38 +0530 Subject: [PATCH 357/781] Create adding the array elements --- adding the array elements | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 adding the array elements diff --git a/adding the array elements b/adding the array elements new file mode 100644 index 00000000..3bad39e9 --- /dev/null +++ b/adding the array elements @@ -0,0 +1,14 @@ +#include +int main() +{ + int a[100],sum=0,n; + scanf("%d",&n); + for(int i=1;i Date: Sat, 17 Oct 2020 12:30:21 +0530 Subject: [PATCH 358/781] Create Sieve Of Eratosthenes --- Sieve Of Eratosthenes | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Sieve Of Eratosthenes diff --git a/Sieve Of Eratosthenes b/Sieve Of Eratosthenes new file mode 100644 index 00000000..981a11c3 --- /dev/null +++ b/Sieve Of Eratosthenes @@ -0,0 +1,37 @@ +// C++ program to print all primes smaller than or equal to +// n using Sieve of Eratosthenes +#include +using namespace std; + +void SieveOfEratosthenes(int n) +{ + + bool prime[n+1]; + memset(prime, true, sizeof(prime)); + + for (int p=2; p*p<=n; p++) + { + // If prime[p] is not changed, then it is a prime + if (prime[p] == true) + { + + for (int i=p*p; i<=n; i += p) + prime[i] = false; + } + } + + // Print all prime numbers + for (int p=2; p<=n; p++) + if (prime[p]) + cout << p << " "; +} + + +int main() +{ + int n = 30; + cout << "Following are the prime numbers smaller " + << " than or equal to " << n << endl; + SieveOfEratosthenes(n); + return 0; +} From 6b755c1e598d3f4d7a1680710865d6f66c6b5ac1 Mon Sep 17 00:00:00 2001 From: Abdul Sameer <66318169+AbdulSameer47@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:32:41 +0530 Subject: [PATCH 359/781] Create Binary Search Tree --- Binary Search Tree | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 Binary Search Tree diff --git a/Binary Search Tree b/Binary Search Tree new file mode 100644 index 00000000..46c9a37b --- /dev/null +++ b/Binary Search Tree @@ -0,0 +1,128 @@ +#include + +using namespace std; +class treenode{ +public: + int value; + treenode* left; + treenode* right; + + + treenode() + { + value=0; + left=NULL; + right=NULL; + } + treenode(int v) + { + value =v; + left = NULL; + right =NULL; + } +}; + +class bst{ +public: + treenode* root; + bst() + { + root =NULL; + } + + bool isEmpty(){ + if(root == NULL) + return true; + else + return false; + } + + void insert(treenode* new_node) + { + if(root == NULL) + root = new_node; + else{ + treenode* temp =root; + while(temp!=NULL) + { + if(new_node->value == temp->value) + return; + else if((new_node->value value)&& (temp->left==NULL)) + { + temp->left = new_node; + break; + } + else if((new_node->value > temp->value) && (temp->right ==NULL)) + { + temp->right =new_node; + break; + } + else{ + temp =temp->right; + } + } + } + } + + void disp(treenode* root){ + + if(root ==NULL) + return; + cout<value<left); + disp(root->right); + } +}; + + + + + +int main(){ +bst obj; + + int option,val; + do{ + cout<<"Selet operation: (press 0 t exit)"<>option; + + treenode *new_node = new treenode(); + switch(option){ + + case 0: + break; + case 1: + cout<<"insert"<>val; + new_node->value=val; + obj.insert(new_node); + cout< Date: Sat, 17 Oct 2020 12:33:42 +0530 Subject: [PATCH 360/781] Create diagonal diffrence it is used to find the difference of the sum of two diagonals in a matrix --- diagonal diffrence | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 diagonal diffrence diff --git a/diagonal diffrence b/diagonal diffrence new file mode 100644 index 00000000..cc3c0be9 --- /dev/null +++ b/diagonal diffrence @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + + int n, j; + int i=0,RightDiagonalSum=0,LeftDiagonalSum=0, firstarray, secondarray; + + scanf("%d",&n); + int a[n][n]; + + for(int firstarray = 0; firstarray < n; firstarray++) + { + for(int secondarray = 0; secondarray < n; secondarray++) + { + + scanf("%d",&a[firstarray][secondarray]); + } + } + + while(i Date: Sat, 17 Oct 2020 12:36:18 +0530 Subject: [PATCH 361/781] Create Circular Quee Options: Insert(enquee) delete(dequee) is full is empty count display clear screen --- Circular Quee | 154 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 Circular Quee diff --git a/Circular Quee b/Circular Quee new file mode 100644 index 00000000..9110f596 --- /dev/null +++ b/Circular Quee @@ -0,0 +1,154 @@ +#include +#include +#include +#include +#include +using namespace std; + +class cqueue{ +private: + int front,rear,cnt; + int arr[5]; +public: + cqueue(){ + cnt=0; + front =-1; + rear=-1; + for(int i=0;i<5;i++) + arr[i]=0; + } + + +bool isEmpty(){ + + if(front==-1 && rear==-1) + return true; + else + return false; +} + +bool isFull(){ + + if((rear+1)%5==front) + return true; + else + return false; +} + +void enqueue(int val){ + + if(isFull()) + cout<<"queue full"; + else if(isEmpty()){ + + front =rear=0; + arr[rear]=val; + } + else{ + rear = (rear+1)%5; + arr[rear]=val; + + } + cnt++; +} + +int dequeue(){ + + int x; + if(isEmpty()){ + cout<<"queue empty"<>option; + switch(option){ + case 0: + break; + case 1: + cout<<"enqueue operation"<>value; + q1.enqueue(value); + break; + case 2: + cout<<"dequeue operation:"< Date: Sat, 17 Oct 2020 12:38:16 +0530 Subject: [PATCH 362/781] Create power_of_number math class used to find power in python --- power_of_number | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 power_of_number diff --git a/power_of_number b/power_of_number new file mode 100644 index 00000000..859177b5 --- /dev/null +++ b/power_of_number @@ -0,0 +1,7 @@ +import math + +base_number = float(input("Enter the base number: ")) +exponent = float(input("Enter the exponent: ")) + +power = math.pow(base_number,exponent) +print("Power is =",power) From 6ef968002f3605bb80b0cf8d581ccce0eb2f4269 Mon Sep 17 00:00:00 2001 From: Abdul Sameer <66318169+AbdulSameer47@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:40:00 +0530 Subject: [PATCH 363/781] Create All Stack Operations 1. push 2. pop 3. isEmpty 4. isFull 5. peek 6. count 7. change 8. Display 9. clear screen --- All Stack Operations | 169 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 All Stack Operations diff --git a/All Stack Operations b/All Stack Operations new file mode 100644 index 00000000..dcb66264 --- /dev/null +++ b/All Stack Operations @@ -0,0 +1,169 @@ +#include +#include +using namespace std; + +class stack{ + private: + int top; + int arr[5]; + public: + stack(){ + top=-1; + for(int i=0;i<5;i++){ + arr[i]=0; + } + } + + bool isEmpty(){ + if(top==-1) + return true; + else + return false; + } + + bool isFull(){ + if (top==4) + return true; + else + return false; + } + + + void push(int val){ + + if(isFull()){ + cout<<"stack full"; + } + else{ + + top++; + arr[top] =val; + } + } + + int pop(){ + + if(isEmpty()){ + cout<<"stack is empty"; + return 0; + } + else{ + int popvalue=arr[top]; + arr[top]=0; + top--; + return popvalue; + } + } + + int coun(){ + return (top+1); + } + + int peek(int pos){ + + if(isEmpty()){ + cout<<"stack empty<=0;i--){ + cout<>option; + switch(option){ + case 0: + break; + case 1: + cout<<"enter value to push"<>value; + s1.push(value); + break; + case 2: + cout<<"pop function called..."<>position; + cout<<"peek function called...value at position"<>position; + cout<>value; + s1.change(position,value); + break; + case 8: + cout<<"display function called"< Date: Sat, 17 Oct 2020 12:43:01 +0530 Subject: [PATCH 364/781] Create largest element of the array --- largest element of the array | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 largest element of the array diff --git a/largest element of the array b/largest element of the array new file mode 100644 index 00000000..34a9b0c4 --- /dev/null +++ b/largest element of the array @@ -0,0 +1,12 @@ +#include +int main() +{ + int a[100],n,max=0; + scanf("%d",&n); + for(int i=0;i>max){max=a[i];} + } + printf("%d",max); + } From 40d947616619648eff42e31d799ddbdb9df590eb Mon Sep 17 00:00:00 2001 From: Sahil2607-hub <56781731+Sahil2607-hub@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:50:59 +0530 Subject: [PATCH 365/781] Create sumofarraynumbers.c --- sumofarraynumbers.c | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 sumofarraynumbers.c diff --git a/sumofarraynumbers.c b/sumofarraynumbers.c new file mode 100644 index 00000000..a0c4900f --- /dev/null +++ b/sumofarraynumbers.c @@ -0,0 +1,46 @@ +#include +#include + +int main (){ +int i ,j, a,b,n,arr[20][20],h,v; +int count=0; + +scanf("%d",&h); + +scanf("%d",&v); + +printf("enter the elements"); +for (i=0;i Date: Sat, 17 Oct 2020 14:27:48 +0700 Subject: [PATCH 366/781] Create Python: Largest element in an array --- Python: Largest element in an array | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Python: Largest element in an array diff --git a/Python: Largest element in an array b/Python: Largest element in an array new file mode 100644 index 00000000..a9bda037 --- /dev/null +++ b/Python: Largest element in an array @@ -0,0 +1,12 @@ +def largest(arr,n): + + max = arr[0] + for i in range(1, n): + if arr[i] > max: + max = arr[i] + return max + +arr = [10, 54, 45, 90, 1000] +n = len(arr) +Ans = largest(arr,n) +print ("Largest in given array is",Ans) From 07b4def61efaf064f0d601af1a38228d1780b03f Mon Sep 17 00:00:00 2001 From: Sahil2607-hub <56781731+Sahil2607-hub@users.noreply.github.com> Date: Sat, 17 Oct 2020 12:58:44 +0530 Subject: [PATCH 367/781] Create linkedlist.c --- linkedlist.c | 233 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 233 insertions(+) create mode 100644 linkedlist.c diff --git a/linkedlist.c b/linkedlist.c new file mode 100644 index 00000000..a410d87a --- /dev/null +++ b/linkedlist.c @@ -0,0 +1,233 @@ +#include +#include + +struct node { + int data; + struct node *link; + +}; +struct node *head,*newnode,*temp; + +int main(){ + int i,n; + + head =0; + printf("enter number of nodes :"); + scanf("%d",&n); + for(i=0;idata); + newnode->link=0; + + if(head ==0){ + + head =temp=newnode; + } + else{ + temp->link=newnode; + temp=newnode; + } + + + } + temp=head; + while(temp!=0){ + + printf("\t%d->",temp->data); + temp=temp->link; + } + int ch; + + + printf("\nOperations on singly linked list\n"); + + printf("\n1.Insert node at first"); + printf("\n2.Insert node at last"); + printf("\n3.Insert node at position"); + printf("\n4.Delete Node from any Position"); + printf("\n5.Display List in Reverse"); + printf("\n6.Exit\n"); + + + while (ch!=6) + { + + printf("\nEnter your choice"); + scanf("%d", &ch); + + switch (ch) + { + case 1: + printf("...Inserting node at first\n"); + insbegin();temp=head; + printf("\n list :"); + disp(); + break; + case 2: + printf("...Inserting node at last\n"); + insend();temp=head; + printf("\n list :"); + disp(); + break; + case 3: + printf("...Inserting node at position\n"); + inspos();temp=head; + printf("\n list :"); + disp(); + break; + case 4: + printf("...Deleting Node from any Position\n"); + del();temp=head; + printf("\n list :"); + disp(); + break; + case 5: + printf("Displaying List in Reverse\n"); + rev();temp=head; + printf("\n list :"); + disp(); + break; + case 6: + printf("Exiting\n"); + return 0; + break; + default: + printf("...Invalid Choice...\n"); + break; + } + + } + + +} +void disp() + + { + while(temp!=0){ + + printf("\t%d->",temp->data); + temp=temp->link; + } + } + + +void insbegin(){ + newnode=(struct node *)malloc(sizeof(struct node)); + printf("enter data to be inserted:"); + scanf("%d",&newnode->data); + newnode->link=0; + temp=head; + if(head ==0){ + + head =temp=newnode; + } + else{ + + newnode->link=temp->link; + head=newnode; + } + +} +void insend(){ + newnode=(struct node *)malloc(sizeof(struct node)); + printf("\nenter data to be inserted at end:"); + scanf("%d",&newnode->data); + newnode->link=0; + temp=head; + while(temp->link!=0){ + temp=temp->link; + } + temp->link=newnode; + temp=newnode; + +} +void inspos(){ + int i,c; + printf("\nenter the position at which node is to be inserted :"); + scanf("%d",&c); + newnode=(struct node *)malloc(sizeof(struct node)); + printf("\nenter data to be inserted :"); + scanf("%d",&newnode->data); + + temp=head; + for(i=1;ilink; + +} +newnode->link=temp->link; + temp->link=newnode; + + + + +} + + +void delbegin(){ + temp = head; + head = head->link; + free(temp); + + + +} + + + + + + +void dellast(){ + struct node *prev; + temp =head ; + while(temp->link!=0){ + prev=temp; + + temp=temp->link; + } + prev->link=0; + free(temp); +} + + + + + + + +void del(){ + int c,i=1 ; + struct node *prev; + printf("\nenter the node you want to delete :"); + scanf("%d",&c); + + temp=head; + while(ilink; + + i++;} + + prev->link=temp->link; + free(temp); +} + + + +void rev(){ + struct node *nextnode,*current,*prev; + prev=0; + current=nextnode=head; + while(nextnode!=0){ + nextnode=nextnode->link; + current->link=prev; + prev=current; + current = nextnode; + + } + head =prev; + +} + From b78789715e8f64a5ac2a3cf0220091b8cc119735 Mon Sep 17 00:00:00 2001 From: Trung_Ngo <57355092+TrungNgo2809@users.noreply.github.com> Date: Sat, 17 Oct 2020 14:32:26 +0700 Subject: [PATCH 368/781] Create MergeSort.py --- MergeSort.py | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 MergeSort.py diff --git a/MergeSort.py b/MergeSort.py new file mode 100644 index 00000000..be5a3ff0 --- /dev/null +++ b/MergeSort.py @@ -0,0 +1,67 @@ +def merge(arr, l, m, r): + n1 = m - l + 1 + n2 = r- m + L = [0] * (n1) + R = [0] * (n2) + + # Copy data to temp arrays L[] and R[] + for i in range(0 , n1): + L[i] = arr[l + i] + + for j in range(0 , n2): + R[j] = arr[m + 1 + j] + + # Merge the temp arrays back into arr[l..r] + i = 0 # Initial index of first subarray + j = 0 # Initial index of second subarray + k = l # Initial index of merged subarray + + while i < n1 and j < n2 : + if L[i] <= R[j]: + arr[k] = L[i] + i += 1 + else: + arr[k] = R[j] + j += 1 + k += 1 + + # Copy the remaining elements of L[], if there + # are any + while i < n1: + arr[k] = L[i] + i += 1 + k += 1 + + # Copy the remaining elements of R[], if there + # are any + while j < n2: + arr[k] = R[j] + j += 1 + k += 1 + +# l is for left index and r is right index of the +# sub-array of arr to be sorted +def mergeSort(arr,l,r): + if l < r: + + # Same as (l+r)//2, but avoids overflow for + # large l and h + m = (l+(r-1))//2 + + # Sort first and second halves + mergeSort(arr, l, m) + mergeSort(arr, m+1, r) + merge(arr, l, m, r) + + +# Driver code to test above +arr = [12, 11, 13, 5, 6, 7] +n = len(arr) +print ("Given array is") +for i in range(n): + print ("%d" %arr[i]), + +mergeSort(arr,0,n-1) +print ("\n\nSorted array is") +for i in range(n): + print ("%d" %arr[i]), From 36abd1dbca39d081b688689aacf054f7f4c8518b Mon Sep 17 00:00:00 2001 From: dhanrajchavan1 <72387618+dhanrajchavan1@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:08:08 +0530 Subject: [PATCH 369/781] Create ASCII Values --- ASCII Values | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 ASCII Values diff --git a/ASCII Values b/ASCII Values new file mode 100644 index 00000000..b1a25d84 --- /dev/null +++ b/ASCII Values @@ -0,0 +1,7 @@ +int main() +{ + char a; + prinf("Enter the character = "); + scanf("%c",&a); + printf("The Ascii value of Character %c = %d",a,a); +} From 11f34f789d85d2094ada4d2259e75697deb8e02a Mon Sep 17 00:00:00 2001 From: Project AM Date: Sat, 17 Oct 2020 14:38:36 +0700 Subject: [PATCH 370/781] Create find the minimum and maximum element of an Array --- ...he minimum and maximum element of an Array | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 find the minimum and maximum element of an Array diff --git a/find the minimum and maximum element of an Array b/find the minimum and maximum element of an Array new file mode 100644 index 00000000..fcb66969 --- /dev/null +++ b/find the minimum and maximum element of an Array @@ -0,0 +1,25 @@ +#include +using namespace std; + +int main() +{ + // Get the array + int arr[] = { 1, 45, 54, 71, 76, 12 }; + + // Compute the sizes + int n = sizeof(arr) / sizeof(arr[0]); + + // Print the array + cout << "Array: "; + for (int i = 0; i < n; i++) + cout << arr[i] << " "; + + // Find the minimum element + cout << "\nMin Element = " + << *min_element(arr, arr + n); + + // Find the maximum element + cout << "\nMax Element = " + << *max_element(arr, arr + n); + return 0; +} From 4e3586432edbec2ce1d671c121020c035042af7d Mon Sep 17 00:00:00 2001 From: Shivam Raj <49182562+shivam4312@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:08:45 +0530 Subject: [PATCH 371/781] Create Program to multiply 2D or 3D Matrices in c++ --- Program to multiply 2D or 3D Matrices in c++ | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Program to multiply 2D or 3D Matrices in c++ diff --git a/Program to multiply 2D or 3D Matrices in c++ b/Program to multiply 2D or 3D Matrices in c++ new file mode 100644 index 00000000..1f2fd1f9 --- /dev/null +++ b/Program to multiply 2D or 3D Matrices in c++ @@ -0,0 +1,70 @@ +#include +using namespace std; + +int main() +{ + int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k; + + cout << "Enter rows and columns for first matrix: "; + cin >> r1 >> c1; + cout << "Enter rows and columns for second matrix: "; + cin >> r2 >> c2; + + // If column of first matrix in not equal to row of second matrix, + // ask the user to enter the size of matrix again. + while (c1!=r2) + { + cout << "Error! column of first matrix not equal to row of second."; + + cout << "Enter rows and columns for first matrix: "; + cin >> r1 >> c1; + + cout << "Enter rows and columns for second matrix: "; + cin >> r2 >> c2; + } + + // Storing elements of first matrix. + cout << endl << "Enter elements of matrix 1:" << endl; + for(i = 0; i < r1; ++i) + for(j = 0; j < c1; ++j) + { + cout << "Enter element a" << i + 1 << j + 1 << " : "; + cin >> a[i][j]; + } + + // Storing elements of second matrix. + cout << endl << "Enter elements of matrix 2:" << endl; + for(i = 0; i < r2; ++i) + for(j = 0; j < c2; ++j) + { + cout << "Enter element b" << i + 1 << j + 1 << " : "; + cin >> b[i][j]; + } + + // Initializing elements of matrix mult to 0. + for(i = 0; i < r1; ++i) + for(j = 0; j < c2; ++j) + { + mult[i][j]=0; + } + + // Multiplying matrix a and b and storing in array mult. + for(i = 0; i < r1; ++i) + for(j = 0; j < c2; ++j) + for(k = 0; k < c1; ++k) + { + mult[i][j] += a[i][k] * b[k][j]; + } + + // Displaying the multiplication of two matrix. + cout << endl << "Output Matrix: " << endl; + for(i = 0; i < r1; ++i) + for(j = 0; j < c2; ++j) + { + cout << " " << mult[i][j]; + if(j == c2-1) + cout << endl; + } + + return 0; +} From 329ef55e0bfb718a35b4212fd0d1d0a486d3fac8 Mon Sep 17 00:00:00 2001 From: dhanrajchavan1 <72387618+dhanrajchavan1@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:09:05 +0530 Subject: [PATCH 372/781] Create Matrices Addition --- Matrices Addition | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Matrices Addition diff --git a/Matrices Addition b/Matrices Addition new file mode 100644 index 00000000..89a2fc40 --- /dev/null +++ b/Matrices Addition @@ -0,0 +1,39 @@ +#include +#define N 4 + +// This function adds A[][] and B[][], and stores +// the result in C[][] +void add(int A[][N], int B[][N], int C[][N]) +{ + int i, j; + for (i = 0; i < N; i++) + for (j = 0; j < N; j++) + C[i][j] = A[i][j] + B[i][j]; +} + +int main() +{ + int A[N][N] = { {1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4}}; + + int B[N][N] = { {1, 1, 1, 1}, + {2, 2, 2, 2}, + {3, 3, 3, 3}, + {4, 4, 4, 4}}; + + int C[N][N]; // To store result + int i, j; + add(A, B, C); + + printf("Result matrix is \n"); + for (i = 0; i < N; i++) + { + for (j = 0; j < N; j++) + printf("%d ", C[i][j]); + printf("\n"); + } + + return 0; +} From 02be82d303610666014b00a037a2bab9d30f5f7f Mon Sep 17 00:00:00 2001 From: dhanrajchavan1 <72387618+dhanrajchavan1@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:09:49 +0530 Subject: [PATCH 373/781] Create Binary to decimals --- Binary to decimals | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Binary to decimals diff --git a/Binary to decimals b/Binary to decimals new file mode 100644 index 00000000..baac2403 --- /dev/null +++ b/Binary to decimals @@ -0,0 +1,18 @@ +#include +#include +using namespace std; + +int main() +{ + long bi, deci = 0, j = 1, r; + cout << " Input a binary number: "; + cin>> bi; + while (bi != 0) + { + r = bi%10; + deci = deci + r*j; + j = j*2; + bi = bi/10; + } + cout<<" The decimal number: " << deci<<"\n"; +} From 6eb97908d6c2ef6b89d7965077c596b78304788f Mon Sep 17 00:00:00 2001 From: bhargava53929 <72983345+bhargava53929@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:20:04 +0530 Subject: [PATCH 374/781] Create plus minus --- plus minus | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 plus minus diff --git a/plus minus b/plus minus new file mode 100644 index 00000000..5a9ea052 --- /dev/null +++ b/plus minus @@ -0,0 +1,27 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(){ + int t; + float p=0,n=0,z=0; + scanf("%d",&t); + int arr[t]; + for(int i = 0; i < t;i++){ + scanf("%d",&arr[i]); + if(arr[i]>0) + p++; + else if(arr[i]<0) + n++; + else + z++; + } + printf("%.5f\n%.5f\n%.5f",(float)p/t,(float)n/t,(float)z/t); + return 0; +} From 4a9fd728370427c7804cca4b06297f4fec6919d1 Mon Sep 17 00:00:00 2001 From: Shivam Raj <49182562+shivam4312@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:44:31 +0530 Subject: [PATCH 375/781] Create Program to Find Factorial in c++ Optimized code for Program to Find Factorial in c++ --- Program to Find Factorial in c++ | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Program to Find Factorial in c++ diff --git a/Program to Find Factorial in c++ b/Program to Find Factorial in c++ new file mode 100644 index 00000000..810be643 --- /dev/null +++ b/Program to Find Factorial in c++ @@ -0,0 +1,13 @@ +#include +using namespace std; +int fact(int n) { + if ((n==0)||(n==1)) + return 1; + else + return n*fact(n-1); +} +int main() { + int n = 5; + cout<<"Factorial of "< Date: Sat, 17 Oct 2020 13:47:41 +0530 Subject: [PATCH 376/781] Triangle is equilateral, isosceles or scalene Python Program To Check a triangle is equilateral, isosceles or scalene --- Check a triangle is equilateral, isosceles or scalene | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Check a triangle is equilateral, isosceles or scalene diff --git a/Check a triangle is equilateral, isosceles or scalene b/Check a triangle is equilateral, isosceles or scalene new file mode 100644 index 00000000..d3c22251 --- /dev/null +++ b/Check a triangle is equilateral, isosceles or scalene @@ -0,0 +1,11 @@ +print("Input lengths of the triangle sides: ") +x = int(input("x: ")) +y = int(input("y: ")) +z = int(input("z: ")) + +if x == y == z: + print("Equilateral triangle") +elif x==y or y==z or z==x: + print("isosceles triangle") +else: + print("Scalene triangle") From 5b27746362abbc44fdbbaca60f7be0f5d59733bd Mon Sep 17 00:00:00 2001 From: Shivam Raj <49182562+shivam4312@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:47:59 +0530 Subject: [PATCH 377/781] Create Program To Convert Binary To Decimal Number in python most optimized code Program To Convert Binary To Decimal Number in python --- Program To Convert Binary To Decimal Number in python | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Program To Convert Binary To Decimal Number in python diff --git a/Program To Convert Binary To Decimal Number in python b/Program To Convert Binary To Decimal Number in python new file mode 100644 index 00000000..33e28128 --- /dev/null +++ b/Program To Convert Binary To Decimal Number in python @@ -0,0 +1,8 @@ +# Python3 program to convert +# binary to decimal +n = input("Enter the binary no. : ") + +# Convert n to base 2 +s = int(n, 2) + +print(s) From aa1f3a3f702d8ce8dfa85052b63f19a291841635 Mon Sep 17 00:00:00 2001 From: Shivam Raj <49182562+shivam4312@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:49:42 +0530 Subject: [PATCH 378/781] Create Program To Convert Binary To Decimal Number in c++ fully optimized and fast running code for Program To Convert Binary To Decimal Number in c++ --- Program To Convert Binary To Decimal Number in c++ | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Program To Convert Binary To Decimal Number in c++ diff --git a/Program To Convert Binary To Decimal Number in c++ b/Program To Convert Binary To Decimal Number in c++ new file mode 100644 index 00000000..1922ea16 --- /dev/null +++ b/Program To Convert Binary To Decimal Number in c++ @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + char binaryNumber[] = "1001"; + + cout << stoi(binaryNumber, 0, 2); + + return 0; +} From 13892a5b343b6f8f9478b2ab1234f8f26b1282dd Mon Sep 17 00:00:00 2001 From: Tinku-Singh <73016166+Tinku-Singh@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:50:09 +0530 Subject: [PATCH 379/781] ASCII Value Of Character Python Program To Find ASCII Value Of Character --- Find ASCII Value of Character | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Find ASCII Value of Character diff --git a/Find ASCII Value of Character b/Find ASCII Value of Character new file mode 100644 index 00000000..7fb487ab --- /dev/null +++ b/Find ASCII Value of Character @@ -0,0 +1,4 @@ +# Program to find the ASCII value of the given character + +c = 'p' +print("The ASCII value of '" + c + "' is", ord(c)) From bbf9ede7706e35f1e8d443d9d66245631deb9d5b Mon Sep 17 00:00:00 2001 From: Tinku-Singh <73016166+Tinku-Singh@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:51:33 +0530 Subject: [PATCH 380/781] Print the Fibonacci sequence Python Program To Print the Fibonacci sequence --- Print the Fibonacci sequence | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Print the Fibonacci sequence diff --git a/Print the Fibonacci sequence b/Print the Fibonacci sequence new file mode 100644 index 00000000..9f6b1b3d --- /dev/null +++ b/Print the Fibonacci sequence @@ -0,0 +1,23 @@ +# Program to display the Fibonacci sequence up to n-th term + +nterms = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + # update values + n1 = n2 + n2 = nth + count += 1 From ab834259087cf69010d65f41a093752774bfb8ad Mon Sep 17 00:00:00 2001 From: Tinku-Singh <73016166+Tinku-Singh@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:53:39 +0530 Subject: [PATCH 381/781] Calculate Power of a Number Paython Program To Calculate Power of a Number --- Find power of any number | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Find power of any number diff --git a/Find power of any number b/Find power of any number new file mode 100644 index 00000000..59f8573c --- /dev/null +++ b/Find power of any number @@ -0,0 +1,7 @@ +import math + +base_number = float(input("Enter the base number")) +exponent = float(input("Enter the exponent")) + +power = math.pow(base_number,exponent) +print("Power is =",power) From 23f99de5ea519443e0bd94dec425655ab72dc200 Mon Sep 17 00:00:00 2001 From: Shivam Raj <49182562+shivam4312@users.noreply.github.com> Date: Sat, 17 Oct 2020 13:54:18 +0530 Subject: [PATCH 382/781] Create Create Program to Print Leap Years using java most efficient and optimized code to Create Program to Print Leap Years using java --- Create Program to Print Leap Years using java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Create Program to Print Leap Years using java diff --git a/Create Program to Print Leap Years using java b/Create Program to Print Leap Years using java new file mode 100644 index 00000000..24aeeeb9 --- /dev/null +++ b/Create Program to Print Leap Years using java @@ -0,0 +1,31 @@ +import java.util.Scanner; + +public class PrintLeapYear { + + public static void main(String[] args) { + + int startYear, endYear, i; + + //create a scanner object to get the input + Scanner in = new Scanner(System.in); + + //get the start year from user + System.out.print("Enter the Start Year:"); + startYear = in.nextInt(); + + //get the end year from user + System.out.print("Enter the End Year:"); + endYear = in.nextInt(); + + //print the leap years + System.out.println("Leap years:"); + + //loop through between start and end year + for (i = startYear; i <= endYear; i++) { + + //find the year is leap year or not, if yes print it + if ( (0 == i % 4) && (0 != i % 100) || (0 == i % 400) ){ + System.out.println(i); + } + } +} From bc1cf23877537719e32bf36faccc2438c3963b0e Mon Sep 17 00:00:00 2001 From: bhargava53929 <72983345+bhargava53929@users.noreply.github.com> Date: Sat, 17 Oct 2020 14:07:15 +0530 Subject: [PATCH 383/781] Create string length --- string length | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 string length diff --git a/string length b/string length new file mode 100644 index 00000000..6db6b67e --- /dev/null +++ b/string length @@ -0,0 +1,11 @@ +#include +int main() +{ + char s[100]; + int l; + scanf("%s",&s); + l=strlen(s); + printf("%d",l); + return 0; + } + From 9686128e769e21d3f14b55bd1d562c84876df786 Mon Sep 17 00:00:00 2001 From: Abhay Agrahary Date: Sat, 17 Oct 2020 14:08:11 +0530 Subject: [PATCH 384/781] Create Program to print all prime numbers in given range optimized code for printing prime number for hactoberfest --- ... to print all prime numbers in given range | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Program to print all prime numbers in given range diff --git a/Program to print all prime numbers in given range b/Program to print all prime numbers in given range new file mode 100644 index 00000000..1d875ac8 --- /dev/null +++ b/Program to print all prime numbers in given range @@ -0,0 +1,33 @@ +#include +#include +#include +#include + +using namespace std; + +bool isPrime(int n) +{ + // Corner case + if (n <= 1) + return false; + + // Check from 2 to n-1 + for (int i = 2; i < n; i++) + if (n % i == 0) + return false; + + return true; +} +int main() +{ + int n,i; + cin>>n; + + for(i=2;i<=n;i++) + { + + if(isPrime(i)) + cout< Date: Sat, 17 Oct 2020 14:12:15 +0530 Subject: [PATCH 385/781] Create Program to convert binary digits to octal digits optimizing code for conversion of binary digits into ocatal digits for hactoberfest --- ...m to convert binary digits to octal digits | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Program to convert binary digits to octal digits diff --git a/Program to convert binary digits to octal digits b/Program to convert binary digits to octal digits new file mode 100644 index 00000000..a300ba46 --- /dev/null +++ b/Program to convert binary digits to octal digits @@ -0,0 +1,28 @@ +#include +#include +#include +#include + +using namespace std; + +int main() +{ + int b,d=0,i=0,s; + cin>>b; + while(b!=0) + { + + s=b%10; + b/=10; + if(s!=0&&s!=1) + { + break; + } + d=d+(s*pow(8,i++)); + } + if(s!=0&&s!=1) + cout<<"not a binary"; + else + cout<<"Decimal Conversion is : "< Date: Sat, 17 Oct 2020 14:20:15 +0530 Subject: [PATCH 386/781] Create Program to print n number of Fibonnaci Series optimizing code for printing fabionacci series of n numbers for hacttoberfest --- Program to print n number of Fibonnaci Series | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Program to print n number of Fibonnaci Series diff --git a/Program to print n number of Fibonnaci Series b/Program to print n number of Fibonnaci Series new file mode 100644 index 00000000..67b69f3c --- /dev/null +++ b/Program to print n number of Fibonnaci Series @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +using namespace std; + +int main() +{ + int n,f=0,s=1,t,i; + cin>>n; + cout< Date: Sat, 17 Oct 2020 14:34:01 +0530 Subject: [PATCH 387/781] Create Hacktoberfest: Program To Check whether a Triangle is Equilateral, Isosceles or Scalene --- ...angle is Equilateral, Isosceles or Scalene | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Hacktoberfest: Program To Check whether a Triangle is Equilateral, Isosceles or Scalene diff --git a/Hacktoberfest: Program To Check whether a Triangle is Equilateral, Isosceles or Scalene b/Hacktoberfest: Program To Check whether a Triangle is Equilateral, Isosceles or Scalene new file mode 100644 index 00000000..9ce19b97 --- /dev/null +++ b/Hacktoberfest: Program To Check whether a Triangle is Equilateral, Isosceles or Scalene @@ -0,0 +1,32 @@ +// C++ program for the above approach +#include +using namespace std; + +// Function to check if the triangle +// is equilateral or isosceles or scalene +void checkTriangle(int x, int y, int z) +{ + + // Check for equilateral triangle + if (x == y && y == z) + cout << "Equilateral Triangle"; + + // Check for isoceles triangle + else if (x == y || y == z || z == x) + cout << "Isoceles Triangle"; + + // Otherwise scalene triangle + else + cout << "Scalene Triangle"; +} + +// Driver Code +int main() +{ + + // Given sides of triangle + int x = 8, y = 7, z = 9; + + // Function call + checkTriangle(x, y, z); +} From 56e3f6d580562a01a8728c799b89b8c1f1380364 Mon Sep 17 00:00:00 2001 From: Sakshi Date: Sat, 17 Oct 2020 14:34:22 +0530 Subject: [PATCH 388/781] Remove linked list elements of particular value in C++. If the list is 1->2->3->4 and value to be removed in 3 then list will get converted to 1->2->4 with this program. This is written in C++. --- ...linked list elements of a particular value | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Remove linked list elements of a particular value diff --git a/Remove linked list elements of a particular value b/Remove linked list elements of a particular value new file mode 100644 index 00000000..1c01ad93 --- /dev/null +++ b/Remove linked list elements of a particular value @@ -0,0 +1,48 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + ListNode* removeElements(ListNode* head, int val) { + ListNode * temp = head, *prev = NULL; + if(head == NULL) + { + return head; + } + if(head->next == NULL && temp->val == val) + { + head = temp->next; + return NULL; + + } + //For handling cases when the particular value elements come in first positions, as then head needs to be changed to remove those elements. For example [1,1,1,1], val = 1 + while(head && head->val == val) + { + head = head->next; + } + temp = head; + //If an element is equal to the value then set the address in the previous node as the address of next node. + while(temp != NULL) + { + if(temp->val == val) + { + prev->next = temp->next; + temp = temp->next; + } + else + { + prev = temp; + temp = temp->next; + } + } + return head; + //Modified linked list would be returned. + } +}; From 2f90675e234f53f695a5886de7c38f1f8e676592 Mon Sep 17 00:00:00 2001 From: Sakshi Date: Sat, 17 Oct 2020 14:39:16 +0530 Subject: [PATCH 389/781] C++ program to merge two sorted lists By this program we can merge two sorted linked lists, like for example we have 1->3->5 and 2->4 then result new list would be 1->2->3->4->5. --- Merge two sorted linked lists | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Merge two sorted linked lists diff --git a/Merge two sorted linked lists b/Merge two sorted linked lists new file mode 100644 index 00000000..b6fb941e --- /dev/null +++ b/Merge two sorted linked lists @@ -0,0 +1,51 @@ +/** + * Definition for singly-linked list. + * struct ListNode { + * int val; + * ListNode *next; + * ListNode() : val(0), next(nullptr) {} + * ListNode(int x) : val(x), next(nullptr) {} + * ListNode(int x, ListNode *next) : val(x), next(next) {} + * }; + */ +class Solution { +public: + ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { + ListNode *newlist = new ListNode(); + //Make a dummy node,now see if like whose value is lesser and then connect the new list with that node and move to the next node, we need to have three pointers one for each list! + ListNode* i = l1; + ListNode* j = l2; + ListNode* k = newlist; + //Iterating over both the lists and figuring out which element has to be joined in the new list. + while(i && j) + { + if(i->val > j->val) + { + k->next = j; + j = j->next; + k = k->next; + } + else + { + k->next = i; + i = i->next; + k = k->next; + } + } + + while(i) + { + k->next = i; + i = i->next; + k = k->next; + } + while(j) + { + k->next = j; + j = j->next; + k = k->next; + } + return newlist->next; + + } +}; From c794b15f45e55285e5c025964209e51986d538b7 Mon Sep 17 00:00:00 2001 From: Usha Kiran Melasthri <42317551+KiranDon@users.noreply.github.com> Date: Sat, 17 Oct 2020 14:41:22 +0530 Subject: [PATCH 390/781] Create Hacktoberfest: c Program to reverse the array --- Hacktoberfest: c Program to reverse the array | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Hacktoberfest: c Program to reverse the array diff --git a/Hacktoberfest: c Program to reverse the array b/Hacktoberfest: c Program to reverse the array new file mode 100644 index 00000000..76a5815d --- /dev/null +++ b/Hacktoberfest: c Program to reverse the array @@ -0,0 +1,30 @@ +#include +int main() +{ + int n, c, d, a[100], b[100]; + + printf("Enter the number of elements in array\n"); + scanf("%d", &n); + + printf("Enter array elements\n"); + + for (c = 0; c < n ; c++) + scanf("%d", &a[c]); + + // Copying elements into array b starting from the end of array a + + for (c = n - 1, d = 0; c >= 0; c--, d++) + b[d] = a[c]; + + // Copying reversed array into the original, we are modifying the original array. + + for (c = 0; c < n; c++) + a[c] = b[c]; + + printf("The array after reversal:\n"); + + for (c = 0; c < n; c++) + printf("%d\n", a[c]); + + return 0; +} From 3a298b3b39bb8369c2e5d868e3823c564715d06a Mon Sep 17 00:00:00 2001 From: Sakshi Date: Sat, 17 Oct 2020 14:43:46 +0530 Subject: [PATCH 391/781] Find unique number in an array containing all other numbers twice in linear time C++ program to find the single number in array where rest of numbers appear time in linear time using XOR operation on the elements. --- ... array which containing all other numbers twice | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Find unique number in an array which containing all other numbers twice diff --git a/Find unique number in an array which containing all other numbers twice b/Find unique number in an array which containing all other numbers twice new file mode 100644 index 00000000..e1350548 --- /dev/null +++ b/Find unique number in an array which containing all other numbers twice @@ -0,0 +1,14 @@ +//This is an linear time complexity solution.In this we have used the property of XOR that A^A = 0 and A^0 = A. +//So when we take XOR of all elements we will be left with the number that appears only one time. +class Solution { +public: + int singleNumber(vector& nums) { + int n = nums.size(); + int ans = nums[0]; + for(int i = 1;i Date: Sat, 17 Oct 2020 14:48:43 +0530 Subject: [PATCH 392/781] C++ program to find number of unique ways to climb stairs We can take 1 or 2 steps so the number of ways in which we can reach a level n is calculated by this cpp program. This uses dynamic programming to solve the problem and has linear time and space compexity. --- ...mber of unique ways to climb stairs in C++ | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Find number of unique ways to climb stairs in C++ diff --git a/Find number of unique ways to climb stairs in C++ b/Find number of unique ways to climb stairs in C++ new file mode 100644 index 00000000..56a7f44f --- /dev/null +++ b/Find number of unique ways to climb stairs in C++ @@ -0,0 +1,19 @@ +int climbStairs(int n) { + vector dp(n+1, 0); + //Using dynamic programming here to store the results of the subproblems in the vector dp and then using them to get to bigger problem. + //Base case + if(n == 0 || n == 1) + { + return 1; + } + dp[0] =1; + dp[1] = 1; + dp[2] = 2; + //There are two ways to reach a particular number i, we can either reach it from i-1 or i-2 so adding the possibilities of both. + for(int i=3;i<=n;i++) + { + dp[i] = dp[i-1]+dp[i-2]; + } + + return dp[n]; + } From 2a8ac7de1981fa3554ece3795eb7f0b29f33be30 Mon Sep 17 00:00:00 2001 From: DewniEkanayaka <52849506+DewniEkanayaka@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:07:39 +0530 Subject: [PATCH 393/781] Create Java Program to find factorial of a number Optimized Java program to display the factorial value of any given number --- Java Program to find factorial of a number | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Java Program to find factorial of a number diff --git a/Java Program to find factorial of a number b/Java Program to find factorial of a number new file mode 100644 index 00000000..cc269198 --- /dev/null +++ b/Java Program to find factorial of a number @@ -0,0 +1,20 @@ +import java.util.Scanner; + +public class Factorial { + //method to get factorial value of a number + public static int calcFactorial(int number){ + int factorial = 1; + for(int i=1;i<=number;i++){ + factorial=factorial*i; + } + return factorial; + } + + public static void main(String []args){ + int number; + Scanner sc= new Scanner(System.in); + System.out.print("Enter number : "); + number = sc.nextInt(); + System.out.println("Factorial Value of " +number+ " is : "+calcFactorial(number)); + } +} From b0c12d9e4139fada67a21b3425f89abb9b55fc00 Mon Sep 17 00:00:00 2001 From: DewniEkanayaka <52849506+DewniEkanayaka@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:30:19 +0530 Subject: [PATCH 394/781] Create Java program to calculate sum of numbers in a given array Optimized Java Program where user can define the array and get the sum of elements in it --- ... calculate sum of numbers in a given array | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Java program to calculate sum of numbers in a given array diff --git a/Java program to calculate sum of numbers in a given array b/Java program to calculate sum of numbers in a given array new file mode 100644 index 00000000..e1044845 --- /dev/null +++ b/Java program to calculate sum of numbers in a given array @@ -0,0 +1,28 @@ +import java.util.Scanner; + +public class SumOfArray { + //method to get sum of numbers in a given array + public static int calcSum(int array[]){ + int sum = 0; + for(int i=0;i Date: Sat, 17 Oct 2020 15:39:22 +0530 Subject: [PATCH 395/781] Multiply Two Matrices Using Multi-dimensional Arrays C Program to Multiply Two Matrices Using Multi-dimensional Arrays --- ...wo Matrices Using Multi-dimensional Arrays | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Multiply Two Matrices Using Multi-dimensional Arrays diff --git a/Multiply Two Matrices Using Multi-dimensional Arrays b/Multiply Two Matrices Using Multi-dimensional Arrays new file mode 100644 index 00000000..def03f7b --- /dev/null +++ b/Multiply Two Matrices Using Multi-dimensional Arrays @@ -0,0 +1,82 @@ +#include + +// function to get matrix elements entered by the user +void getMatrixElements(int matrix[][10], int row, int column) { + + printf("\nEnter elements: \n"); + + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("Enter a%d%d: ", i + 1, j + 1); + scanf("%d", &matrix[i][j]); + } + } +} + +// function to multiply two matrices +void multiplyMatrices(int first[][10], + int second[][10], + int result[][10], + int r1, int c1, int r2, int c2) { + + // Initializing elements of matrix mult to 0. + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + result[i][j] = 0; + } + } + + // Multiplying first and second matrices and storing it in result + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + for (int k = 0; k < c1; ++k) { + result[i][j] += first[i][k] * second[k][j]; + } + } + } +} + +// function to display the matrix +void display(int result[][10], int row, int column) { + + printf("\nOutput Matrix:\n"); + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("%d ", result[i][j]); + if (j == column - 1) + printf("\n"); + } + } +} + +int main() { + int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2; + printf("Enter rows and column for the first matrix: "); + scanf("%d %d", &r1, &c1); + printf("Enter rows and column for the second matrix: "); + scanf("%d %d", &r2, &c2); + + // Taking input until + // 1st matrix columns is not equal to 2nd matrix row + while (c1 != r2) { + printf("Error! Enter rows and columns again.\n"); + printf("Enter rows and columns for the first matrix: "); + scanf("%d%d", &r1, &c1); + printf("Enter rows and columns for the second matrix: "); + scanf("%d%d", &r2, &c2); + } + + // get elements of the first matrix + getMatrixElements(first, r1, c1); + + // get elements of the second matrix + getMatrixElements(second, r2, c2); + + // multiply two matrices. + multiplyMatrices(first, second, result, r1, c1, r2, c2); + + // display the result + display(result, r1, c2); + + return 0; +} From 379d4201b0b94cca8a4764245a1e0bbe6938cc80 Mon Sep 17 00:00:00 2001 From: shriraamm <66256231+shriraamm@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:40:00 +0530 Subject: [PATCH 396/781] Create find smallest element in the array Optimized code for finding smallest element in an array using python. --- find smallest element in the array | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 find smallest element in the array diff --git a/find smallest element in the array b/find smallest element in the array new file mode 100644 index 00000000..50697dc5 --- /dev/null +++ b/find smallest element in the array @@ -0,0 +1,7 @@ +lst = [] +num = int(input("Enter the size of the array: ")) +print("Enter the array elements: ") +for n in range(num): + numbers = int(input()) + lst.append(numbers) +print("The smallest element of the given list is:", min(lst)) From 34106840e4859852809f7c588d3c3585e93887b9 Mon Sep 17 00:00:00 2001 From: shah krupali <60919462+krupalishah5123@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:40:50 +0530 Subject: [PATCH 397/781] Create Find length of string using python code for finding the length of the string using a loop in python. --- Find length of string using python | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Find length of string using python diff --git a/Find length of string using python b/Find length of string using python new file mode 100644 index 00000000..ce705762 --- /dev/null +++ b/Find length of string using python @@ -0,0 +1,9 @@ +def findLen(str): + counter = 0 + for i in str: + counter += 1 + return counter + + +str = "Krupali" +print(findLen(str)) From 05c2da225f0899d55cf6cd0cbfeb0ee301fc845d Mon Sep 17 00:00:00 2001 From: Vikash Choudhary <73019201+Meetjaat321@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:44:20 +0530 Subject: [PATCH 398/781] Convert Binary Number to Decimal and vice-versa C Program to Convert Binary Number to Decimal and vice-versa --- Convert Binary Number to Decimal | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Convert Binary Number to Decimal diff --git a/Convert Binary Number to Decimal b/Convert Binary Number to Decimal new file mode 100644 index 00000000..6b73a730 --- /dev/null +++ b/Convert Binary Number to Decimal @@ -0,0 +1,21 @@ +#include +#include +int convert(long long n); +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +int convert(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From d4ec2924cadffbf804a873fd97bcb19f597108a7 Mon Sep 17 00:00:00 2001 From: poojajaware <73019463+poojajaware@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:44:58 +0530 Subject: [PATCH 399/781] Create bubbleSort.java --- bubbleSort.java | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 bubbleSort.java diff --git a/bubbleSort.java b/bubbleSort.java new file mode 100644 index 00000000..bed82a77 --- /dev/null +++ b/bubbleSort.java @@ -0,0 +1,42 @@ + +next →← prev +Bubble Sort in Java +We can create a java program to sort array elements using bubble sort. Bubble sort algorithm is known as the simplest sorting algorithm. + +In bubble sort algorithm, array is traversed from first element to last element. Here, current element is compared with the next element. If current element is greater than the next element, it is swapped. + +public class BubbleSortExample { + static void bubbleSort(int[] arr) { + int n = arr.length; + int temp = 0; + for(int i=0; i < n; i++){ + for(int j=1; j < (n-i); j++){ + if(arr[j-1] > arr[j]){ + //swap elements + temp = arr[j-1]; + arr[j-1] = arr[j]; + arr[j] = temp; + } + + } + } + + } + public static void main(String[] args) { + int arr[] ={3,60,35,2,45,320,5}; + + System.out.println("Array Before Bubble Sort"); + for(int i=0; i < arr.length; i++){ + System.out.print(arr[i] + " "); + } + System.out.println(); + + bubbleSort(arr);//sorting array elements using bubble sort + + System.out.println("Array After Bubble Sort"); + for(int i=0; i < arr.length; i++){ + System.out.print(arr[i] + " "); + } + + } +} From 72367b0fe3424f3c952e61accd2b3ee0a2cc7b5e Mon Sep 17 00:00:00 2001 From: Vikash Choudhary <73019201+Meetjaat321@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:48:25 +0530 Subject: [PATCH 400/781] Display Fibonacci Sequence C Program to Display Fibonacci Sequence --- print Fibonnaci Series using C | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 print Fibonnaci Series using C diff --git a/print Fibonnaci Series using C b/print Fibonnaci Series using C new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/print Fibonnaci Series using C @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 4966046e225e8c906c998e79ab994502d4dffc01 Mon Sep 17 00:00:00 2001 From: DewniEkanayaka <52849506+DewniEkanayaka@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:49:53 +0530 Subject: [PATCH 401/781] Create Java Program to find the largest element in a given array Optimized code to find and print the largest element in a given array --- ... find the largest element in a given array | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Java Program to find the largest element in a given array diff --git a/Java Program to find the largest element in a given array b/Java Program to find the largest element in a given array new file mode 100644 index 00000000..f593401f --- /dev/null +++ b/Java Program to find the largest element in a given array @@ -0,0 +1,31 @@ +import java.util.Scanner; + +public class LargestElement { + //method to get the largest element in a given array + public static int findLargestElement(int array[]){ + int largest = 0; + for(int i=0;i largest) + { + largest = array[i]; + } + } + return largest; + } + + public static void main(String []args){ + int elementCount,number; + Scanner sc= new Scanner(System.in); + System.out.print("Enter number of elements in the array : "); + elementCount = sc.nextInt(); + int array[] = new int[elementCount]; + for(int i = 0; i < elementCount; i++) + { + System.out.print("Enter number " +(i+1) +": "); + number = sc.nextInt(); + array[i] = number; + } + + System.out.println("Largest element in the array is : "+findLargestElement(array)); + } +} From 9dac25ff8eb87d5273e56c5e8eabe050e6ca0472 Mon Sep 17 00:00:00 2001 From: poojajaware <73019463+poojajaware@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:50:35 +0530 Subject: [PATCH 402/781] Create interface_in_java.java --- interface_in_java.java | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 interface_in_java.java diff --git a/interface_in_java.java b/interface_in_java.java new file mode 100644 index 00000000..f5576b4b --- /dev/null +++ b/interface_in_java.java @@ -0,0 +1,42 @@ + +// A simple interface +interface Player +{ + final int id = 10; + int move(); +} +//To implement an interface we use keyword: implements + + +// Java program to demonstrate working of +// interface. +import java.io.*; + +// A simple interface +interface In1 +{ + // public, static and final + final int a = 10; + + // public and abstract + void display(); +} + +// A class that implements the interface. +class TestClass implements In1 +{ + // Implementing the capabilities of + // interface. + public void display() + { + System.out.println("Geek"); + } + + // Driver Code + public static void main (String[] args) + { + TestClass t = new TestClass(); + t.display(); + System.out.println(a); + } +} From 66c4f057bf9242e71cc4bc3323e563bc7874c80e Mon Sep 17 00:00:00 2001 From: Vikash Choudhary <73019201+Meetjaat321@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:51:32 +0530 Subject: [PATCH 403/781] Calculate the Power of a Number Java Program to Calculate the Power of a Number --- the Power of a Number | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 the Power of a Number diff --git a/the Power of a Number b/the Power of a Number new file mode 100644 index 00000000..f4b492e2 --- /dev/null +++ b/the Power of a Number @@ -0,0 +1,17 @@ +public class Power { + + public static void main(String[] args) { + + int base = 3, exponent = 4; + + long result = 1; + + while (exponent != 0) + { + result *= base; + --exponent; + } + + System.out.println("Answer = " + result); + } +} From 6d4022c03e2512e3109755c3b097d98a73ef78cd Mon Sep 17 00:00:00 2001 From: shah krupali <60919462+krupalishah5123@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:54:41 +0530 Subject: [PATCH 404/781] Create Program find factorial of number Here I code factorial using the while loop in Java. --- Program find factorial of number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Program find factorial of number diff --git a/Program find factorial of number b/Program find factorial of number new file mode 100644 index 00000000..d3f4b213 --- /dev/null +++ b/Program find factorial of number @@ -0,0 +1,14 @@ +public class Factorial { + + public static void main(String[] args) { + + int n = 5, i = 1; + long factorial = 1; + while(i <= n) + { + factorial *= i; + i++; + } + System.out.printf("Factorial of %d = %d", n, factorial); + } +} From 47ac9bf555908e3019b092ce4b8c1d75e6a57ec1 Mon Sep 17 00:00:00 2001 From: DewniEkanayaka <52849506+DewniEkanayaka@users.noreply.github.com> Date: Sat, 17 Oct 2020 15:58:10 +0530 Subject: [PATCH 405/781] Create Java Program to find the smallest element in a given array Optimized program to find and print the smallest element of any given array --- ...find the smallest element in a given array | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Java Program to find the smallest element in a given array diff --git a/Java Program to find the smallest element in a given array b/Java Program to find the smallest element in a given array new file mode 100644 index 00000000..3c51d4e7 --- /dev/null +++ b/Java Program to find the smallest element in a given array @@ -0,0 +1,31 @@ +import java.util.Scanner; + +public class SmallestElement { + //method to get the smallest element in a given array + public static int findSmallestElement(int array[]){ + int smallest = array[0]; + for(int i=0;i Date: Sat, 17 Oct 2020 16:00:48 +0530 Subject: [PATCH 406/781] Find Factorial of Number Python Program to Find Factorial of Number --- Python Program to Find Factorial of Number | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Python Program to Find Factorial of Number diff --git a/Python Program to Find Factorial of Number b/Python Program to Find Factorial of Number new file mode 100644 index 00000000..03a704de --- /dev/null +++ b/Python Program to Find Factorial of Number @@ -0,0 +1,23 @@ +# This Python Program finds the factorial of a number + +def factorial(num): + """This is a recursive function that calls + itself to find the factorial of given number""" + if num == 1: + return num + else: + return num * factorial(num - 1) + + +# We will find the factorial of this number +num = int(input("Enter a Number: ")) + +# if input number is negative then return an error message +# elif the input number is 0 then display 1 as output +# else calculate the factorial by calling the user defined function +if num < 0: + print("Factorial cannot be found for negative numbers") +elif num == 0: + print("Factorial of 0 is 1") +else: + print("Factorial of", num, "is: ", factorial(num)) From 8154b7677559cb3e09b58eb7aa432c7ab4cc03b9 Mon Sep 17 00:00:00 2001 From: shah krupali <60919462+krupalishah5123@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:01:25 +0530 Subject: [PATCH 407/781] Create Program to find leap years in given range Here I code in python. to find the leap year in the given range. --- Program to find leap years in given range | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Program to find leap years in given range diff --git a/Program to find leap years in given range b/Program to find leap years in given range new file mode 100644 index 00000000..1d50717f --- /dev/null +++ b/Program to find leap years in given range @@ -0,0 +1,20 @@ +def calNum(year) : + + return (year // 4) - (year // 100) + (year // 400); + + +def leapNum(l, r) : + + l -= 1; + num1 = calNum(r); + num2 = calNum(l); + print(num1 - num2); + + +if __name__ == "__main__" : + + l1 = 1; r1 = 400; + leapNum(l1, r1); + + l2 = 400; r2 = 2000; + leapNum(l2, r2); From 4b20b41d49512fc2cdc75a23136f577a975c59f1 Mon Sep 17 00:00:00 2001 From: Shashi-Bhushan Date: Sat, 17 Oct 2020 16:03:11 +0530 Subject: [PATCH 408/781] Identity Matrix A matrix is said to be an identity matrix if it is a square matrix in which elements of principle diagonal are ones, and the rest of the elements are zeroes. --- ... a Program to find Identity Matrix in Java | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Write a Program to find Identity Matrix in Java diff --git a/Write a Program to find Identity Matrix in Java b/Write a Program to find Identity Matrix in Java new file mode 100644 index 00000000..b8858177 --- /dev/null +++ b/Write a Program to find Identity Matrix in Java @@ -0,0 +1,47 @@ +public class IdentityMatrix +{ + public static void main(String[] args) { + int rows, cols; + boolean flag = true; + + //Initialize matrix a + int a[][] = { + {1, 0, 0}, + {0, 1, 0}, + {0, 0, 1} + }; + + //Calculates the number of rows and columns present in the given matrix + + rows = a.length; + cols = a[0].length; + + //Checks whether given matrix is a square matrix or not + if(rows != cols){ + System.out.println("Matrix should be a square matrix"); + } + else { + //Checks if diagonal elements are equal to 1 and rest of elements are 0 + for(int i = 0; i < rows; i++){ + for(int j = 0; j < cols; j++){ + if(i == j && a[i][j] != 1){ + flag = false; + break; + } + if(i != j && a[i][j] != 0){ + flag = false; + break; + } + } + } + + if(flag) + System.out.println("Given matrix is an identity matrix"); + else + System.out.println("Given matrix is not an identity matrix"); + } + } +} +Output: + +Given matrix is an identity matrix From 169eb8c3e1b6ee9d9e3764d81350cd5e06f9d541 Mon Sep 17 00:00:00 2001 From: shah krupali <60919462+krupalishah5123@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:10:07 +0530 Subject: [PATCH 409/781] Create program to calculate the power of num Here I code to find the power of any base with any exponential.I code it in the C language. --- program to calculate the power of num | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 program to calculate the power of num diff --git a/program to calculate the power of num b/program to calculate the power of num new file mode 100644 index 00000000..e019a0a9 --- /dev/null +++ b/program to calculate the power of num @@ -0,0 +1,16 @@ +#include +int main() { + int b, ex; + long long result = 1; + printf("Enter a base number: "); + scanf("%d", &b); + printf("Enter an exponent: "); + scanf("%d", &ex); + + while (ex != 0) { + result *= b; + --exp; + } + printf("Answer = %lld", result); + return 0; +} From e2f91cb2f4a3cc2eda4a33f36b416c4b2142386f Mon Sep 17 00:00:00 2001 From: Sandeep Jat <73019163+Sandeep-Jat@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:14:51 +0530 Subject: [PATCH 410/781] Find largest element in an array Python Program to find largest element in an array --- ...rogram to find largest element in an array | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Python Program to find largest element in an array diff --git a/Python Program to find largest element in an array b/Python Program to find largest element in an array new file mode 100644 index 00000000..93776b51 --- /dev/null +++ b/Python Program to find largest element in an array @@ -0,0 +1,23 @@ +# Python3 program to find maximum +# in arr[] of size n + +# python function to find maximum +# in arr[] of size n +def largest(arr,n): + + # Initialize maximum element + max = arr[0] + + # Traverse array elements from second + # and compare every element with + # current max + for i in range(1, n): + if arr[i] > max: + max = arr[i] + return max + +# Driver Code +arr = [10, 324, 45, 90, 9808] +n = len(arr) +Ans = largest(arr,n) +print ("Largest in given array is",Ans) From a03b6644f57db13ae9d56ad85cdea8378a413cca Mon Sep 17 00:00:00 2001 From: Sandeep Jat <73019163+Sandeep-Jat@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:17:06 +0530 Subject: [PATCH 411/781] Print number of leap years from given list of years Python | Print number of leap years from given list of years --- ...ber of leap years from given list of years | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Python | Print number of leap years from given list of years diff --git a/Python | Print number of leap years from given list of years b/Python | Print number of leap years from given list of years new file mode 100644 index 00000000..cb6331dc --- /dev/null +++ b/Python | Print number of leap years from given list of years @@ -0,0 +1,22 @@ +# Python code to finding number of +# leap years in list of years. + +# Input list initialization +Input = [2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012] + +# Find whether it is leap year or not +def checkYear(year): + return (((year % 4 == 0) and + (year % 100 != 0)) or + (year % 400 == 0)) + +# Answer Initialization +Answer = 0 + +for elem in Input: + if checkYear(elem): + Answer = Answer + 1 + +# Printing +print("No of leap years are:", Answer) From f001b5237b18a08e217063c0abe7d60d20d881a8 Mon Sep 17 00:00:00 2001 From: Sandeep Jat <73019163+Sandeep-Jat@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:18:25 +0530 Subject: [PATCH 412/781] Python Program to find sum of array Python Program to find sum of array --- Python Program to find sum of array | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Python Program to find sum of array diff --git a/Python Program to find sum of array b/Python Program to find sum of array new file mode 100644 index 00000000..5280ddea --- /dev/null +++ b/Python Program to find sum of array @@ -0,0 +1,20 @@ +# Python 3 code to find sum +# of elements in given array +def _sum(arr,n): + + # return sum using sum + # inbuilt sum() function + return(sum(arr)) + +# driver function +arr=[] +# input values to list +arr = [12, 3, 4, 15] + +# calculating length of array +n = len(arr) + +ans = _sum(arr,n) + +# display sum +print ('Sum of the array is ', ans) From 41b009b76cf8bf55cbccaa547448a8e0ae783dbb Mon Sep 17 00:00:00 2001 From: Samiksha sandip sankar Date: Sat, 17 Oct 2020 16:20:54 +0530 Subject: [PATCH 413/781] Program to find lenght of a string in java This program is in java --- Java Program to find lenght of a string in java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Java Program to find lenght of a string in java diff --git a/Java Program to find lenght of a string in java b/Java Program to find lenght of a string in java new file mode 100644 index 00000000..b736fa6b --- /dev/null +++ b/Java Program to find lenght of a string in java @@ -0,0 +1,16 @@ + public class CountVowelConsonant { + public static void main(String[] args) { + + // String Handling + + char[] myArray = {'W' , 'e' , 'l' ,'c' , 'o' , 'm' ,'e'}; + + // Sequence of characters + String firstString = "Welcome"; + + System.out.println("lenght of a string" +" : " + firstString.length()); + + + } + } + From 177e6cdb857dc8e0ce541dd0018499b090ee3da9 Mon Sep 17 00:00:00 2001 From: omkar669 <46934695+omkar669@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:24:21 +0530 Subject: [PATCH 414/781] Create program to print Fibonacci series in python The program will display the Fibonacci sequence up to n-th term --- program to print Fibonacci series in python | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 program to print Fibonacci series in python diff --git a/program to print Fibonacci series in python b/program to print Fibonacci series in python new file mode 100644 index 00000000..9f6b1b3d --- /dev/null +++ b/program to print Fibonacci series in python @@ -0,0 +1,23 @@ +# Program to display the Fibonacci sequence up to n-th term + +nterms = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + # update values + n1 = n2 + n2 = nth + count += 1 From cfca65b101283640e8fbc0799bafce392f022e0f Mon Sep 17 00:00:00 2001 From: omkar669 <46934695+omkar669@users.noreply.github.com> Date: Sat, 17 Oct 2020 16:35:28 +0530 Subject: [PATCH 415/781] Create Find power of any number in python Python Program to find Power of a Number using While loop or using pow function --- Find power of any number in python | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Find power of any number in python diff --git a/Find power of any number in python b/Find power of any number in python new file mode 100644 index 00000000..6e55d0c0 --- /dev/null +++ b/Find power of any number in python @@ -0,0 +1,31 @@ +# Python Program to find Power of a Number using While loop + +number = int(input(" Please Enter any Positive Integer : ")) +exponent = int(input(" Please Enter Exponent Value : ")) + +power = 1 +i = 1 + +while(i <= exponent): + power = power * number + i = i + 1 + +print("The Result of {0} Power {1} = {2}".format(number, exponent, power)) + + + + + +# Python Program to find Power of a Number using pow function + +number = int(input(" Please Enter any Positive Integer : ")) +exponent = int(input(" Please Enter Exponent Value : ")) + +power = 1 +i = 1 + +while(i <= exponent): + power = power * number + i = i + 1 + +print("The Result of {0} Power {1} = {2}".format(number, exponent, power)) From 8a05e445b899a0e435418f6fafb737a05cc5186d Mon Sep 17 00:00:00 2001 From: Samiksha sandip sankar Date: Sat, 17 Oct 2020 16:55:03 +0530 Subject: [PATCH 416/781] count sum of all numbers in array in java This program is in java for loop --- ...to count sum of all numbers in array in java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Program to count sum of all numbers in array in java diff --git a/Program to count sum of all numbers in array in java b/Program to count sum of all numbers in array in java new file mode 100644 index 00000000..c5943f03 --- /dev/null +++ b/Program to count sum of all numbers in array in java @@ -0,0 +1,17 @@ +import java.util.Scanner; +public class prime +{ + public static void main(String args[]) + { + // Sum og all elements + int [] myFirstArray = {20, 19, 48, 7}; + + int sum = 0; + for (int i = 0; i< myFirstArray.length; i++){ + + sum += myFirstArray[i]; + System.out.println(myFirstArray[i]); + } + System.out.println("Sum of array : " + sum); + } +} From fce90ade4637ac87a7c8af2e1c94610339b0e0c8 Mon Sep 17 00:00:00 2001 From: hemanth-pj <69573607+hemanth-pj@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:26:56 +0000 Subject: [PATCH 417/781] Create sum of elements in the array Optimized Code For Getting Sum of Elements in an array quickly --- sum of elements in the array | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum of elements in the array diff --git a/sum of elements in the array b/sum of elements in the array new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/sum of elements in the array @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From 492d7d4c9d988ae2ddef18e621542540666554b7 Mon Sep 17 00:00:00 2001 From: royalgypson <72905188+royalgypson@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:02:32 +0530 Subject: [PATCH 418/781] Create Program to sort given array (ascending & descending) Optimized code sort given array (ascending & descending) --- ... sort given array (ascending & descending) | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Program to sort given array (ascending & descending) diff --git a/Program to sort given array (ascending & descending) b/Program to sort given array (ascending & descending) new file mode 100644 index 00000000..bf97cc28 --- /dev/null +++ b/Program to sort given array (ascending & descending) @@ -0,0 +1,53 @@ +#include +#include + + +int main() +{ + int a[100],n,i,j; + printf("Array size: "); + scanf("%d",&n); + printf("Elements: "); + + for(i=0;i a[i]) + { + int tmp = a[i]; + a[i] = a[j]; + a[j] = tmp; + } + } + } + printf("\n\nAscending : "); + for (int i = 0; i < n; i++) + { + printf(" %d ", a[i]); + } + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n; j++) + { + if (a[j] < a[i]) + { + int tmp = a[i]; + a[i] = a[j]; + a[j] = tmp; + } + } + } + printf("\n\nDescending : "); + for (int i = 0; i < n; i++) + { + printf(" %d ", a[i]); + } + + return 0; +getch(); +} From d8e499e44c6255ed2dcc5a37f0c7da5ba34defbc Mon Sep 17 00:00:00 2001 From: Ram Vivek Singh Date: Sat, 17 Oct 2020 17:04:27 +0530 Subject: [PATCH 419/781] Create Binary_to_Octal.py --- Binary_to_Octal.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Binary_to_Octal.py diff --git a/Binary_to_Octal.py b/Binary_to_Octal.py new file mode 100644 index 00000000..18c2f126 --- /dev/null +++ b/Binary_to_Octal.py @@ -0,0 +1,8 @@ +b_num = list(input("Input a binary number: ")) +value = 0 + +for i in range(len(b_num)): + digit = b_num.pop() + if digit == '1': + value = value + pow(2, i) +print("The decimal value of the number is", value) From 884ce4651be9cac06a1f9e35b07c2f8ad41de45b Mon Sep 17 00:00:00 2001 From: royalgypson <72905188+royalgypson@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:10:03 +0530 Subject: [PATCH 420/781] Create program to find length of a string Optimized code (to find length of a string). --- program to find length of a string | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 program to find length of a string diff --git a/program to find length of a string b/program to find length of a string new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/program to find length of a string @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 4fc0cf9c89ed3a72c8b5307e806a0b6431a2d1f6 Mon Sep 17 00:00:00 2001 From: Swadha-27 <48059712+Swadha-27@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:11:52 +0530 Subject: [PATCH 421/781] Find the largest element in the given array Finds the largest element in the array quickly --- Find the largest element in an array using PYTHON | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Find the largest element in an array using PYTHON diff --git a/Find the largest element in an array using PYTHON b/Find the largest element in an array using PYTHON new file mode 100644 index 00000000..029b98d8 --- /dev/null +++ b/Find the largest element in an array using PYTHON @@ -0,0 +1,9 @@ +def LargestNumber(arr): # function to find maximum element + max_element=arr[0] + for i in arr: + max_element=max(max_element,i) + return max_element + +arr=[4,5,1,3,6,0,8,2] #input array +ans=LargestNumber(arr) +print("Largest element is",ans) From 998188b1500b5b910ac017cef3d326bdcdc22256 Mon Sep 17 00:00:00 2001 From: royalgypson <72905188+royalgypson@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:13:44 +0530 Subject: [PATCH 422/781] Create Program to find smallest element in array Optimized code for (Program to find smallest element in array). --- Program to find smallest element in array | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Program to find smallest element in array diff --git a/Program to find smallest element in array b/Program to find smallest element in array new file mode 100644 index 00000000..5c5c4407 --- /dev/null +++ b/Program to find smallest element in array @@ -0,0 +1,26 @@ +#include + +int main() { + int a[30], i, num, smallest; + + printf("\nEnter no of elements :"); + scanf("%d", &num); + + + for (i = 0; i < num; i++) + scanf("%d", &a[i]); + + + smallest = a[0]; + + for (i = 0; i < num; i++) { + if (a[i] < smallest) { + smallest = a[i]; + } + } + + + printf("\nSmallest Element : %d", smallest); + + return (0); +} From be34abcff3b80290324338a356a6fd006eaf69e1 Mon Sep 17 00:00:00 2001 From: hemanth-pj <69573607+hemanth-pj@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:47:03 +0000 Subject: [PATCH 423/781] Create sum of elements in a array . --- sum of elements in a array | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum of elements in a array diff --git a/sum of elements in a array b/sum of elements in a array new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/sum of elements in a array @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From a1fde60cafc4b42f615d0ba91db002af47f18c34 Mon Sep 17 00:00:00 2001 From: Samiksha sandip sankar Date: Sat, 17 Oct 2020 17:18:55 +0530 Subject: [PATCH 424/781] Program to find factorial of number in java This program is in java --- Program to find factorial of number in java | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Program to find factorial of number in java diff --git a/Program to find factorial of number in java b/Program to find factorial of number in java new file mode 100644 index 00000000..e0b784fd --- /dev/null +++ b/Program to find factorial of number in java @@ -0,0 +1,13 @@ + public class FactorialProgram{ + public static void main(String args[]){ + + int num=5; + long factorial =1; + + while(num > 0) { + factorial *= num; + num--; + } + System.out.println("Factorial is : " +factorial); + } + } From d9252974f1b7cc561199a465cc1f9a4bfd490556 Mon Sep 17 00:00:00 2001 From: hemanth-pj <69573607+hemanth-pj@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:49:10 +0000 Subject: [PATCH 425/781] Create sum of elements in an array ... --- sum of elements in an array | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum of elements in an array diff --git a/sum of elements in an array b/sum of elements in an array new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/sum of elements in an array @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From 4dbca7b568ff02717764b0265c6e540d2eaad294 Mon Sep 17 00:00:00 2001 From: hemanth-pj <69573607+hemanth-pj@users.noreply.github.com> Date: Sat, 17 Oct 2020 11:50:44 +0000 Subject: [PATCH 426/781] Create sum of elements in an array. .... --- sum of elements in an array. | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum of elements in an array. diff --git a/sum of elements in an array. b/sum of elements in an array. new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/sum of elements in an array. @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From 9cc982dbfebfcdf7b6a628cdc65fbe8cb06fd57f Mon Sep 17 00:00:00 2001 From: vandit1920 <48818526+vandit1920@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:36:36 +0530 Subject: [PATCH 427/781] Create Program to find leap years Optimized and clear code to find to leap years --- Program to find leap years | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Program to find leap years diff --git a/Program to find leap years b/Program to find leap years new file mode 100644 index 00000000..b101f209 --- /dev/null +++ b/Program to find leap years @@ -0,0 +1,18 @@ +Input = [2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012] + +# Find whether it is leap year or not +def checkYear(year): + return (((year % 4 == 0) and + (year % 100 != 0)) or + (year % 400 == 0)) + +# Answer Initialization +Answer = 0 + +for elem in Input: + if checkYear(elem): + Answer = Answer + 1 + +# Printing +print("No of leap years are:", Answer) From 0c0b51d797c5c6ca00811a3629e5ea68430c7dfb Mon Sep 17 00:00:00 2001 From: Swadha-27 <48059712+Swadha-27@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:37:29 +0530 Subject: [PATCH 428/781] ASCII value of any character Short and simple code to print the ASCII value of a given character in python. --- Program to Print the ASCII value of any character In PYTHON | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Program to Print the ASCII value of any character In PYTHON diff --git a/Program to Print the ASCII value of any character In PYTHON b/Program to Print the ASCII value of any character In PYTHON new file mode 100644 index 00000000..0337b6a5 --- /dev/null +++ b/Program to Print the ASCII value of any character In PYTHON @@ -0,0 +1,4 @@ + +character="s" # input character +value=ord(character) # this function finds the ascii value +print("The ASCII value of the given character is",value) #o/p-115 From bb1c62705de55771c910997669256bcdbcdb4098 Mon Sep 17 00:00:00 2001 From: Ram Vivek Singh Date: Sat, 17 Oct 2020 17:49:29 +0530 Subject: [PATCH 429/781] Create Power_of_Number.py Created a python program to find the power of any number --- Power_of_Number.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Power_of_Number.py diff --git a/Power_of_Number.py b/Power_of_Number.py new file mode 100644 index 00000000..0ab65b6d --- /dev/null +++ b/Power_of_Number.py @@ -0,0 +1,8 @@ +import math + +number = int(input(" Please Enter any Positive Integer : ")) +exponent = int(input(" Please Enter Exponent Value : ")) + +power = math.pow(number, exponent) + +print("The Result of {0} Power {1} = {2}".format(number, exponent, power)) From 86d752b11587c436adae3e77674b151dd8e6a3e9 Mon Sep 17 00:00:00 2001 From: vandit1920 <48818526+vandit1920@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:50:46 +0530 Subject: [PATCH 430/781] Create Program to print prime numbers in given range using python Optimized Program to print prime numbers in given range using python --- ... print prime numbers in given range using python | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Program to print prime numbers in given range using python diff --git a/Program to print prime numbers in given range using python b/Program to print prime numbers in given range using python new file mode 100644 index 00000000..7f9e0749 --- /dev/null +++ b/Program to print prime numbers in given range using python @@ -0,0 +1,13 @@ +lower = 900 +upper = 1000 + +print("Prime numbers between", lower, "and", upper, "are:") + +for num in range(lower, upper + 1): + # all prime numbers are greater than 1 + if num > 1: + for i in range(2, num): + if (num % i) == 0: + break + else: + print(num) From e8ff879f8b0420e72a3d401899a6bb3686f27357 Mon Sep 17 00:00:00 2001 From: shouvikroy2130 <73024108+shouvikroy2130@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:53:10 +0530 Subject: [PATCH 431/781] Create total number of vowels and consonants in a string Program_java Java Program to count the total number of vowels and consonants in a string --- ...ls and consonants in a string Program_java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 total number of vowels and consonants in a string Program_java diff --git a/total number of vowels and consonants in a string Program_java b/total number of vowels and consonants in a string Program_java new file mode 100644 index 00000000..d06700c1 --- /dev/null +++ b/total number of vowels and consonants in a string Program_java @@ -0,0 +1,28 @@ +public class CountVowelConsonant { + public static void main(String[] args) { + + //Counter variable to store the count of vowels and consonant + int vCount = 0, cCount = 0; + + //Declare a string + String str = "This is a really simple sentence"; + + //Converting entire string to lower case to reduce the comparisons + str = str.toLowerCase(); + + for(int i = 0; i < str.length(); i++) { + //Checks whether a character is a vowel + if(str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u') { + //Increments the vowel counter + vCount++; + } + //Checks whether a character is a consonant + else if(str.charAt(i) >= 'a' && str.charAt(i)<='z') { + //Increments the consonant counter + cCount++; + } + } + System.out.println("Number of vowels: " + vCount); + System.out.println("Number of consonants: " + cCount); + } +} From 8ddf7509dc2a0163580e725e47e0925603db8171 Mon Sep 17 00:00:00 2001 From: Ram Vivek Singh Date: Sat, 17 Oct 2020 17:53:36 +0530 Subject: [PATCH 432/781] Create Fibonnaci_Series.py Created a Python Program to print Fibonacci Series --- Fibonnaci_Series.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Fibonnaci_Series.py diff --git a/Fibonnaci_Series.py b/Fibonnaci_Series.py new file mode 100644 index 00000000..759bed4a --- /dev/null +++ b/Fibonnaci_Series.py @@ -0,0 +1,12 @@ +n = int(input("Enter the value of 'n': ")) +a = 0 +b = 1 +sum = 0 +count = 1 +print("Fibonacci Series: ", end = " ") +while(count <= n): + print(sum, end = " ") + count += 1 + a = b + b = sum + sum = a + b From c2860f4caa0337d3f1830ac0cf1becf42b4d27c7 Mon Sep 17 00:00:00 2001 From: shouvikroy2130 <73024108+shouvikroy2130@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:54:32 +0530 Subject: [PATCH 433/781] Create add two given Matrices_Java Program to add two given Matrices --- add two given Matrices_Java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 add two given Matrices_Java diff --git a/add two given Matrices_Java b/add two given Matrices_Java new file mode 100644 index 00000000..21608f90 --- /dev/null +++ b/add two given Matrices_Java @@ -0,0 +1,28 @@ +public class JavaExample { + public static void main(String[] args) { + int rows = 2, columns = 4; + + // Declaring the two matrices as multi-dimensional arrays + int[][] MatrixA = { {1, 1, 1, 1}, {2, 3, 5, 2} }; + int[][] MatrixB = { {2, 3, 4, 5}, {2, 2, 4, -4} }; + + /* Declaring a matrix sum, that will be the sum of MatrixA + * and MatrixB, the sum matrix will have the same rows and + * columns as the given matrices. + */ + int[][] sum = new int[rows][columns]; + for(int i = 0; i < rows; i++) { + for (int j = 0; j < columns; j++) { + sum[i][j] = MatrixA[i][j] + MatrixB[i][j]; + } + } + // Displaying the sum matrix + System.out.println("Sum of the given matrices is: "); + for(int i = 0; i < rows; i++) { + for (int j = 0; j < columns; j++) { + System.out.print(sum[i][j] + " "); + } + System.out.println(); + } + } +} From 3160310deda553f7379674bf60c6db865a57e633 Mon Sep 17 00:00:00 2001 From: shouvikroy2130 <73024108+shouvikroy2130@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:56:40 +0530 Subject: [PATCH 434/781] Create Java_Program To Subtract Two Matrices Java Program To Subtract Two Matrices --- Java_Program To Subtract Two Matrices | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Java_Program To Subtract Two Matrices diff --git a/Java_Program To Subtract Two Matrices b/Java_Program To Subtract Two Matrices new file mode 100644 index 00000000..3afe988b --- /dev/null +++ b/Java_Program To Subtract Two Matrices @@ -0,0 +1,56 @@ + +class SUBMatrix +{ + public static void main(String args[]) + { + int row, col,i,j; + Scanner in = new Scanner(System.in); + + System.out.println("Enter the number of rows"); + row = in.nextInt(); + + System.out.println("Enter the number columns"); + col = in.nextInt(); + + int mat1[][] = new int[row][col]; + int mat2[][] = new int[row][col]; + int res[][] = new int[row][col]; + + System.out.println("Enter the elements of matrix1"); + + for ( i= 0 ; i < row ; i++ ) + { + + for ( j= 0 ; j < col ;j++ ) + mat1[i][j] = in.nextInt(); + + } + System.out.println("Enter the elements of matrix2"); + + + for ( i= 0 ; i < row ; i++ ) + { + + for ( j= 0 ; j < col ;j++ ) + mat2[i][j] = in.nextInt(); + + + } + + + for ( i= 0 ; i < row ; i++ ) + for ( j= 0 ; j < col ;j++ ) + res[i][j] = mat1[i][j] - mat2[i][j] ; + + System.out.println("subtract of two matrices:-"); + + for ( i= 0 ; i < row ; i++ ) + { + for ( j= 0 ; j < col ;j++ ) + System.out.print(res[i][j]+"\t"); + + System.out.println(); + } + + } +} From 9646e5396531a60ba7f5087e20797544c8b5fe24 Mon Sep 17 00:00:00 2001 From: shouvikroy2130 <73024108+shouvikroy2130@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:58:00 +0530 Subject: [PATCH 435/781] Create Calculate power of a number using a while loop_Java Program to find power of a number using a while loop --- ...te power of a number using a while loop_Java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Calculate power of a number using a while loop_Java diff --git a/Calculate power of a number using a while loop_Java b/Calculate power of a number using a while loop_Java new file mode 100644 index 00000000..f4b492e2 --- /dev/null +++ b/Calculate power of a number using a while loop_Java @@ -0,0 +1,17 @@ +public class Power { + + public static void main(String[] args) { + + int base = 3, exponent = 4; + + long result = 1; + + while (exponent != 0) + { + result *= base; + --exponent; + } + + System.out.println("Answer = " + result); + } +} From 43703e4beb7564c33797c7407ac290f048ed2166 Mon Sep 17 00:00:00 2001 From: Pratx-404 <32536443+Pratx-404@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:58:17 +0530 Subject: [PATCH 436/781] Create Program to find factorial --- Program to find factorial | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Program to find factorial diff --git a/Program to find factorial b/Program to find factorial new file mode 100644 index 00000000..802cf83e --- /dev/null +++ b/Program to find factorial @@ -0,0 +1,7 @@ +def factorial(n): + if n==0 or n==1: + return 1 + else: + return n*factorial(n-1) +n=int(input()) +print(factorial(n)) From 8362409e938d879fbf94173d0ade11ccb104f68c Mon Sep 17 00:00:00 2001 From: kapoor2427 <41826795+kapoor2427@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:02:15 +0530 Subject: [PATCH 437/781] Create Cpp Program to find power of any number Optimized code to find the power of any number (float or integer) --- Cpp Program to find power of any number | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Cpp Program to find power of any number diff --git a/Cpp Program to find power of any number b/Cpp Program to find power of any number new file mode 100644 index 00000000..bcf06940 --- /dev/null +++ b/Cpp Program to find power of any number @@ -0,0 +1,23 @@ +#include +using namespace std; + +float Calculatepower(float base, int exponent) { + float power = 1; + while (exponent != 0) { + power *= base; + --exponent; + } + return power; +} + + +int main() +{ + int exponent; + float base; + cin >> base; + cin >> exponent; + float power = Calculatepower(base, exponent); + cout << power; + return 0; +} From 9d1a04e6f7a5925bfc7f7dad8fc11b2e3e3cfd30 Mon Sep 17 00:00:00 2001 From: Swadha-27 <48059712+Swadha-27@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:04:30 +0530 Subject: [PATCH 438/781] Find the power of any number Short code to find the power of any number in Python. --- Find the power of any number in Python | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Find the power of any number in Python diff --git a/Find the power of any number in Python b/Find the power of any number in Python new file mode 100644 index 00000000..84d25459 --- /dev/null +++ b/Find the power of any number in Python @@ -0,0 +1,4 @@ +number=2 #given number +exponent=4 #given exponent +power=2**4 +print("The result power of",number,"raised to",exponent,"is",power) From 1b052ea82557d9c881eaaa1899ec234e884c0d9a Mon Sep 17 00:00:00 2001 From: biranchinarayan <70357046+biranchinarayan@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:05:15 +0530 Subject: [PATCH 439/781] Create hacktoberfest-2020 - program to find nCr and nPr [hacktoberfest-2020] a quality program for find nCr and nPr using function --- ...berfest-2020 - program to find nCr and nPr | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 hacktoberfest-2020 - program to find nCr and nPr diff --git a/hacktoberfest-2020 - program to find nCr and nPr b/hacktoberfest-2020 - program to find nCr and nPr new file mode 100644 index 00000000..7749ce38 --- /dev/null +++ b/hacktoberfest-2020 - program to find nCr and nPr @@ -0,0 +1,42 @@ +import java.util.Scanner; +class NcrAndNpr +{ + double fact(double n) + { + int i=1; + double fact=1; + while(i<=n) + { + fact=fact*i; + i++; + } + return fact; + } + double permutation(int n,int r ) + { + double per=fact(n)/fact(n-r); + return per; + } + double combination(int n,int r) + { + double com=fact(n)/(fact(n-r)*fact(r)); + return com; + } + public static void main(String arg[]) + { + NcrAndNpr p=new NcrAndNpr( ); + Scanner sc=new Scanner(System.in); + System.out.println("enter value of n"); + int n=sc.nextInt(); + System.out.println("enter value of r"); + int r=sc.nextInt(); + if(n>=r) + { + System.out.println("The value of "+n+"p"+r+" is : "+p.permutation(n,r)); + System.out.println("The value of "+n+"c"+r+" is : "+p.combination(n,r)); + } + else + System.out.println("n value should be greater than or equals to r value"); + + } +} From 36c21824d20cf5c68136a24d3ade822964e596d6 Mon Sep 17 00:00:00 2001 From: shalilmandidev <73024553+shalilmandidev@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:06:08 +0530 Subject: [PATCH 440/781] Create c_program Program to check triangle is equilateral, isosceles ot scalene Program to check triangle is equilateral, isosceles ot scalene --- ...angle is equilateral, isosceles ot scalene | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 c_program Program to check triangle is equilateral, isosceles ot scalene diff --git a/c_program Program to check triangle is equilateral, isosceles ot scalene b/c_program Program to check triangle is equilateral, isosceles ot scalene new file mode 100644 index 00000000..44d601a4 --- /dev/null +++ b/c_program Program to check triangle is equilateral, isosceles ot scalene @@ -0,0 +1,26 @@ +#include +int main() +{ + int sidea, sideb, sidec; //are three sides of a triangle + + /* + * Reads all sides of a triangle + */ + printf("Input three sides of triangle: "); + scanf("%d %d %d", &sidea, &sideb, &sidec); + + if(sidea==sideb && sideb==sidec) //check whether all sides are equal + { + printf("This is an equilateral triangle.\n"); + } + else if(sidea==sideb || sidea==sidec || sideb==sidec) //check whether two sides are equal + { + printf("This is an isosceles triangle.\n"); + } + else //check whether no sides are equal + { + printf("This is a scalene triangle.\n"); + } + + return 0; +} From 40b6a667d47030e291769ebf3804cb621cbd82c0 Mon Sep 17 00:00:00 2001 From: shalilmandidev <73024553+shalilmandidev@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:07:34 +0530 Subject: [PATCH 441/781] Create C_Program to Print ASCII Value Program to Print ASCII Value --- C_Program to Print ASCII Value | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 C_Program to Print ASCII Value diff --git a/C_Program to Print ASCII Value b/C_Program to Print ASCII Value new file mode 100644 index 00000000..a73b9c24 --- /dev/null +++ b/C_Program to Print ASCII Value @@ -0,0 +1,12 @@ +#include +int main() { + char c; + printf("Enter a character: "); + scanf("%c", &c); + + // %d displays the integer value of a character + // %c displays the actual character + printf("ASCII value of %c = %d", c, c); + + return 0; +} From 084a14bc7eee08c5ffdab0554bf9c5ab81db6f09 Mon Sep 17 00:00:00 2001 From: shalilmandidev <73024553+shalilmandidev@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:08:50 +0530 Subject: [PATCH 442/781] Create Fibonacci_Python_Code Python Program to Print the Fibonacci sequence --- Fibonacci_Python_Code | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Fibonacci_Python_Code diff --git a/Fibonacci_Python_Code b/Fibonacci_Python_Code new file mode 100644 index 00000000..9f6b1b3d --- /dev/null +++ b/Fibonacci_Python_Code @@ -0,0 +1,23 @@ +# Program to display the Fibonacci sequence up to n-th term + +nterms = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + # update values + n1 = n2 + n2 = nth + count += 1 From ee5643d98849439ed84b717c938b31399c3c500a Mon Sep 17 00:00:00 2001 From: shalilmandidev <73024553+shalilmandidev@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:10:24 +0530 Subject: [PATCH 443/781] Create C_Program to find lenght of a string Program to find lenght of a string --- C_Program to find lenght of a string | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 C_Program to find lenght of a string diff --git a/C_Program to find lenght of a string b/C_Program to find lenght of a string new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/C_Program to find lenght of a string @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From b02bf4cc1963e3a3cae508687abf759abb245e45 Mon Sep 17 00:00:00 2001 From: Pratx-404 <32536443+Pratx-404@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:13:47 +0530 Subject: [PATCH 444/781] Create Number of vowels and consonants --- Number of vowels and consonants | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Number of vowels and consonants diff --git a/Number of vowels and consonants b/Number of vowels and consonants new file mode 100644 index 00000000..6ab63cee --- /dev/null +++ b/Number of vowels and consonants @@ -0,0 +1,11 @@ +string=list(input()) +vowels=['A','E','I','O','U','a','e','i','o','u'] +vowel_count=0 +consonant_count=0 +for i in range(len(string)): + if string[i] in vowels: + vowel_count+=1 + else: + consonant_count+=1 +print("Number of Vowels in the string",vowel_count) +print("Number of Consonants in th string",consonant_count) From 3e2bb7dd0ea0d1e3532a5d890a638f46c48b79f7 Mon Sep 17 00:00:00 2001 From: JyotsnaSree <65958274+JyotsnaSree@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:14:54 +0530 Subject: [PATCH 445/781] Create reverse an array Optimized code for reversing an array --- reverse an array | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 reverse an array diff --git a/reverse an array b/reverse an array new file mode 100644 index 00000000..c34ee78d --- /dev/null +++ b/reverse an array @@ -0,0 +1,46 @@ +// Iterative C++ program to reverse an array +#include +using namespace std; + +/* Function to reverse arr[] from start to end*/ +void rvereseArray(int arr[], int start, int end) +{ + while (start < end) + { + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } +} + +/* Utility function to print an array */ +void printArray(int arr[], int size) +{ + for (int i = 0; i < size; i++) + cout << arr[i] << " "; + + cout << endl; +} + +/* Driver function to test above functions */ +int main() +{ + int arr[] = {1, 2, 3, 4, 5, 6}; + + int n = sizeof(arr) / sizeof(arr[0]); + + // To print original array + printArray(arr, n); + + // Function calling + rvereseArray(arr, 0, n-1); + + cout << "Reversed array is" << endl; + + // To print the Reversed array + printArray(arr, n); + + return 0; +} From 9209e910111c72e53f6ee687b78afcea302cce25 Mon Sep 17 00:00:00 2001 From: Swadha-27 <48059712+Swadha-27@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:16:03 +0530 Subject: [PATCH 446/781] Reverse the given array in Python Short and optimized code to find the reverse of an array. --- Reverse the given array in Python | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Reverse the given array in Python diff --git a/Reverse the given array in Python b/Reverse the given array in Python new file mode 100644 index 00000000..296871f5 --- /dev/null +++ b/Reverse the given array in Python @@ -0,0 +1,9 @@ +array=[1,3,5,4,8,6,2,4] #input array +i=0 +j=len(array)-1 + +while i<=j: # two-pointer approach + array[i],array[j]=array[j],array[i] + i+=1 + j-=1 +print("Array in reversed form is",array) #o/p is [4, 2, 6, 8, 4, 5, 3, 1] From c83b6ff97f9d5355b473715ece4ad7a1f5e5c7cb Mon Sep 17 00:00:00 2001 From: kapoor2427 <41826795+kapoor2427@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:29:47 +0530 Subject: [PATCH 447/781] Create Cpp Program to reverse the array Optimized CPP program to reverse an array using two pointer technique. --- Cpp Program to reverse the array | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Cpp Program to reverse the array diff --git a/Cpp Program to reverse the array b/Cpp Program to reverse the array new file mode 100644 index 00000000..28b5eaec --- /dev/null +++ b/Cpp Program to reverse the array @@ -0,0 +1,22 @@ +#include +using namespace std; + +void reverseArray(int arr[], int n){ + int i = 0, j = n-1; + while(i Date: Sat, 17 Oct 2020 18:33:43 +0530 Subject: [PATCH 448/781] Create C_Program Factorial Factorial program in C --- C_Program Factorial | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 C_Program Factorial diff --git a/C_Program Factorial b/C_Program Factorial new file mode 100644 index 00000000..cf5490fd --- /dev/null +++ b/C_Program Factorial @@ -0,0 +1,16 @@ +#include + +int main() +{ + int c, n, f = 1; + + printf("Enter a number to calculate its factorial\n"); + scanf("%d", &n); + for (c = 1; c <= n; c++) + f = f * c; + + printf("Factorial of %d = %d\n", n, f); + + return 0; +} + From 172c94e7303e984a1ec676edb10355c32780365a Mon Sep 17 00:00:00 2001 From: souvikismyname <73025539+souvikismyname@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:36:27 +0530 Subject: [PATCH 449/781] Create C_Code Largest Element in an Array C Program to Find Largest Element in an Array --- C_Code Largest Element in an Array | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 C_Code Largest Element in an Array diff --git a/C_Code Largest Element in an Array b/C_Code Largest Element in an Array new file mode 100644 index 00000000..98a77125 --- /dev/null +++ b/C_Code Largest Element in an Array @@ -0,0 +1,22 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + // storing the largest number to arr[0] + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From 3e2ba4f3fa7bbaf524f973459ffaecd883d8d33c Mon Sep 17 00:00:00 2001 From: souvikismyname <73025539+souvikismyname@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:38:24 +0530 Subject: [PATCH 450/781] Create Array_Smallest_Element Program to find smallest array element in C --- Array_Smallest_Element | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Array_Smallest_Element diff --git a/Array_Smallest_Element b/Array_Smallest_Element new file mode 100644 index 00000000..4e665c58 --- /dev/null +++ b/Array_Smallest_Element @@ -0,0 +1,17 @@ +#include + +int main() { + int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + int loop, smallest; + + smallest = array[0]; + + for(loop = 1; loop < 10; loop++) { + if( smallest > array[loop] ) + smallest = array[loop]; + } + + printf("Smallest element of array is %d", smallest); + + return 0; +} From b149e91c13d0593fe0dc082641eed0081adced10 Mon Sep 17 00:00:00 2001 From: souvikismyname <73025539+souvikismyname@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:39:48 +0530 Subject: [PATCH 451/781] Create Length of String in C_Lang Calculate Length of String without Using strlen() Function --- Length of String in C_Lang | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Length of String in C_Lang diff --git a/Length of String in C_Lang b/Length of String in C_Lang new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/Length of String in C_Lang @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 325294deb1261d1cfe9c9522d3168fc315c01758 Mon Sep 17 00:00:00 2001 From: ayush-1998 <64705130+ayush-1998@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:43:21 +0530 Subject: [PATCH 452/781] Create Fibonacci Series using Java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimized code for Fibonacci Series using direct formula. Fn = {[(√5 + 1)/2] ^ n} / √5 Time Complexity: O(1) Space Complexity: O(1) --- Fibonacci Series using Java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Fibonacci Series using Java diff --git a/Fibonacci Series using Java b/Fibonacci Series using Java new file mode 100644 index 00000000..c686e650 --- /dev/null +++ b/Fibonacci Series using Java @@ -0,0 +1,17 @@ +import java.util.*; + +class Solution { + +static int fib(int n) { +double result = (1 + Math.sqrt(5)) / 2; +return (int) Math.round(Math.pow(result, n) + / Math.sqrt(5)); +} + +// Driver Code +public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int n=sc.nextInt(); + System.out.println(fib(n)); + } +} From 6412fbb766b0c6a5d1217507f6d0982633077fba Mon Sep 17 00:00:00 2001 From: sayandas51 <73025984+sayandas51@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:46:40 +0530 Subject: [PATCH 453/781] Create Java Program to count the total number of vowels and consonants in a string Java Program to count the total number of vowels and consonants in a string --- ...umber of vowels and consonants in a string | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Java Program to count the total number of vowels and consonants in a string diff --git a/Java Program to count the total number of vowels and consonants in a string b/Java Program to count the total number of vowels and consonants in a string new file mode 100644 index 00000000..d06700c1 --- /dev/null +++ b/Java Program to count the total number of vowels and consonants in a string @@ -0,0 +1,28 @@ +public class CountVowelConsonant { + public static void main(String[] args) { + + //Counter variable to store the count of vowels and consonant + int vCount = 0, cCount = 0; + + //Declare a string + String str = "This is a really simple sentence"; + + //Converting entire string to lower case to reduce the comparisons + str = str.toLowerCase(); + + for(int i = 0; i < str.length(); i++) { + //Checks whether a character is a vowel + if(str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i' || str.charAt(i) == 'o' || str.charAt(i) == 'u') { + //Increments the vowel counter + vCount++; + } + //Checks whether a character is a consonant + else if(str.charAt(i) >= 'a' && str.charAt(i)<='z') { + //Increments the consonant counter + cCount++; + } + } + System.out.println("Number of vowels: " + vCount); + System.out.println("Number of consonants: " + cCount); + } +} From 1291ce3bed1acd9d3a9f83f54fe300d5c17f0143 Mon Sep 17 00:00:00 2001 From: kapoor2427 <41826795+kapoor2427@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:48:11 +0530 Subject: [PATCH 454/781] Create CPP Program to convert binary to decimal number CPP program to convert binary to decimal number for a higher range of binary values. --- ...rogram to convert binary to decimal number | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 CPP Program to convert binary to decimal number diff --git a/CPP Program to convert binary to decimal number b/CPP Program to convert binary to decimal number new file mode 100644 index 00000000..aec2a98f --- /dev/null +++ b/CPP Program to convert binary to decimal number @@ -0,0 +1,23 @@ +#include +#include + +using namespace std; + +long long binaryToDecimal(string str) +{ + int sum = 0; + int b = 1; + + for (int i = str.length() - 1; i >= 0; i--) { + if (str[i] == '1') + sum += b; + b = b * 2; + } + return sum; +} + +int main() +{ + cout< Date: Sat, 17 Oct 2020 18:49:25 +0530 Subject: [PATCH 455/781] Create C_Program to perform arithmetic operations C program to enter two numbers and perform all arithmetic operations --- C_Program to perform arithmetic operations | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 C_Program to perform arithmetic operations diff --git a/C_Program to perform arithmetic operations b/C_Program to perform arithmetic operations new file mode 100644 index 00000000..52112d93 --- /dev/null +++ b/C_Program to perform arithmetic operations @@ -0,0 +1,29 @@ +#include + +int main() +{ + int p, q; + int sum, sub, mul, mod; + float div; + + /** Input two numbers from user **/ + printf("Enter any two numbers::\n"); + scanf("%d%d", &p, &q, "\n"); + + /** Perform all arithmetic operations **/ + sum = p + q; + sub = p - q; + mul = p * q; + div = (float)p / q; + mod = p % q; + + /** Print result of all arithmetic operations **/ + printf("\n"); + printf("SUM %d + %d = %d\n", p, q, sum); + printf("DIFFERENCE %d - %d = %d\n", p, q, sub); + printf("PRODUCT %d * %d = %d\n", p, q, mul); + printf("QUOTIENT %d / %d = %f\n", p, q, div); + printf("MODULUS %d %% %d = %d\n", p, q, mod); + + return 0; +} From d4574e7fed70bba017a96b257992bb8bba31e3ca Mon Sep 17 00:00:00 2001 From: sayandas51 <73025984+sayandas51@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:50:40 +0530 Subject: [PATCH 456/781] Create c++_Program to find sum of elements in a given array Program to find sum of elements in a given array --- ...m to find sum of elements in a given array | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 c++_Program to find sum of elements in a given array diff --git a/c++_Program to find sum of elements in a given array b/c++_Program to find sum of elements in a given array new file mode 100644 index 00000000..5feb4b6f --- /dev/null +++ b/c++_Program to find sum of elements in a given array @@ -0,0 +1,27 @@ +/* C++ Program to find sum of elements +in a given array */ +#include +using namespace std; + +// function to return sum of elements +// in an array of size n +int sum(int arr[], int n) +{ + int sum = 0; // initialize sum + + // Iterate through all elements + // and add them to sum + for (int i = 0; i < n; i++) + sum += arr[i]; + + return sum; +} + +// Driver code +int main() +{ + int arr[] = {12, 3, 4, 15}; + int n = sizeof(arr) / sizeof(arr[0]); + cout << "Sum of given array is " << sum(arr, n); + return 0; +} From 9edd862542eae6f48638b725b9f10f84ffc382af Mon Sep 17 00:00:00 2001 From: sayandas51 <73025984+sayandas51@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:52:16 +0530 Subject: [PATCH 457/781] Create Php_Program to multiply two matrices Program to multiply two matrices --- Php_Program to multiply two matrices | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Php_Program to multiply two matrices diff --git a/Php_Program to multiply two matrices b/Php_Program to multiply two matrices new file mode 100644 index 00000000..41c01dac --- /dev/null +++ b/Php_Program to multiply two matrices @@ -0,0 +1,51 @@ + +edit +play_arrow + +brightness_4 + From 2a2a0b712027d17b55f562928eb8f2a9387c9c49 Mon Sep 17 00:00:00 2001 From: Anush kamath Date: Sat, 17 Oct 2020 18:52:23 +0530 Subject: [PATCH 458/781] Create Counting number of digits in an integer Optimized code for getting the count for entered number of digits --- Counting number of digits in an integer | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Counting number of digits in an integer diff --git a/Counting number of digits in an integer b/Counting number of digits in an integer new file mode 100644 index 00000000..f8c75237 --- /dev/null +++ b/Counting number of digits in an integer @@ -0,0 +1,15 @@ +#include + +int main(){ +int n,count=0; + +printf("Enter an integer:"); +scanf("%d",&n); + +while(n!=0){ +n/=10; +count++; +} + +printf("Number of digits:%d",count); +} From 96235db1b6236a39cfb1f00c88faa371c5e3e38b Mon Sep 17 00:00:00 2001 From: biranchinarayan <70357046+biranchinarayan@users.noreply.github.com> Date: Sat, 17 Oct 2020 18:56:02 +0530 Subject: [PATCH 459/781] Create [hacktoberfest] java for find modulus of a matrix a quality code for determining the modulus of a matrix using java --- ...berfest] java for find modulus of a matrix | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 [hacktoberfest] java for find modulus of a matrix diff --git a/[hacktoberfest] java for find modulus of a matrix b/[hacktoberfest] java for find modulus of a matrix new file mode 100644 index 00000000..627a2101 --- /dev/null +++ b/[hacktoberfest] java for find modulus of a matrix @@ -0,0 +1,33 @@ + import java.io.BufferedReader; +import java.io.InputStreamReader; + +public class ModulusOfAMatrix { + public static void main(String[] args) { + BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); + int order=3; + int[][] matrix=new int[3][3]; + System.out.println("Enter the elements of 3x3 matrix"); + int i,j; + for(i=0;i Date: Sat, 17 Oct 2020 18:59:58 +0530 Subject: [PATCH 460/781] Create c# Prime No. Program to find Prime Numbers Between given Interval --- c# Prime No. | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 c# Prime No. diff --git a/c# Prime No. b/c# Prime No. new file mode 100644 index 00000000..f5b5ed02 --- /dev/null +++ b/c# Prime No. @@ -0,0 +1,61 @@ +// C# program to find the prime numbers +// between a given interval +using System; + +class GFG{ + +// Driver code +public static void Main(string[] args) +{ + + // Declare the variables + int a, b, i, j, flag; + + // Ask user to enter lower value of interval + Console.WriteLine("Enter lower bound of " + + "the interval: "); + + // Take input + a = int.Parse(Console.ReadLine()); + + // Ask user to enter upper value of interval + Console.WriteLine("\nEnter upper bound " + + "of the interval: "); + + // Take input + b = int.Parse(Console.ReadLine()); + + // Print display message + Console.WriteLine("\nPrime numbers between " + + "{0} and {1} are: ", a, b); + + // Traverse each number in the interval + // with the help of for loop + for(i = a; i <= b; i++) + { + + // Skip 0 and 1 as they are + // niether prime nor composite + if (i == 1 || i == 0) + continue; + + // flag variable to tell + // if i is prime or not + flag = 1; + + for(j = 2; j <= i / 2; ++j) + { + if (i % j == 0) + { + flag = 0; + break; + } + } + + // flag = 1 means i is prime + // and flag = 0 means i is not prime + if (flag == 1) + Console.WriteLine(i); + } +} +} From 1b01567b042fbebbaa873f5d25cab8c2b278d75c Mon Sep 17 00:00:00 2001 From: sattwatdas71 <73026398+sattwatdas71@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:02:29 +0530 Subject: [PATCH 461/781] Create c# program to reverse an array or string program to reverse an array or string --- c# program to reverse an array or string | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 c# program to reverse an array or string diff --git a/c# program to reverse an array or string b/c# program to reverse an array or string new file mode 100644 index 00000000..59be7d45 --- /dev/null +++ b/c# program to reverse an array or string @@ -0,0 +1,44 @@ +// Iterative C# program to reverse an +// array +using System; + +class GFG { + + /* Function to reverse arr[] from + start to end*/ + static void rvereseArray(int []arr, + int start, int end) + { + int temp; + + while (start < end) + { + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } + } + + /* Utility that prints out an + array on a line */ + static void printArray(int []arr, + int size) + { + for (int i = 0; i < size; i++) + Console.Write(arr[i] + " "); + + Console.WriteLine(); + } + + // Driver function + public static void Main() + { + int []arr = {1, 2, 3, 4, 5, 6}; + printArray(arr, 6); + rvereseArray(arr, 0, 5); + Console.Write("Reversed array is \n"); + printArray(arr, 6); + } +} From 2fda4494e63f68593d66c72914bf0b4f6d8fb605 Mon Sep 17 00:00:00 2001 From: sattwatdas71 <73026398+sattwatdas71@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:03:27 +0530 Subject: [PATCH 462/781] Create c# Count of Leap Years in a given year range Count of Leap Years in a given year range --- c# Count of Leap Years in a given year range | 36 ++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 c# Count of Leap Years in a given year range diff --git a/c# Count of Leap Years in a given year range b/c# Count of Leap Years in a given year range new file mode 100644 index 00000000..dd515fda --- /dev/null +++ b/c# Count of Leap Years in a given year range @@ -0,0 +1,36 @@ +// C# implementation to find the +// count of leap years in given +// range of the year +using System; + +class GFG +{ + +// Function to calculate the number +// of leap years in range of (1, year) +static int calNum(int year) +{ + return (year / 4) - (year / 100) + + (year / 400); +} + +// Function to calculate the number +// of leap years in given range +static void leapNum(int l, int r) +{ + l--; + int num1 = calNum(r); + int num2 = calNum(l); + Console.Write(num1 - num2 +"\n"); +} + +// Driver Code +public static void Main(String[] args) +{ + int l1 = 1, r1 = 400; + leapNum(l1, r1); + + int l2 = 400, r2 = 2000; + leapNum(l2, r2); +} +} From 8c60e1d9f99a45d028842e12c64d77457adc1d6c Mon Sep 17 00:00:00 2001 From: sattwatdas71 <73026398+sattwatdas71@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:04:22 +0530 Subject: [PATCH 463/781] Create c# Program for Binary To Decimal Conversion --- c# Program for Binary To Decimal Conversion | 36 +++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 c# Program for Binary To Decimal Conversion diff --git a/c# Program for Binary To Decimal Conversion b/c# Program for Binary To Decimal Conversion new file mode 100644 index 00000000..344cb55b --- /dev/null +++ b/c# Program for Binary To Decimal Conversion @@ -0,0 +1,36 @@ +// C# program to convert +// binary to decimal + +// Function to convert +// binary to decimal +class GFG { + public static int binaryToDecimal(int n) + { + int num = n; + int dec_value = 0; + + // Initializing base1 + // value to 1, i.e 2^0 + int base1 = 1; + + int temp = num; + while (temp > 0) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base1; + + base1 = base1 * 2; + } + + return dec_value; + } + + // Driver Code + public static void Main() + { + int num = 10101001; + + System.Console.Write(binaryToDecimal(num)); + } +} From 60f2a02c10e6095971a7516fb2ed5ef99c3269a3 Mon Sep 17 00:00:00 2001 From: bipradeepbiswas704 <73026870+bipradeepbiswas704@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:10:32 +0530 Subject: [PATCH 464/781] Create Convert a binary number to octal_Python 3 Convert a binary number to octal --- Convert a binary number to octal_Python 3 | 71 +++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Convert a binary number to octal_Python 3 diff --git a/Convert a binary number to octal_Python 3 b/Convert a binary number to octal_Python 3 new file mode 100644 index 00000000..1a81c965 --- /dev/null +++ b/Convert a binary number to octal_Python 3 @@ -0,0 +1,71 @@ +# Python3 implementation to convert a binary number +# to octal number + +# function to create map between binary +# number and its equivalent octal +def createMap(bin_oct_map): + bin_oct_map["000"] = '0' + bin_oct_map["001"] = '1' + bin_oct_map["010"] = '2' + bin_oct_map["011"] = '3' + bin_oct_map["100"] = '4' + bin_oct_map["101"] = '5' + bin_oct_map["110"] = '6' + bin_oct_map["111"] = '7' + +# Function to find octal equivalent of binary +def convertBinToOct(bin): + l = len(bin) + + # length of string before '.' + t = -1 + if '.' in bin: + t = bin.index('.') + len_left = t + else: + len_left = l + + # add min 0's in the beginning to make + # left substring length divisible by 3 + for i in range(1, (3 - len_left % 3) % 3 + 1): + bin = '0' + bin + + # if decimal point exists + if (t != -1): + + # length of string after '.' + len_right = l - len_left - 1 + + # add min 0's in the end to make right + # substring length divisible by 3 + for i in range(1, (3 - len_right % 3) % 3 + 1): + bin = bin + '0' + + # create dictionary between binary and its + # equivalent octal code + bin_oct_map = {} + createMap(bin_oct_map) + i = 0 + octal = "" + + while (True) : + + # one by one extract from left, substring + # of size 3 and add its octal code + octal += bin_oct_map[bin[i:i + 3]] + i += 3 + if (i == len(bin)): + break + + # if '.' is encountered add it to result + if (bin[i] == '.'): + octal += '.' + i += 1 + + # required octal number + return octal + +# Driver Code +bin = "1111001010010100001.010110110011011" +print("Octal number = ", + convertBinToOct(bin)) From 45132f3ab93adcd26454414be160712ddbf9e817 Mon Sep 17 00:00:00 2001 From: ayush-1998 <64705130+ayush-1998@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:11:02 +0530 Subject: [PATCH 465/781] Create Power of any number An optimized version of Java code for power function that can work for float x and negative y. Time Complexity: O(logn) --- Power of any number | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Power of any number diff --git a/Power of any number b/Power of any number new file mode 100644 index 00000000..b9a1461d --- /dev/null +++ b/Power of any number @@ -0,0 +1,30 @@ +import java.util.*; +class Solution { + + static float power(float x, int y) + { + float result; + if( y == 0) + return 1; + result = power(x, y/2); + + if (y%2 == 0) + return result * result; + else + { + if(y > 0) + return x * result * result; + else + return (result * result) / x; + } + } + + /* Program to test function power */ + public static void main(String[] args) + { + Scanner sc= new Scanner(System.in); + float x = sc.nextFloat(); + int y = sc.nextInt(); + System.out.printf("%f", power(x, y)); + } +} From d8f3e2846949a525986f62c6168756c65732fbd9 Mon Sep 17 00:00:00 2001 From: bipradeepbiswas704 <73026870+bipradeepbiswas704@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:11:52 +0530 Subject: [PATCH 466/781] Create Write a program to calculate power_Python 3 Write a program to calculate pow(x,n) --- Write a program to calculate power_Python 3 | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Write a program to calculate power_Python 3 diff --git a/Write a program to calculate power_Python 3 b/Write a program to calculate power_Python 3 new file mode 100644 index 00000000..fe3bf768 --- /dev/null +++ b/Write a program to calculate power_Python 3 @@ -0,0 +1,17 @@ +# Python3 program to calculate pow(x,n) + +# Function to calculate x +# raised to the power y +def power(x, y): + + if (y == 0): return 1 + elif (int(y % 2) == 0): + return (power(x, int(y / 2)) * + power(x, int(y / 2))) + else: + return (x * power(x, int(y / 2)) * + power(x, int(y / 2))) + +# Driver Code +x = 2; y = 3 +print(power(x, y)) From 9903838e055efc5758dceff017bdec205ab7bb79 Mon Sep 17 00:00:00 2001 From: bipradeepbiswas704 <73026870+bipradeepbiswas704@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:13:50 +0530 Subject: [PATCH 467/781] Create Fibonacci_C_codebybipradeep C Program to print Fibonacci Series without using loop --- Fibonacci_C_codebybipradeep | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Fibonacci_C_codebybipradeep diff --git a/Fibonacci_C_codebybipradeep b/Fibonacci_C_codebybipradeep new file mode 100644 index 00000000..c5673dd0 --- /dev/null +++ b/Fibonacci_C_codebybipradeep @@ -0,0 +1,37 @@ +// C program to print fibonacci +// series using recursion +#include + +// Recursive function to print +// Fibonacci series +void fib(int a, int b, int sum, int N) +{ + + // Print first N term of the series + if (N != 0) { + + printf(" %d", a); + sum = a + b; + a = b; + b = sum; + + // Decrement N + N--; + + // recursive call function fib + fib(a, b, sum, N); + } +} + +// Driver Code +int main() +{ + // Given Number N + int N = 10; + + // First term as 0 + // Second term as 1 and + // Sum of first and second term + fib(0, 1, 0, N); + return 0; +} From 41537c6725a02573934fc649ec89591b61629132 Mon Sep 17 00:00:00 2001 From: bipradeepbiswas704 <73026870+bipradeepbiswas704@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:15:20 +0530 Subject: [PATCH 468/781] Create Java_Program Program to find largest element in an array Program to find largest element in an array --- ...rogram to find largest element in an array | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Java_Program Program to find largest element in an array diff --git a/Java_Program Program to find largest element in an array b/Java_Program Program to find largest element in an array new file mode 100644 index 00000000..8dba88e9 --- /dev/null +++ b/Java_Program Program to find largest element in an array @@ -0,0 +1,28 @@ +// Java Program to find maximum in arr[] +class Test +{ + static int arr[] = {10, 324, 45, 90, 9808}; + + // Method to find maximum in arr[] + static int largest() + { + int i; + + // Initialize maximum element + int max = arr[0]; + + // Traverse array elements from second and + // compare every element with current max + for (i = 1; i < arr.length; i++) + if (arr[i] > max) + max = arr[i]; + + return max; + } + + // Driver method + public static void main(String[] args) + { + System.out.println("Largest in given array is " + largest()); + } + } From 96605326cf15fbf861d9de98a7161a4b2ff3db99 Mon Sep 17 00:00:00 2001 From: Divyanshu Singh <67826413+DivyanshuSingh2000@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:17:00 +0530 Subject: [PATCH 469/781] Create ProgramToReverseArray A simple program to reverse an array in python --- ProgramToReverseArray | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ProgramToReverseArray diff --git a/ProgramToReverseArray b/ProgramToReverseArray new file mode 100644 index 00000000..d1f71189 --- /dev/null +++ b/ProgramToReverseArray @@ -0,0 +1,3 @@ +l = list(map(int,input().split())) +l.reverse() +print(l) From c57a4626aac69ef52bad1e3c92c6066e03009e42 Mon Sep 17 00:00:00 2001 From: Pummy Jha <64890582+Pummy12@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:21:21 +0530 Subject: [PATCH 470/781] Create matrix multiplication Optimize code for matrix multiplication quickly. --- matrix multiplication | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 matrix multiplication diff --git a/matrix multiplication b/matrix multiplication new file mode 100644 index 00000000..7ec5e0be --- /dev/null +++ b/matrix multiplication @@ -0,0 +1,43 @@ +// C program to multiply two square matrices. +#include +#define N 4 + +// This function multiplies mat1[][] and mat2[][], +// and stores the result in res[][] +void multiply(int mat1[][N], int mat2[][N], int res[][N]) +{ + int i, j, k; + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) { + res[i][j] = 0; + for (k = 0; k < N; k++) + res[i][j] += mat1[i][k] * mat2[k][j]; + } + } +} + +int main() +{ + int mat1[N][N] = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + int mat2[N][N] = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + int res[N][N]; // To store result + int i, j; + multiply(mat1, mat2, res); + + printf("Result matrix is \n"); + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) + printf("%d ", res[i][j]); + printf("\n"); + } + + return 0; +} From d6c9931e9945c9676fb4725473138532bf5173de Mon Sep 17 00:00:00 2001 From: Khushi Jain <56038894+KhushiJain2810@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:21:26 +0530 Subject: [PATCH 471/781] C++ Program to revere an array using swap() --- Reversing an array | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Reversing an array diff --git a/Reversing an array b/Reversing an array new file mode 100644 index 00000000..be9c1cbf --- /dev/null +++ b/Reversing an array @@ -0,0 +1,21 @@ +#include + +using namespace std; + +int main() +{ + int numOfElements; + cin >> numOfElements; + int arr[numOfElements]; + for(int i = 0; i < numOfElements; i++) + cin >> arr[i]; + for(int i = 0; i < numOfElements/2; i++) + { + swap(arr[i], arr[numOfElements-i-1]); + } + for(int i = 0; i < numOfElements; i++) + { + cout << arr[i] << " "; + } + return 0; +} From 220a20bb22b4a30d24f81b932b21cd3043c32e6c Mon Sep 17 00:00:00 2001 From: ayush-1998 <64705130+ayush-1998@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:23:18 +0530 Subject: [PATCH 472/781] Create Prime Numbers Between given Interval Optimized code for finding the prime numbers in a given range. --- Prime Numbers Between given Interval | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Prime Numbers Between given Interval diff --git a/Prime Numbers Between given Interval b/Prime Numbers Between given Interval new file mode 100644 index 00000000..51af35f8 --- /dev/null +++ b/Prime Numbers Between given Interval @@ -0,0 +1,55 @@ +import java.util.*; + +class Main { + + // driver code + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + + int a, b, i, j,flag; + + // enter lower value of interval + System.out.printf( "Enter lower bound of the interval: "); + a = sc.nextInt(); + + // enter upper value of interval + System.out.printf( "\nEnter upper bound of the interval: "); + b = sc.nextInt(); + + System.out.printf("\nPrime numbers between %d and %d are: ", a, b); + + // Explicitly handling the cases when a is less than 2 + if (a == 1) { + System.out.println(a); + a++; + if (b >= 2) { + System.out.println(a); + a++; + } + } + if (a == 2) + System.out.println(a); + + + if (a % 2 == 0) + a++; + + + for (i = a; i <= b; i = i + 2) { + + + flag = 1; + + for (j = 2; j * j <= i; ++j) { + if (i % j == 0) { + flag = 0; + break; + } + } + if (flag == 1) + System.out.println(i); + } + + } +} From ee89c1b3b9b5419dced232325776da1761faa10a Mon Sep 17 00:00:00 2001 From: sudiptabiswas88 <73027321+sudiptabiswas88@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:24:09 +0530 Subject: [PATCH 473/781] Create Program to multiply two matrices c# Code Program to multiply two matrices --- Program to multiply two matrices c# Code | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Program to multiply two matrices c# Code diff --git a/Program to multiply two matrices c# Code b/Program to multiply two matrices c# Code new file mode 100644 index 00000000..0ee8ded8 --- /dev/null +++ b/Program to multiply two matrices c# Code @@ -0,0 +1,53 @@ +// C# program to multiply two square +// matrices. +using System; + +class GFG { + + static int N = 4; + + // This function multiplies mat1[][] + // and mat2[][], and stores the result + // in res[][] + static void multiply(int[, ] mat1, + int[, ] mat2, int[, ] res) + { + int i, j, k; + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) { + res[i, j] = 0; + for (k = 0; k < N; k++) + res[i, j] += mat1[i, k] + * mat2[k, j]; + } + } + } + + // Driver code + public static void Main() + { + int[, ] mat1 = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + int[, ] mat2 = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + // To store result + int[, ] res = new int[N, N]; + int i, j; + multiply(mat1, mat2, res); + + Console.WriteLine("Result matrix" + + " is "); + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) + Console.Write(res[i, j] + + " "); + Console.WriteLine(); + } + } +} From 175911880cb55623633d1080f8d0db27a15deee0 Mon Sep 17 00:00:00 2001 From: sudiptabiswas88 <73027321+sudiptabiswas88@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:25:15 +0530 Subject: [PATCH 474/781] Create Program for Binary To Decimal Conversion c# Code Program for Binary To Decimal Conversion --- ...m for Binary To Decimal Conversion c# Code | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Program for Binary To Decimal Conversion c# Code diff --git a/Program for Binary To Decimal Conversion c# Code b/Program for Binary To Decimal Conversion c# Code new file mode 100644 index 00000000..344cb55b --- /dev/null +++ b/Program for Binary To Decimal Conversion c# Code @@ -0,0 +1,36 @@ +// C# program to convert +// binary to decimal + +// Function to convert +// binary to decimal +class GFG { + public static int binaryToDecimal(int n) + { + int num = n; + int dec_value = 0; + + // Initializing base1 + // value to 1, i.e 2^0 + int base1 = 1; + + int temp = num; + while (temp > 0) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base1; + + base1 = base1 * 2; + } + + return dec_value; + } + + // Driver Code + public static void Main() + { + int num = 10101001; + + System.Console.Write(binaryToDecimal(num)); + } +} From 4fc256531bd2476168d7f0a050ea247e7b9cccfc Mon Sep 17 00:00:00 2001 From: Divyanshu Singh <67826413+DivyanshuSingh2000@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:26:49 +0530 Subject: [PATCH 475/781] Create ProgramToPrintFibonnacciSeries --- ProgramToPrintFibonnacciSeries | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 ProgramToPrintFibonnacciSeries diff --git a/ProgramToPrintFibonnacciSeries b/ProgramToPrintFibonnacciSeries new file mode 100644 index 00000000..9f6b1b3d --- /dev/null +++ b/ProgramToPrintFibonnacciSeries @@ -0,0 +1,23 @@ +# Program to display the Fibonacci sequence up to n-th term + +nterms = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + # update values + n1 = n2 + n2 = nth + count += 1 From 0a0dbf8b33882cdd6c016f6c4ba3a55e8c52a047 Mon Sep 17 00:00:00 2001 From: sudiptabiswas88 <73027321+sudiptabiswas88@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:26:49 +0530 Subject: [PATCH 476/781] Create Python Matrix addition Python program to add two Matrices --- Python Matrix addition | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Python Matrix addition diff --git a/Python Matrix addition b/Python Matrix addition new file mode 100644 index 00000000..c9206ec8 --- /dev/null +++ b/Python Matrix addition @@ -0,0 +1,14 @@ +# Program to add two matrices +# using zip() + +X = [[1,2,3], + [4 ,5,6], + [7 ,8,9]] + +Y = [[9,8,7], + [6,5,4], + [3,2,1]] + +result = [map(sum, zip(*t)) for t in zip(X, Y)] + +print(result) From ab95a2dbbeb82acdf65480b94fe3f6e6ec5cdd9a Mon Sep 17 00:00:00 2001 From: Pummy Jha <64890582+Pummy12@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:28:29 +0530 Subject: [PATCH 477/781] Create convert decimal to binary Optimized code for conversion of decimal to binary quickly. --- convert decimal to binary | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 convert decimal to binary diff --git a/convert decimal to binary b/convert decimal to binary new file mode 100644 index 00000000..e3ac7e19 --- /dev/null +++ b/convert decimal to binary @@ -0,0 +1,19 @@ +#include +#include +int main(){ +int a[10],n,i; +system ("cls"); +printf("Enter the number to convert: "); +scanf("%d",&n); +for(i=0;n>0;i++) +{ +a[i]=n%2; +n=n/2; +} +printf("\nBinary of Given Number is="); +for(i=i-1;i>=0;i--) +{ +printf("%d",a[i]); +} +return 0; +} From 77133bd779f8727c01ee78c1a5024db8f4ca4363 Mon Sep 17 00:00:00 2001 From: sudiptabiswas88 <73027321+sudiptabiswas88@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:28:40 +0530 Subject: [PATCH 478/781] Create c_length_String C program to find the length of a string --- c_length_String | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 c_length_String diff --git a/c_length_String b/c_length_String new file mode 100644 index 00000000..5d3de3c2 --- /dev/null +++ b/c_length_String @@ -0,0 +1,18 @@ +// C program to find the length of string +#include +#include + +int main() +{ + char Str[1000]; + int i; + + printf("Enter the String: "); + scanf("%s", Str); + + for (i = 0; Str[i] != '\0'; ++i); + + printf("Length of Str is %d", i); + + return 0; +} From cafc98dcb00c31993ace563b42a0b0ad59e531fe Mon Sep 17 00:00:00 2001 From: ayush-1998 <64705130+ayush-1998@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:31:50 +0530 Subject: [PATCH 479/781] Create binary to decimal conversion Converting binary to decimal in java using method. --- binary to decimal conversion | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 binary to decimal conversion diff --git a/binary to decimal conversion b/binary to decimal conversion new file mode 100644 index 00000000..70886cf5 --- /dev/null +++ b/binary to decimal conversion @@ -0,0 +1,8 @@ + +class Solution { + public static void main(String args[]) + { + String binaryNumber = "1001"; + System.out.println(Integer.parseInt(binaryNumber, 2)); + } +} From e7fefdc3f346c737a7c12cf93db740289da7ecd6 Mon Sep 17 00:00:00 2001 From: Pummy Jha <64890582+Pummy12@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:32:01 +0530 Subject: [PATCH 480/781] Create smallest element in array optimized code for smallest element in array quickly. --- smallest element in array | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 smallest element in array diff --git a/smallest element in array b/smallest element in array new file mode 100644 index 00000000..4e665c58 --- /dev/null +++ b/smallest element in array @@ -0,0 +1,17 @@ +#include + +int main() { + int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + int loop, smallest; + + smallest = array[0]; + + for(loop = 1; loop < 10; loop++) { + if( smallest > array[loop] ) + smallest = array[loop]; + } + + printf("Smallest element of array is %d", smallest); + + return 0; +} From 493f137d3a3237d3204c3341fd50c161e99ba79e Mon Sep 17 00:00:00 2001 From: Mohit Kumar <39983059+anodit@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:37:06 +0530 Subject: [PATCH 481/781] Create Binary heap in c++ Implementation of the Binary Heap in c++ Language. --- Binary heap in c++ | 210 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 Binary heap in c++ diff --git a/Binary heap in c++ b/Binary heap in c++ new file mode 100644 index 00000000..0374173a --- /dev/null +++ b/Binary heap in c++ @@ -0,0 +1,210 @@ +/* + * C++ Program to Implement Binary Heap + */ +#include +#include +#include +#include +using namespace std; +/* + * Class Declaration + */ +class BinaryHeap +{ + private: + vector heap; + int left(int parent); + int right(int parent); + int parent(int child); + void heapifyup(int index); + void heapifydown(int index); + public: + BinaryHeap() + {} + void Insert(int element); + void DeleteMin(); + int ExtractMin(); + void DisplayHeap(); + int Size(); +}; +/* + * Return Heap Size + */ +int BinaryHeap::Size() +{ + return heap.size(); +} + +/* + * Insert Element into a Heap + */ +void BinaryHeap::Insert(int element) +{ + heap.push_back(element); + heapifyup(heap.size() -1); +} +/* + * Delete Minimum Element + */ +void BinaryHeap::DeleteMin() +{ + if (heap.size() == 0) + { + cout<<"Heap is Empty"<::iterator pos = heap.begin(); + cout<<"Heap --> "; + while (pos != heap.end()) + { + cout<<*pos<<" "; + pos++; + } + cout<= 0 && parent(in) >= 0 && heap[parent(in)] > heap[in]) + { + int temp = heap[in]; + heap[in] = heap[parent(in)]; + heap[parent(in)] = temp; + heapifyup(parent(in)); + } +} + +/* + * Heapify- Maintain Heap Structure top down + */ +void BinaryHeap::heapifydown(int in) +{ + + int child = left(in); + int child1 = right(in); + if (child >= 0 && child1 >= 0 && heap[child] > heap[child1]) + { + child = child1; + } + if (child > 0 && heap[in] > heap[child]) + { + int temp = heap[in]; + heap[in] = heap[child]; + heap[child] = temp; + heapifydown(child); + } +} + +/* + * Main Contains Menu + */ +int main() +{ + BinaryHeap h; + while (1) + { + cout<<"------------------"<>choice; + switch(choice) + { + case 1: + cout<<"Enter the element to be inserted: "; + cin>>element; + h.Insert(element); + break; + case 2: + h.DeleteMin(); + break; + case 3: + cout<<"Minimum Element: "; + if (h.ExtractMin() == -1) + { + cout<<"Heap is Empty"< Date: Sat, 17 Oct 2020 19:38:15 +0530 Subject: [PATCH 482/781] Create CPP Program to find length of a string CPP program to find the length of a string. --- CPP Program to find length of a string | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 CPP Program to find length of a string diff --git a/CPP Program to find length of a string b/CPP Program to find length of a string new file mode 100644 index 00000000..2993d402 --- /dev/null +++ b/CPP Program to find length of a string @@ -0,0 +1,15 @@ +#include + +using namespace std; + +int main() +{ + string str = "abcdef"; + int count = 0; + while(str[count] != '\0') + { + count++; + } + cout< Date: Sat, 17 Oct 2020 19:39:18 +0530 Subject: [PATCH 483/781] Create length of a string Optimized code for length of a string quickly. --- length of a string | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 length of a string diff --git a/length of a string b/length of a string new file mode 100644 index 00000000..5d3de3c2 --- /dev/null +++ b/length of a string @@ -0,0 +1,18 @@ +// C program to find the length of string +#include +#include + +int main() +{ + char Str[1000]; + int i; + + printf("Enter the String: "); + scanf("%s", Str); + + for (i = 0; Str[i] != '\0'; ++i); + + printf("Length of Str is %d", i); + + return 0; +} From 2ea0038fd4b957584c377939e21926074310e692 Mon Sep 17 00:00:00 2001 From: Mohit Kumar <39983059+anodit@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:41:11 +0530 Subject: [PATCH 484/781] Create Balanced Parenthesis by using Stacks This C++ program, using a stack data structure, computes whether the given parentheses expression is valid or not by checking whether each parenthesis is closed and nested in the input expression. Here is the source code of the C++ program to display if it is a balanced expression or an invalid string. This C++ program is successfully compiled and run on DevCpp, a C++ compiler. --- Balanced Parenthesis by using Stacks | 94 ++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Balanced Parenthesis by using Stacks diff --git a/Balanced Parenthesis by using Stacks b/Balanced Parenthesis by using Stacks new file mode 100644 index 00000000..2a81a5b4 --- /dev/null +++ b/Balanced Parenthesis by using Stacks @@ -0,0 +1,94 @@ +/* + * C++ Program to Check for balanced parenthesis by using Stacks + */ +#include +#include +using namespace std; +struct node +{ + char data; + node *next; +}*p = NULL, *top = NULL, *save = NULL,*ptr; +void push(char x) +{ + p = new node; + p->data = x; + p->next = NULL; + if (top == NULL) + { + top = p; + } + else + { + save = top; + top = p; + p->next = save; + } +} +char pop() +{ + if (top == NULL) + { + cout<<"underflow!!"; + } + else + { + ptr = top; + top = top->next; + return(ptr->data); + delete ptr; + } +} +int main() +{ + int i; + char c[30], a, y, z; + cout<<"enter the expression:\n"; + cin>>c; + for (i = 0; i < strlen(c); i++) + { + if ((c[i] == '(') || (c[i] == '{') || (c[i] == '[')) + { + push(c[i]); + } + else + { + switch(c[i]) + { + case ')': + a = pop(); + if ((a == '{') || (a == '[')) + { + cout<<"invalid expr!!"; + getch(); + } + break; + case '}': + y = pop(); + if ((y == '[') || (y == '(')) + { + cout<<"invalid expr!!"; + getch(); + } + break; + case ']': + z = pop(); + if ((z == '{') || (z == '(')) + { + cout<<"invalid expr!!"; + getch(); + } + break; + } + } + } + if (top == NULL) + { + cout<<"balanced expr!!"; + } + else + { + cout<<"string is not valid.!!"; + } + getch(); +} From 3f6b9b9bb2aac4a23d9c27b18e7ee1274eae090f Mon Sep 17 00:00:00 2001 From: dennyxsingh <73027993+dennyxsingh@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:42:21 +0530 Subject: [PATCH 485/781] Create Python _Code Print number of leap years from given list of years Python Programming Print number of leap years from given list of years --- ...ber of leap years from given list of years | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Python _Code Print number of leap years from given list of years diff --git a/Python _Code Print number of leap years from given list of years b/Python _Code Print number of leap years from given list of years new file mode 100644 index 00000000..cb6331dc --- /dev/null +++ b/Python _Code Print number of leap years from given list of years @@ -0,0 +1,22 @@ +# Python code to finding number of +# leap years in list of years. + +# Input list initialization +Input = [2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012] + +# Find whether it is leap year or not +def checkYear(year): + return (((year % 4 == 0) and + (year % 100 != 0)) or + (year % 400 == 0)) + +# Answer Initialization +Answer = 0 + +for elem in Input: + if checkYear(elem): + Answer = Answer + 1 + +# Printing +print("No of leap years are:", Answer) From 50d6f96206ab5392944c2b558c6e6bbe4fb99504 Mon Sep 17 00:00:00 2001 From: dennyxsingh <73027993+dennyxsingh@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:44:20 +0530 Subject: [PATCH 486/781] Create ASCII_Java Program to print ASCII Value of a character --- ASCII_Java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 ASCII_Java diff --git a/ASCII_Java b/ASCII_Java new file mode 100644 index 00000000..89910c95 --- /dev/null +++ b/ASCII_Java @@ -0,0 +1,12 @@ +// Java program to print +// ASCII Value of Character +public class AsciiValue { + + public static void main(String[] args) + { + + char c = 'e'; + int ascii = c; + System.out.println("The ASCII value of " + c + " is: " + ascii); + } +} From 9cfee8d5babdaa9bc0e4aaa86b138067a80cbc21 Mon Sep 17 00:00:00 2001 From: Pummy Jha <64890582+Pummy12@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:46:38 +0530 Subject: [PATCH 487/781] Create calculate average using array optimized code for calculation of average using array quickly. --- calculate average using array | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 calculate average using array diff --git a/calculate average using array b/calculate average using array new file mode 100644 index 00000000..5b50f483 --- /dev/null +++ b/calculate average using array @@ -0,0 +1,18 @@ +#include + +int main() { + int array[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; + int sum, loop; + float avg; + + sum = avg = 0; + + for(loop = 0; loop < 10; loop++) { + sum = sum + array[loop]; + } + + avg = (float)sum / loop; + printf("Average of array values is %.2f", avg); + + return 0; +} From 81b77d32e2e9ac7db21ca363c6a196746fd0af85 Mon Sep 17 00:00:00 2001 From: dennyxsingh <73027993+dennyxsingh@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:46:49 +0530 Subject: [PATCH 488/781] Create C_length Of String C program to find the length of a string --- C_length Of String | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 C_length Of String diff --git a/C_length Of String b/C_length Of String new file mode 100644 index 00000000..5d3de3c2 --- /dev/null +++ b/C_length Of String @@ -0,0 +1,18 @@ +// C program to find the length of string +#include +#include + +int main() +{ + char Str[1000]; + int i; + + printf("Enter the String: "); + scanf("%s", Str); + + for (i = 0; Str[i] != '\0'; ++i); + + printf("Length of Str is %d", i); + + return 0; +} From 43b4067617268f36479e4d3089954d2d34560370 Mon Sep 17 00:00:00 2001 From: dennyxsingh <73027993+dennyxsingh@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:49:28 +0530 Subject: [PATCH 489/781] Create Program for Binary To Decimal Conversion In C# Program for Binary To Decimal Conversion in C# --- ...ram for Binary To Decimal Conversion In C# | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Program for Binary To Decimal Conversion In C# diff --git a/Program for Binary To Decimal Conversion In C# b/Program for Binary To Decimal Conversion In C# new file mode 100644 index 00000000..82752b94 --- /dev/null +++ b/Program for Binary To Decimal Conversion In C# @@ -0,0 +1,37 @@ +// C# program to convert +// binary to decimal + +// Function to convert +// binary to decimal +class GFG { + public static int binaryToDecimal(int n) + { + int num = n; + int dec_value = 0; + + // Initializing base1 + // value to 1, i.e 2^0 + int base1 = 1; + + int temp = num; + while (temp > 0) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base1; + + base1 = base1 * 2; + } + + return dec_value; + } + + // Driver Code + public static void Main() + { + int num = 10101001; + + System.Console.Write(binaryToDecimal(num)); + } +} + From 3929952f55f0bf03847809ba4bf82653b14928bd Mon Sep 17 00:00:00 2001 From: Pummy Jha <64890582+Pummy12@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:49:58 +0530 Subject: [PATCH 490/781] Create to check whether an integer is prime or not Optimized code to check whether an integer is prime or not. --- to check whether an integer is prime or not | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 to check whether an integer is prime or not diff --git a/to check whether an integer is prime or not b/to check whether an integer is prime or not new file mode 100644 index 00000000..5d7a61dd --- /dev/null +++ b/to check whether an integer is prime or not @@ -0,0 +1,40 @@ +// C program to check if a +// number is prime + +#include +#include +int main() +{ + int n, i, flag = 1; + + // Ask user for input + printf("Enter a number: \n"); + + // Store input number in a variable + scanf("%d", &n); + + // Iterate from 2 to n/2 + for (i = 2; i <= sqrt(n); i++) { + + // If n is divisible by any number between + // 2 and n/2, it is not prime + if (n % i == 0) { + flag = 0; + break; + } + } + + if(n<=1) + flag=0; + else if(n==2) + flag=1; + + if (flag == 1) { + printf("%d is a prime number", n); + } + else { + printf("%d is not a prime number", n); + } + + return 0; +} From 4a7473ec8d619d6f17af37ba959ac5c3689edf8f Mon Sep 17 00:00:00 2001 From: Pummy Jha <64890582+Pummy12@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:56:11 +0530 Subject: [PATCH 491/781] Create create circular queue Optimized code for creation of circular queue. --- create circular queue | 110 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 create circular queue diff --git a/create circular queue b/create circular queue new file mode 100644 index 00000000..66f6c2b7 --- /dev/null +++ b/create circular queue @@ -0,0 +1,110 @@ +#include +# define MAX 5 +int cqueue_arr[MAX]; +int front = -1; +int rear = -1; +void insert(int item) +{ +if((front == 0 && rear == MAX-1) || (front == rear+1)) +{ +printf("Queue Overflow n"); +return; +} +if(front == -1) +{ +front = 0; +rear = 0; +} +else +{ +if(rear == MAX-1) +rear = 0; +else +rear = rear+1; +} +cqueue_arr[rear] = item ; +} +void deletion() +{ +if(front == -1) +{ +printf("Queue Underflown"); +return ; +} +printf("Element deleted from queue is : %dn",cqueue_arr[front]); +if(front == rear) +{ +front = -1; +rear=-1; +} +else +{ +if(front == MAX-1) +front = 0; +else +front = front+1; +} +} +void display() +{ +int front_pos = front,rear_pos = rear; +if(front == -1) +{ +printf("Queue is emptyn"); +return; +} +printf("Queue elements :n"); +if( front_pos <= rear_pos ) +while(front_pos <= rear_pos) +{ +printf("%d ",cqueue_arr[front_pos]); +front_pos++; +} +else +{ +while(front_pos <= MAX-1) +{ +printf("%d ",cqueue_arr[front_pos]) +front_pos++; +} +front_pos = 0; +while(front_pos <= rear_pos) +{ +printf("%d ",cqueue_arr[front_pos]); +front_pos++; +} +} +printf("n"); +} +int main() +{ +int choice,item; +do +{ +printf("1.Insertn"); +printf("2.Deleten"); +printf("3.Displayn"); +printf("4.Quitn"); +printf("Enter your choice : "); +scanf("%d",&choice); +switch(choice) +{ +case 1 : +printf("Input the element for insertion in queue : "); +scanf("%d", &item); +insert(item); +break; +case 2 : +deletion(); +break; +case 3: +display(); +break; +case 4: +break; +default: +printf("Wrong choicen"); +} +}while(choice!=4); +return 0; +} From da16acf5ecfba6daeeaa0ca08ca4980bc78c7575 Mon Sep 17 00:00:00 2001 From: ShambhawiVarchasva <32016470+ShambhawiVarchasva@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:57:01 +0530 Subject: [PATCH 492/781] Create factorial_of_a_large_number.py --- factorial_of_a_large_number.py | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 factorial_of_a_large_number.py diff --git a/factorial_of_a_large_number.py b/factorial_of_a_large_number.py new file mode 100644 index 00000000..12495279 --- /dev/null +++ b/factorial_of_a_large_number.py @@ -0,0 +1,64 @@ +# Python program to compute factorial +# of big numbers + +import sys + +# This function finds factorial of large +# numbers and prints them +def factorial( n) : + res = [None]*500 + # Initialize result + res[0] = 1 + res_size = 1 + + # Apply simple factorial formula + # n! = 1 * 2 * 3 * 4...*n + x = 2 + while x <= n : + res_size = multiply(x, res, res_size) + x = x + 1 + + print ("Factorial of given number is") + i = res_size-1 + while i >= 0 : + sys.stdout.write(str(res[i])) + sys.stdout.flush() + i = i - 1 + + +# This function multiplies x with the number +# represented by res[]. res_size is size of res[] +# or number of digits in the number represented +# by res[]. This function uses simple school +# mathematics for multiplication. This function +# may value of res_size and returns the new value +# of res_size +def multiply(x, res,res_size) : + + carry = 0 # Initialize carry + + # One by one multiply n with individual + # digits of res[] + i = 0 + while i < res_size : + prod = res[i] *x + carry + res[i] = prod % 10; # Store last digit of + # 'prod' in res[] + # make sure floor division is used + carry = prod//10; # Put rest in carry + i = i + 1 + + # Put carry in res and increase result size + while (carry) : + res[res_size] = carry % 10 + # make sure floor division is used + # to avoid floating value + carry = carry // 10 + res_size = res_size + 1 + + return res_size + +# Driver program +factorial(100) + +#This code is contributed by Nikita Tiwari. From e99167cb583048bbe28e981afe7b61f5060136d9 Mon Sep 17 00:00:00 2001 From: Pummy Jha <64890582+Pummy12@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:59:49 +0530 Subject: [PATCH 493/781] Create deleting an element in the array Optimized code for deleting an element in the array quickly. --- deleting an element in the array | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 deleting an element in the array diff --git a/deleting an element in the array b/deleting an element in the array new file mode 100644 index 00000000..af3b20ab --- /dev/null +++ b/deleting an element in the array @@ -0,0 +1,44 @@ +// C++ program to remove a given element from an array +#include +using namespace std; + +// This function removes an element x from arr[] and +// returns new size after removal (size is reduced only +// when x is present in arr[] +int deleteElement(int arr[], int n, int x) +{ +// Search x in array +int i; +for (i=0; i Date: Sat, 17 Oct 2020 20:12:57 +0530 Subject: [PATCH 494/781] Create Reverse the elements of the array Optimized code for reversing the array elements quickly. --- Reverse the elements of the array | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Reverse the elements of the array diff --git a/Reverse the elements of the array b/Reverse the elements of the array new file mode 100644 index 00000000..1d784209 --- /dev/null +++ b/Reverse the elements of the array @@ -0,0 +1,38 @@ +// Iterative C program to reverse an array +#include + +/* Function to reverse arr[] from start to end*/ +void rvereseArray(int arr[], int start, int end) +{ + int temp; + while (start < end) + { + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } +} + +/* Utility that prints out an array on a line */ +void printArray(int arr[], int size) +{ +int i; +for (i=0; i < size; i++) + printf("%d ", arr[i]); + +printf("\n"); +} + +/* Driver function to test above functions */ +int main() +{ + int arr[] = {1, 2, 3, 4, 5, 6}; + int n = sizeof(arr) / sizeof(arr[0]); + printArray(arr, n); + rvereseArray(arr, 0, n-1); + printf("Reversed array is \n"); + printArray(arr, n); + return 0; +} From 638952f4c10ecce0b4376032adc8328716221935 Mon Sep 17 00:00:00 2001 From: Deji verma <69495270+Deji76@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:16:30 +0530 Subject: [PATCH 495/781] Create factorial of number.c optimized code for getting factorail. --- factorial of number.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 factorial of number.c diff --git a/factorial of number.c b/factorial of number.c new file mode 100644 index 00000000..1663258b --- /dev/null +++ b/factorial of number.c @@ -0,0 +1,12 @@ +#include +int main() +{ + int i,fact=1,number; + printf("Enter a number: "); + scanf("%d",&number); + for(i=1;i<=number;i++){ + fact=fact*i; + } + printf("Factorial of %d is: %d",number,fact); +return 0; +} From 4ddc7517a5ef93a4b203c584a9cce69ef455caf1 Mon Sep 17 00:00:00 2001 From: Hemant Kumar <39905635+itshmnt@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:32:09 +0530 Subject: [PATCH 496/781] Create Python 3 Program to print prime numbers in given range optimized solution for Program to print prime numbers in given range in Python 3 --- Python 3 Program to print prime numbers in given range | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Python 3 Program to print prime numbers in given range diff --git a/Python 3 Program to print prime numbers in given range b/Python 3 Program to print prime numbers in given range new file mode 100644 index 00000000..781fb42c --- /dev/null +++ b/Python 3 Program to print prime numbers in given range @@ -0,0 +1,7 @@ +low = int(input("Enter lower range: ")) +high = int(input("Enter upper range: ")) +for num in range(low, high + 1): + if(num > 1): + for i in range(2,num): + if (num % i) == 0: #checking whether the value is not primebreakelse: + print(num, end = " ") From 804504df7d5858c712300a874ddd7de8c9942b5d Mon Sep 17 00:00:00 2001 From: Anush kamath Date: Sat, 17 Oct 2020 20:42:48 +0530 Subject: [PATCH 497/781] Create Program for armstrong number Optimized code for getting the armstrong numbers. --- Program for armstrong number | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Program for armstrong number diff --git a/Program for armstrong number b/Program for armstrong number new file mode 100644 index 00000000..41f0a1aa --- /dev/null +++ b/Program for armstrong number @@ -0,0 +1,20 @@ +#include + +int main() +{ + int armstrong,result=0,remainder; + + printf("Enter a number:\n"); + scanf("%d",&armstrong); + int i=armstrong; + while(i!=0) + { + remainder=i%10; + result=result+remainder*remainder*remainder; + i=i/10; + } + if(result==armstrong) + printf("%d is a armstrong number",armstrong); + else + printf("%d is not a armstrong number",armstrong); +} From 33a08f5863619cc0be13370ffd054e04c0e8191b Mon Sep 17 00:00:00 2001 From: Aniruddh-98 <72970942+Aniruddh-98@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:43:23 +0530 Subject: [PATCH 498/781] Factorial number Program to find Factorial no. in C. --- factorialno | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 factorialno diff --git a/factorialno b/factorialno new file mode 100644 index 00000000..c4b104c9 --- /dev/null +++ b/factorialno @@ -0,0 +1,15 @@ +#include +#include + + int main() + { + int i,fact=1,n; + printf("Enter A Number"); + scanf("%d",&n); + for(i=1,i<=n,i++) + { + fact=fact*i; + } + printf("Factorial of %d is %d",n,fact); + return 0; + } From 71357a3b764d751e776a02db6bb77bd42f44c35b Mon Sep 17 00:00:00 2001 From: Hemant Kumar <39905635+itshmnt@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:50:24 +0530 Subject: [PATCH 499/781] Create Python 3 Program to add 2D Matrices optimized and simple Python 3 Program to add 2D Matrices --- Python 3 Program to add 2D Matrices | 51 +++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Python 3 Program to add 2D Matrices diff --git a/Python 3 Program to add 2D Matrices b/Python 3 Program to add 2D Matrices new file mode 100644 index 00000000..6f88fb87 --- /dev/null +++ b/Python 3 Program to add 2D Matrices @@ -0,0 +1,51 @@ +#getting dimension of matrix + +print "enter n for nxn matrix" +n = input() + +matrix1 = [] +matrix2 = [] + +#taking elements of first matrix + +print "Enter elements of first matrix" +for i in range(0,n): + + #taking elements of first column + + print "Enter elements of ",i,"column, seperated by space" + + #raw_input().split() will split the string + #'1 2 34'.split() will give ['1', '2', '34'] + #map will convert its elements into integers [1, 2, 34] + + matrix1.append(map(int,raw_input().split())) + +print "Matrix 1 is",matrix1 + +#taking elements of second matrix + +print "Enter elements of second matrix" +for i in range(0,n): + #Similar to input taken for 1 matrix + + print "Enter elements of ",i,"column, seperated by space" + matrix2.append(map(int,raw_input().split())) + +print "Matrix 2 is",matrix2 + +#adding + +add_matrix = [] +for i in range(0,n): + a = [] + for j in range(0,n): + + + #making a addition matrix's column to append + #making a 1D matrix with elements as sum of elements of + #respective columns of both matrices + + a.append(matrix1[i][j]+matrix2[i][j]) + add_matrix.append(a) +print "Addition of matrix is",add_matrix From 8132daedcc5bbd76a9a57c6209d0720a197d79fb Mon Sep 17 00:00:00 2001 From: 25zeeshan <64727067+25zeeshan@users.noreply.github.com> Date: Sat, 17 Oct 2020 20:54:55 +0530 Subject: [PATCH 500/781] Create Program to convert binary to octal number and vice versa C Program to convert binary to octal number and vice versa. --- ...vert binary to octal number and vice versa | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Program to convert binary to octal number and vice versa diff --git a/Program to convert binary to octal number and vice versa b/Program to convert binary to octal number and vice versa new file mode 100644 index 00000000..13605b52 --- /dev/null +++ b/Program to convert binary to octal number and vice versa @@ -0,0 +1,28 @@ +#include +#include +int convert(long long bin); +int main() { + long long bin; + printf("Enter a binary number: "); + scanf("%lld", &bin); + printf("%lld in binary = %d in octal", bin, convert(bin)); + return 0; +} + +int convert(long long bin) { + int oct = 0, dec = 0, i = 0; + + while (bin != 0) { + dec += (bin % 10) * pow(2, i); + ++i; + bin /= 10; + } + i = 1; + + while (dec != 0) { + oct += (dec % 8) * i; + dec /= 8; + i *= 10; + } + return oct; +} From 26dfa18a012cf5ed4e74c908d67bda2c63886e68 Mon Sep 17 00:00:00 2001 From: Ashee Mishra <67359998+Ash3010@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:02:43 +0530 Subject: [PATCH 501/781] Create Power of a number(using function) in Python Power of a number using function in Python --- Power of a number(using function) in Python | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Power of a number(using function) in Python diff --git a/Power of a number(using function) in Python b/Power of a number(using function) in Python new file mode 100644 index 00000000..9967df76 --- /dev/null +++ b/Power of a number(using function) in Python @@ -0,0 +1,6 @@ +def pwr(x,n): + ans=x**n + return ans + +x, n = [int(x) for x in input().split()] +print(pwr(x,n)) From fa44644658b3259043a9fc62d8d3ef89a7dbd56a Mon Sep 17 00:00:00 2001 From: Ayoma Katuwawala <55722961+A-Chathumini@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:07:54 +0530 Subject: [PATCH 502/781] Create FibonnaciSeries_10values This is a program code in c which outputs the 10 values of a fibonnaci series --- FibonnaciSeries_10values | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 FibonnaciSeries_10values diff --git a/FibonnaciSeries_10values b/FibonnaciSeries_10values new file mode 100644 index 00000000..928159da --- /dev/null +++ b/FibonnaciSeries_10values @@ -0,0 +1,18 @@ +#include +int fibo(int term); +int main() +{ + int i,term=10; + for(i=0;i Date: Sat, 17 Oct 2020 21:21:35 +0530 Subject: [PATCH 503/781] Create Java Program to find power of any number Java Program to find power of any number --- Java Program to find power of any number | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Java Program to find power of any number diff --git a/Java Program to find power of any number b/Java Program to find power of any number new file mode 100644 index 00000000..2fe050f3 --- /dev/null +++ b/Java Program to find power of any number @@ -0,0 +1,17 @@ +public class Power { + + public static void main(String[] args) { + + int base = 3, exponent = 4; + + long result = 1; + + while (exponent != 0) + { + result *= base; + exponent--; + } + + System.out.println("Answer = " + result); + } +} From 71f6bec166c98fb444c84de5906e975637a42918 Mon Sep 17 00:00:00 2001 From: ranjeetraigawali <36514427+ranjeetraigawali@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:24:25 +0530 Subject: [PATCH 504/781] Create Code for sum of array elements --- Code for sum of array elements | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Code for sum of array elements diff --git a/Code for sum of array elements b/Code for sum of array elements new file mode 100644 index 00000000..b42c2100 --- /dev/null +++ b/Code for sum of array elements @@ -0,0 +1,20 @@ +import java.util.Scanner; +public class AdditionOfElements { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Enter the no. of elements you want to add in array : "); + int n= sc.nextInt(); + int arr[] = new int[n]; + System.out.println("Enter the numbers : "); + for(int i=0;i Date: Sat, 17 Oct 2020 21:26:15 +0530 Subject: [PATCH 505/781] Create CPP program to find largest sum contiguous subarray CPP program to find largest Sum Contiguous subarray. --- ...am to find largest sum contiguous subarray | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 CPP program to find largest sum contiguous subarray diff --git a/CPP program to find largest sum contiguous subarray b/CPP program to find largest sum contiguous subarray new file mode 100644 index 00000000..246df5f4 --- /dev/null +++ b/CPP program to find largest sum contiguous subarray @@ -0,0 +1,28 @@ +#include +#include +using namespace std; + +int maxSubArraySum(int a[], int size) +{ + int max_so_far = INT_MIN, max_ending_here = 0; + + for (int i = 0; i < size; i++) + { + max_ending_here = max_ending_here + a[i]; + if (max_so_far < max_ending_here) + max_so_far = max_ending_here; + + if (max_ending_here < 0) + max_ending_here = 0; + } + return max_so_far; +} + +int main() +{ + int a[] = {-2, -3, 4, -1, -2, 1, 5, -3}; + int n = sizeof(a)/sizeof(a[0]); + int max_sum = maxSubArraySum(a, n); + cout << "Maximum contiguous sum is " << max_sum; + return 0; +} From 5cb2756f0ad863eb24424bf0ea27ac000e200704 Mon Sep 17 00:00:00 2001 From: pmanasi <36513491+pmanasi@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:28:47 +0530 Subject: [PATCH 506/781] Create Find factorial of number Optimized python code for finding factorial of number. --- Find factorial of number | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Find factorial of number diff --git a/Find factorial of number b/Find factorial of number new file mode 100644 index 00000000..dd98440f --- /dev/null +++ b/Find factorial of number @@ -0,0 +1,14 @@ +def fact(n): + f = 1 + for i in range(1, n+1): + f = f * i + return f +num = int(input(" Enter a number: ")) +if num < 0: + print(" b+ve") +elif num == 0 or num == 1: + print("Factorial = 1") +else: + ans = fact(num) + print("Factorial = ", ans) + From 426867fd2e141c7c10e0e2e0d837aa5859ede525 Mon Sep 17 00:00:00 2001 From: ranjeetraigawali <36514427+ranjeetraigawali@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:30:27 +0530 Subject: [PATCH 507/781] Create Code for fibonacci series using java Code for fibonacci series in java --- Code for fibonacci series using java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Code for fibonacci series using java diff --git a/Code for fibonacci series using java b/Code for fibonacci series using java new file mode 100644 index 00000000..3dc8557e --- /dev/null +++ b/Code for fibonacci series using java @@ -0,0 +1,20 @@ +import java.util.Scanner; +public class FibonacciSeries { + public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("Enter range for Fibonacci Series : "); + int no=sc.nextInt(); + int i=0,b=1; + int c=i+b; + System.out.println(i); + System.out.println(c); + for(i=0;i<=no;i++) + { + i=b; + b=c; + c=i+b; + System.out.println(c); + } + } + +} From a111d6bf1d249d3d4524a93e53d398698bde03af Mon Sep 17 00:00:00 2001 From: Ayoma Katuwawala <55722961+A-Chathumini@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:30:44 +0530 Subject: [PATCH 508/781] Create SumOfAllNumbers_In_Array using c Sum of all numbers in the array using recursion --- SumOfAllNumbers_In_Array using c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SumOfAllNumbers_In_Array using c diff --git a/SumOfAllNumbers_In_Array using c b/SumOfAllNumbers_In_Array using c new file mode 100644 index 00000000..f540922b --- /dev/null +++ b/SumOfAllNumbers_In_Array using c @@ -0,0 +1,29 @@ + #include + #include + + int sum_array(int arr[],int n,int i) + { + if(i Date: Sat, 17 Oct 2020 21:36:52 +0530 Subject: [PATCH 509/781] Create Code for factorial of given number Factorial of given number using java --- Code for factorial of given number | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Code for factorial of given number diff --git a/Code for factorial of given number b/Code for factorial of given number new file mode 100644 index 00000000..3c50dbc5 --- /dev/null +++ b/Code for factorial of given number @@ -0,0 +1,15 @@ +import java.util.Scanner; +public class FactorialClass { + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + System.out.println("Enter the number: "); + int no = sc.nextInt(); //5 + for(int i=no-1;i>1;i--)//4,3 + { + no = (no*i); //20+6 + } + System.out.println("Factorial is : "+(no)); + } + +} From 7f8a7210e7eb9a85da9323176bea2055560b1382 Mon Sep 17 00:00:00 2001 From: Ayoma Katuwawala <55722961+A-Chathumini@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:40:22 +0530 Subject: [PATCH 510/781] Create Convert binary to decimal using C --- Convert binary to decimal using C | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Convert binary to decimal using C diff --git a/Convert binary to decimal using C b/Convert binary to decimal using C new file mode 100644 index 00000000..8099518e --- /dev/null +++ b/Convert binary to decimal using C @@ -0,0 +1,21 @@ +#include +#include +int convert_to_dec(long long num); +int main() { + long long num; + printf("Enter a binary number: "); + scanf("%lld", &num); + printf("%d is the decimal value.", convert_to_dec(num)); + return 0; +} + +int convert_to_dec(long long num) { + int dec = 0, i = 0, rem; + while (num != 0) { + rem = num % 10; + num /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From b496071b0f7e48ec426fd7170da6e5fc0fe5f688 Mon Sep 17 00:00:00 2001 From: ranjeetraigawali <36514427+ranjeetraigawali@users.noreply.github.com> Date: Sat, 17 Oct 2020 21:41:43 +0530 Subject: [PATCH 511/781] Create Sorting of array elements using quick sort in java Quick sort using java --- ...of array elements using quick sort in java | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Sorting of array elements using quick sort in java diff --git a/Sorting of array elements using quick sort in java b/Sorting of array elements using quick sort in java new file mode 100644 index 00000000..a85f628f --- /dev/null +++ b/Sorting of array elements using quick sort in java @@ -0,0 +1,50 @@ +class QuickSort +{ + int partition(int arr[], int low, int high) + { + int pivot = arr[high]; + int i = (low-1); + for (int j=low; j Date: Sat, 17 Oct 2020 22:01:12 +0530 Subject: [PATCH 512/781] Create Program to find the largest no in array in O(1) time Complexity. O(1) sol. to find largest no in an array. --- ...rgest no in array in O(1) time Complexity. | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Program to find the largest no in array in O(1) time Complexity. diff --git a/Program to find the largest no in array in O(1) time Complexity. b/Program to find the largest no in array in O(1) time Complexity. new file mode 100644 index 00000000..611dc074 --- /dev/null +++ b/Program to find the largest no in array in O(1) time Complexity. @@ -0,0 +1,26 @@ +#include +using namespace std; +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + int size; + cout<<"Enter the size of the array"<>size; + int arr[size]; + cout<<"Enter the elements of the array"<>arr[i]; + if(arr[i]<=arr[i-1]&&i!=0) + { + arr[i] = arr[i-1]; + } + + } + cout< Date: Sat, 17 Oct 2020 22:02:30 +0530 Subject: [PATCH 513/781] Create Binary to octal using C Convert the user entered binary number to octal and output the value --- Binary to octal using C | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Binary to octal using C diff --git a/Binary to octal using C b/Binary to octal using C new file mode 100644 index 00000000..67f60559 --- /dev/null +++ b/Binary to octal using C @@ -0,0 +1,30 @@ +#include +#include +int convert_to_octal(long long bin); +int main() { + long long bin; + printf("Enter a binary number: "); + scanf("%lld", &bin); + printf("%d is the octal number", convert_to_octal(bin)); + return 0; +} + +int convert_to_octal(long long bin) { + int octal = 0, dec = 0, i = 0; + + + while (bin != 0) { + dec += (bin % 10) * pow(2, i); + ++i; + bin /= 10; + } + i = 1; + + + while (dec != 0) { + octal += (dec % 8) * i; + dec /= 8; + i *= 10; + } + return octal; +} From 47602143152503c5506126ceb1c731659a8f995e Mon Sep 17 00:00:00 2001 From: Pranjul Singhal Date: Sat, 17 Oct 2020 22:09:30 +0530 Subject: [PATCH 514/781] Create Swapping --- Swapping | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Swapping diff --git a/Swapping b/Swapping new file mode 100644 index 00000000..b591f3e0 --- /dev/null +++ b/Swapping @@ -0,0 +1,11 @@ +#include +void main() +{ + int a,b,c; + printf("input two numbers:"); + scanf("%d%d",&a,&b); + c=a; + a=b; + b=c; + printf("a=%d,b=%d",a,b); +} From e161460c87145d1c8b3f483529f839129da0dd0c Mon Sep 17 00:00:00 2001 From: Pranjul Singhal Date: Sat, 17 Oct 2020 22:11:33 +0530 Subject: [PATCH 515/781] Create Swapping --- Swapping | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Swapping diff --git a/Swapping b/Swapping new file mode 100644 index 00000000..b591f3e0 --- /dev/null +++ b/Swapping @@ -0,0 +1,11 @@ +#include +void main() +{ + int a,b,c; + printf("input two numbers:"); + scanf("%d%d",&a,&b); + c=a; + a=b; + b=c; + printf("a=%d,b=%d",a,b); +} From 004268e1f3c34dbf4608419ccaa2223b052b5504 Mon Sep 17 00:00:00 2001 From: prabal <54810517+prabalbansal6183@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:11:33 +0530 Subject: [PATCH 516/781] Create Reverse array in half time complexity reverse array in O(n/2) --- Reverse array in half time complexity | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Reverse array in half time complexity diff --git a/Reverse array in half time complexity b/Reverse array in half time complexity new file mode 100644 index 00000000..f8adbdfa --- /dev/null +++ b/Reverse array in half time complexity @@ -0,0 +1,31 @@ +#include +using namespace std; +void reverses(int arr[],int n) +{ + + for(int i=0;i<(n+1)/2;i++) + { + swap(arr[i],arr[n-i-1]); + } +} +int main() +{ + ios_base::sync_with_stdio(false); + cin.tie(NULL); + cout.tie(NULL); + int size; + cout<<"Enter the size of the array"<>size; + int arr[size]; + cout<<"Enter the elements of the array"<>arr[i]; + } + reverses(arr,size); + for(int i=0;i Date: Sat, 17 Oct 2020 22:14:01 +0530 Subject: [PATCH 517/781] Create Check number is even or odd --- Check number is even or odd | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Check number is even or odd diff --git a/Check number is even or odd b/Check number is even or odd new file mode 100644 index 00000000..a3ad4ec1 --- /dev/null +++ b/Check number is even or odd @@ -0,0 +1,8 @@ +#include +void main() +{ + int a; + printf("enter the number: "); + scanf("%d",&a); + a&1?printf("odd"):printf("even"); +} From 9f7c68f9b8b8db1318387bd125d7937aaa95b9e3 Mon Sep 17 00:00:00 2001 From: Pranjul Singhal Date: Sat, 17 Oct 2020 22:20:10 +0530 Subject: [PATCH 518/781] Create Armstrong --- Armstrong | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Armstrong diff --git a/Armstrong b/Armstrong new file mode 100644 index 00000000..3f130bf0 --- /dev/null +++ b/Armstrong @@ -0,0 +1,25 @@ +#include +#include +void main() +{ +int p,t,n,r,c=0,s=0; +printf("enter the range"); +scanf("%d",&p); +p=n; +t=n; +while(p!=0) +{ +p=p/10; +c++; +} +while(t!=0) +{ +r=t%10; +t=t/10; +s=s+pow(r,c); +} +if(s==n) +printf("armstrong"); +else +printf("not armstrong"); +} From 15b0667852d2d1df87d3da7220c6c87c3d90ebe6 Mon Sep 17 00:00:00 2001 From: porwalarchit <55993981+porwalarchit@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:20:58 +0530 Subject: [PATCH 519/781] Create Length of String without Using strlen() Function Optimised Code :) --- Length of String without Using strlen() Function | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Length of String without Using strlen() Function diff --git a/Length of String without Using strlen() Function b/Length of String without Using strlen() Function new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/Length of String without Using strlen() Function @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 944caf0a1e0f193cc6c5ea9d6a896926578b2288 Mon Sep 17 00:00:00 2001 From: koshal111 <72223579+koshal111@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:23:51 +0530 Subject: [PATCH 520/781] Create Passing Arrays in C we are passing array --- Passing Arrays in C | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Passing Arrays in C diff --git a/Passing Arrays in C b/Passing Arrays in C new file mode 100644 index 00000000..f6de3e36 --- /dev/null +++ b/Passing Arrays in C @@ -0,0 +1,8 @@ +#include +void display(int age) { +printf("%d", age); +} +int main() { +int ageArray[] = { 2, 3, 4 }; +display(ageArray[2]); //Passing array element ageArray[2] only. +return 0; From 30f06924a304df8ea153cc32a4ea0ed7d36e4c2c Mon Sep 17 00:00:00 2001 From: porwalarchit <55993981+porwalarchit@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:25:03 +0530 Subject: [PATCH 521/781] Create C Program to Find ASCII Value of a Character Optimised Code --- C Program to Find ASCII Value of a Character | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 C Program to Find ASCII Value of a Character diff --git a/C Program to Find ASCII Value of a Character b/C Program to Find ASCII Value of a Character new file mode 100644 index 00000000..dcbf2c24 --- /dev/null +++ b/C Program to Find ASCII Value of a Character @@ -0,0 +1,10 @@ +#include +int main() { + char c; + printf("Enter a character: "); + scanf("%c", &c); + + printf("ASCII value of %c = %d", c, c); + + return 0; +} From 76beb6217b70cddab5868a555c1f62068f14dc9b Mon Sep 17 00:00:00 2001 From: porwalarchit <55993981+porwalarchit@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:25:57 +0530 Subject: [PATCH 522/781] Create C Program to Calculate the Power of a Number Optimised Code --- C Program to Calculate the Power of a Number | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 C Program to Calculate the Power of a Number diff --git a/C Program to Calculate the Power of a Number b/C Program to Calculate the Power of a Number new file mode 100644 index 00000000..e7d59525 --- /dev/null +++ b/C Program to Calculate the Power of a Number @@ -0,0 +1,16 @@ +#include +int main() { + int base, exp; + long long result = 1; + printf("Enter a base number: "); + scanf("%d", &base); + printf("Enter an exponent: "); + scanf("%d", &exp); + + while (exp != 0) { + result *= base; + --exp; + } + printf("Answer = %lld", result); + return 0; +} From 0fb582f2f598ea1d6f0d2bdab8be133bb765c116 Mon Sep 17 00:00:00 2001 From: Kshitij Tiwari Date: Sat, 17 Oct 2020 22:32:27 +0530 Subject: [PATCH 523/781] Fibonacci series using Recursion --- FibonacciSeries.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 FibonacciSeries.cpp diff --git a/FibonacciSeries.cpp b/FibonacciSeries.cpp new file mode 100644 index 00000000..cb212a0c --- /dev/null +++ b/FibonacciSeries.cpp @@ -0,0 +1,20 @@ +#include +using namespace std; +int fib(int x) { + if((x==1)||(x==0)) { + return(x); + }else { + return(fib(x-1)+fib(x-2)); + } +} +int main() { + int x , i=0; + cout << "Enter the number of terms of series : "; + cin >> x; + cout << "\nFibonnaci Series : "; + while(i < x) { + cout << " " << fib(i); + i++; + } + return 0; +} From 02f4ad615474874c17330a674f5237997d02813b Mon Sep 17 00:00:00 2001 From: Manas Garg Date: Sat, 17 Oct 2020 22:33:26 +0530 Subject: [PATCH 524/781] Create Binary To Decimal_Manas Hey! Saw your YouTube video and sending a PR --- Binary To Decimal_Manas | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Binary To Decimal_Manas diff --git a/Binary To Decimal_Manas b/Binary To Decimal_Manas new file mode 100644 index 00000000..02d2537f --- /dev/null +++ b/Binary To Decimal_Manas @@ -0,0 +1,27 @@ +# Python3 program to convert +# binary to decimal + +# Function to convert +# binary to decimal +def binaryToDecimal(n): + num = n; + dec_value = 0; + + # Initializing base + # value to 1, i.e 2 ^ 0 + base = 1; + + temp = num; + while(temp): + last_digit = temp % 10; + temp = int(temp / 10); + + dec_value += last_digit * base; + base = base * 2; + return dec_value; + +# Driver Code +num = 10101001; +print(binaryToDecimal(num)); + +# This code is contributed by Manas Garg From 762d429e33f6434747e0ee5f1027d81693e06d28 Mon Sep 17 00:00:00 2001 From: preetiahuja18 <72223546+preetiahuja18@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:41:16 +0530 Subject: [PATCH 525/781] Create program for rock,paper and scissor this is a program of rock paper and scissor --- program for rock,paper and scissor | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 program for rock,paper and scissor diff --git a/program for rock,paper and scissor b/program for rock,paper and scissor new file mode 100644 index 00000000..0a6579f3 --- /dev/null +++ b/program for rock,paper and scissor @@ -0,0 +1,24 @@ +#include +#include +#include + +int generateRandomNumber(int n) +{ + srand(time(NULL)); //srand takes seed as an input and is defined inside stdlib.h + return rand() % n; +} +//Create Rock, Paper & Scissors Game +// Player 1: rock +// Player 2 (computer): scissors -->player 1 gets 1 point + +// rock vs scissors - rock wins +// paper vs scissors - scissors wins +// paper vs rock - paper wins +// Write a C program to allow user to play this game three times with computer. Log the scores of computer and the player. Display the name of the winner at the end +// Notes: You have to display name of the player during the game. Take users name as an input from the user. + +int main() +{ + printf("The random number between 0 to 5 is %d\n", generateRandomNumber(5)); + return 0; +} From 39c33ffb5acd3ad87969b5c19aa0429a4d71d826 Mon Sep 17 00:00:00 2001 From: KARAN152 <46127185+KARAN152@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:43:16 +0530 Subject: [PATCH 526/781] Create Reverse an array in Java a good code for reverse an array quickly --- Reverse an array in Java | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Reverse an array in Java diff --git a/Reverse an array in Java b/Reverse an array in Java new file mode 100644 index 00000000..5c430612 --- /dev/null +++ b/Reverse an array in Java @@ -0,0 +1,26 @@ + + +public class reverseArray { + + + static void reverse(int a[], int n) + { + int[] b = new int[n]; + int j = n; + for (int i = 0; i < n; i++) { + b[j - 1] = a[i]; + j = j - 1; + } + + System.out.println("Reversed array is: \n"); + for (int k = 0; k < n; k++) { + System.out.println(b[k]); + } + } + + public static void main(String[] args) + { + int [] arr = {10, 20, 30, 40, 50}; + reverse(arr, arr.length); + } +} From 7f06d6ee4066969f866458ab454fdfa715860a1b Mon Sep 17 00:00:00 2001 From: Kshitij Tiwari Date: Sat, 17 Oct 2020 22:47:25 +0530 Subject: [PATCH 527/781] Binary To Decimal conversion --- BinartToDecimal.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 BinartToDecimal.cpp diff --git a/BinartToDecimal.cpp b/BinartToDecimal.cpp new file mode 100644 index 00000000..c5495ce8 --- /dev/null +++ b/BinartToDecimal.cpp @@ -0,0 +1,30 @@ +#include +#include + +using namespace std; + +int convertBinaryToDecimal(long long); + +int main() +{ + long long n; + + cout << "Enter a binary number: "; + cin >> n; + + cout << n << " in binary = " << convertBinaryToDecimal(n) << "in decimal"; + return 0; +} + +int convertBinaryToDecimal(long long n) +{ + int decimalNumber = 0, i = 0, remainder; + while (n!=0) + { + remainder = n%10; + n /= 10; + decimalNumber += remainder*pow(2,i); + ++i; + } + return decimalNumber; +} From f60a02500a709295d68678b577a4880712165c14 Mon Sep 17 00:00:00 2001 From: Anush kamath Date: Sat, 17 Oct 2020 22:50:22 +0530 Subject: [PATCH 528/781] Create Converting Binary into Decimal numbers Optimized code to convert Binary into Decimal numbers --- Converting Binary into Decimal numbers | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Converting Binary into Decimal numbers diff --git a/Converting Binary into Decimal numbers b/Converting Binary into Decimal numbers new file mode 100644 index 00000000..ec7d0a47 --- /dev/null +++ b/Converting Binary into Decimal numbers @@ -0,0 +1,21 @@ +#include + +int main() + +{ + int n,s=0,i=0; + + printf("Enter the binary numbers:"); + scanf("%d",&n); + + while(n>0) + { + s=s+(n%10)*pow(2,i); + n=n/10; + i++; + } + + printf("Entered number in decimal is %d",s); + + getch(); +} From 66779f29c72151d2ee00bfabfd80a071dfb5616b Mon Sep 17 00:00:00 2001 From: KARAN152 <46127185+KARAN152@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:02:59 +0530 Subject: [PATCH 529/781] Create Count of Leap Years in a given year range a fine code for count of leap years in given year range --- Count of Leap Years in a given year range | 33 +++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Count of Leap Years in a given year range diff --git a/Count of Leap Years in a given year range b/Count of Leap Years in a given year range new file mode 100644 index 00000000..b7cebb12 --- /dev/null +++ b/Count of Leap Years in a given year range @@ -0,0 +1,33 @@ + + +#include + +using namespace std; + + +int calNum(int year) +{ + return (year / 4) - (year / 100) + + (year / 400); +} + + +void leapNum(int l, int r) +{ + l--; + int num1 = calNum(r); + int num2 = calNum(l); + cout << num1 - num2 << endl; +} + + +int main() +{ + int l1 = 1, r1 = 400; + leapNum(l1, r1); + + int l2 = 400, r2 = 2000; + leapNum(l2, r2); + + return 0; +} From b6eb50154bb0918847237942f882d7ace62db097 Mon Sep 17 00:00:00 2001 From: Anush kamath Date: Sat, 17 Oct 2020 23:05:38 +0530 Subject: [PATCH 530/781] Create To find the Fibonacci series in C Optimized code to find the series of Fibonacci --- To find the Fibonacci series in C | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 To find the Fibonacci series in C diff --git a/To find the Fibonacci series in C b/To find the Fibonacci series in C new file mode 100644 index 00000000..93fb0d5b --- /dev/null +++ b/To find the Fibonacci series in C @@ -0,0 +1,20 @@ +#include +void main() + +{ + long long int num,i,a=-1,b=1,c; + + printf("Enter a number:"); + scanf("%d",&num); + + for(i=0;i<=num;i++) + + { + c=a+b; + printf("%lld ",c); + a=b; + b=c; + } + + getch(); +} From 70fc72fcaf4bbf1c9ffffd07f7e0a16a224643a8 Mon Sep 17 00:00:00 2001 From: pmanasi <36513491+pmanasi@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:12:59 +0530 Subject: [PATCH 531/781] Create Count of vowel and Consonants in string Optimized python code for calculating count of vowels and consonants in string. --- Count of vowel and Consonants in string | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Count of vowel and Consonants in string diff --git a/Count of vowel and Consonants in string b/Count of vowel and Consonants in string new file mode 100644 index 00000000..40e599e8 --- /dev/null +++ b/Count of vowel and Consonants in string @@ -0,0 +1,10 @@ +s1 = input("enter a string ") +vc, cc = 0, 0 + +for s in s1: + if s.isalpha(): + if s in [ 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' ] : + vc = vc + 1 + else: + cc = cc + 1 +print("vowels = ", vc, " consonants = ", cc) From e03cfb676b498505a34eb2adc4248c2942bda4ad Mon Sep 17 00:00:00 2001 From: Manas Garg Date: Sat, 17 Oct 2020 23:13:08 +0530 Subject: [PATCH 532/781] Create Find_Length_of_string_Manas Hi, Yet another submission by me. Saw your coding potter channel. --- Find_Length_of_string_Manas | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Find_Length_of_string_Manas diff --git a/Find_Length_of_string_Manas b/Find_Length_of_string_Manas new file mode 100644 index 00000000..8a02797d --- /dev/null +++ b/Find_Length_of_string_Manas @@ -0,0 +1,15 @@ +# Python code to demonstrate string length +# using for loop + +# Returns length of string +def findLen(str): + counter = 0 + for i in str: + counter += 1 + return counter + + +str = "manas" +print(findLen(str)) + +# This code is contributed by Manas From f78da4e8d7037918b81db2f64f9aa90d26ab0a1c Mon Sep 17 00:00:00 2001 From: Manas Garg Date: Sat, 17 Oct 2020 23:16:07 +0530 Subject: [PATCH 533/781] Create Largest_element_in_array_Manas Hi bro, Saw your coding potter channel and am making my 3rd PR --- Largest_element_in_array_Manas | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Largest_element_in_array_Manas diff --git a/Largest_element_in_array_Manas b/Largest_element_in_array_Manas new file mode 100644 index 00000000..aac415d8 --- /dev/null +++ b/Largest_element_in_array_Manas @@ -0,0 +1,25 @@ +# Python3 program to find maximum +# in arr[] of size n + +# python function to find maximum +# in arr[] of size n +def largest(arr,n): + + # Initialize maximum element + max = arr[0] + + # Traverse array elements from second + # and compare every element with + # current max + for i in range(1, n): + if arr[i] > max: + max = arr[i] + return max + +# Driver Code +arr = [10, 324, 45, 90, 9808] +n = len(arr) +Ans = largest(arr,n) +print ("Largest in given array is",Ans) + +# This code is contributed by Manas From 0e1c9adf600c1f241cea163494620386e7f4b857 Mon Sep 17 00:00:00 2001 From: Manas Garg Date: Sat, 17 Oct 2020 23:19:41 +0530 Subject: [PATCH 534/781] Create prime_number_inrange_Manas Hi, Saw your coding potter channel and am making my 4th PR --- prime_number_inrange_Manas | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 prime_number_inrange_Manas diff --git a/prime_number_inrange_Manas b/prime_number_inrange_Manas new file mode 100644 index 00000000..06f5afdf --- /dev/null +++ b/prime_number_inrange_Manas @@ -0,0 +1,15 @@ +# Python program to print all +# prime number in an interval +#number should be greater than 1 +start = 11 +end = 25 + +for i in range(start,end): +if i>1: + for j in range(2,i): + if(i % j==0): + break + else: + print(i) + +# Code contributed by Manas From 1940b683f53caf5145564163db63d00387d97d1c Mon Sep 17 00:00:00 2001 From: anandxkumar2 <72942877+anandxkumar2@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:29:39 +0530 Subject: [PATCH 535/781] Create Program to sort given array (ascending & descending) Sorting Using Merge Sort (Ascending) --- ... sort given array (ascending & descending) | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 Program to sort given array (ascending & descending) diff --git a/Program to sort given array (ascending & descending) b/Program to sort given array (ascending & descending) new file mode 100644 index 00000000..a5910436 --- /dev/null +++ b/Program to sort given array (ascending & descending) @@ -0,0 +1,75 @@ +#include +using namespace std; +void merge(int *a,int *x,int *y,int s,int e) +{ + int i=s; + int k=s; + int mid=(s+e)/2; + int j=mid+1; + while(i<=mid && j<=e) + { + if(x[i]>=y[j]) + { + a[k]=y[j]; + j++; + k++; + } + else + { + a[k]=x[i]; + k++; + i++; + } + } + while(i<=mid) + { + a[k]=x[i]; + i++; + k++; + } + while(j<=e) + { + a[k]=y[j]; + j++; + k++; + } + +} +void sort1(int *a,int s,int e) +{ + if(s==e) + { + return; + } + int x[100],y[100]; + int mid=(s+e)/2; + for(int i=s;i<=mid;i++) + { + x[i]=a[i]; + } + for(int i=mid+1;i<=e;i++) + { + y[i]=a[i]; + } + sort1(x,s,mid); + sort1(y,mid+1,e); + merge(a,x,y,s,e); + +} +int main() +{ + int a[100],n; + cout<<"Enter length of array"<>n; + cout<<"Enter elements"<>a[i]; + } + sort1(a,0,n-1); + for(int i=0;i Date: Sat, 17 Oct 2020 23:32:52 +0530 Subject: [PATCH 536/781] Create Multiply 2D or 3D matrices Optimized python code for multiplying 2D or 3D matrices. --- Multiply 2D or 3D matrices | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Multiply 2D or 3D matrices diff --git a/Multiply 2D or 3D matrices b/Multiply 2D or 3D matrices new file mode 100644 index 00000000..e16f8ab0 --- /dev/null +++ b/Multiply 2D or 3D matrices @@ -0,0 +1,19 @@ +X = [[12,7,3], + [4,5,6], + [7,8,9]] + +Y = [[5,8,1,2], + [6,7,3,0], + [4,5,9,1]] + +result = [[0,0,0,0], + [0,0,0,0], + [0,0,0,0]] + +for i in range(len(X)): + for j in range(len(Y[0])): + for k in range(len(Y)): + result[i][j] += X[i][k] * Y[k][j] + +for r in result: + print(r) From 9e0e2c62cb74cb83e070a01953324db9a3cacb7d Mon Sep 17 00:00:00 2001 From: ayush-1998 <64705130+ayush-1998@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:43:41 +0530 Subject: [PATCH 537/781] Fibonacci Series Optimized code for Fibonacci Series in Java using Dynamic Programming. --- Fibonacci Series Using Dynamic Programming | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Fibonacci Series Using Dynamic Programming diff --git a/Fibonacci Series Using Dynamic Programming b/Fibonacci Series Using Dynamic Programming new file mode 100644 index 00000000..8d75d235 --- /dev/null +++ b/Fibonacci Series Using Dynamic Programming @@ -0,0 +1,40 @@ +import java.util.*; +class Solution { + + // Function to find the fibonacci Series + static int fib(int n) + { + + // Declare an array to store + // Fibonacci numbers. + // 1 extra to handle case, n = 0 + int Fibonacci[] = new int[n + 2]; + + int i; + + // 0th and 1st number of + // the series are 0 and 1 + Fibonacci[0] = 0; + Fibonacci[1] = 1; + + for (i = 2; i <= n; i++) { + + // Add the previous 2 numbers + // in the series and store it + Fibonacci[i] = Fibonacci[i - 1] + Fibonacci[i - 2]; + } + + // Nth Fibonacci Number + return Fibonacci[n]; + } + + public static void main(String args[]) + { + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); + + + for (int i = 0; i < N; i++) + System.out.print(fib(i) + " "); + } +} From f0d2470a4eb4cd7e1dd4e6fee18cde98b3727540 Mon Sep 17 00:00:00 2001 From: anandxkumar2 <72942877+anandxkumar2@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:48:32 +0530 Subject: [PATCH 538/781] Create Program to print Fibonnaci Series using Recursion Fibonnaci using recursion --- ... to print Fibonnaci Series using Recursion | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Program to print Fibonnaci Series using Recursion diff --git a/Program to print Fibonnaci Series using Recursion b/Program to print Fibonnaci Series using Recursion new file mode 100644 index 00000000..cb212a0c --- /dev/null +++ b/Program to print Fibonnaci Series using Recursion @@ -0,0 +1,20 @@ +#include +using namespace std; +int fib(int x) { + if((x==1)||(x==0)) { + return(x); + }else { + return(fib(x-1)+fib(x-2)); + } +} +int main() { + int x , i=0; + cout << "Enter the number of terms of series : "; + cin >> x; + cout << "\nFibonnaci Series : "; + while(i < x) { + cout << " " << fib(i); + i++; + } + return 0; +} From 70494a3d34d9d2721e9c0e20e813e1241758fc8b Mon Sep 17 00:00:00 2001 From: anandxkumar2 <72942877+anandxkumar2@users.noreply.github.com> Date: Sat, 17 Oct 2020 23:50:18 +0530 Subject: [PATCH 539/781] Create Program to print Fibonnaci Series Recursive approach Fibonnaci series using recursion --- ... print Fibonnaci Series Recursive approach | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Program to print Fibonnaci Series Recursive approach diff --git a/Program to print Fibonnaci Series Recursive approach b/Program to print Fibonnaci Series Recursive approach new file mode 100644 index 00000000..cb212a0c --- /dev/null +++ b/Program to print Fibonnaci Series Recursive approach @@ -0,0 +1,20 @@ +#include +using namespace std; +int fib(int x) { + if((x==1)||(x==0)) { + return(x); + }else { + return(fib(x-1)+fib(x-2)); + } +} +int main() { + int x , i=0; + cout << "Enter the number of terms of series : "; + cin >> x; + cout << "\nFibonnaci Series : "; + while(i < x) { + cout << " " << fib(i); + i++; + } + return 0; +} From 8b37f5f4e1328c56a15644ac84e83b7dc04ad149 Mon Sep 17 00:00:00 2001 From: anandxkumar2 <72942877+anandxkumar2@users.noreply.github.com> Date: Sun, 18 Oct 2020 00:06:00 +0530 Subject: [PATCH 540/781] Created program to find prime no using recurison Using recursion to find whether number is prime or not --- Prime Number using Recursion | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Prime Number using Recursion diff --git a/Prime Number using Recursion b/Prime Number using Recursion new file mode 100644 index 00000000..fdeab1d4 --- /dev/null +++ b/Prime Number using Recursion @@ -0,0 +1,33 @@ +#include +using namespace std; + +bool isPrime(int n, int d); +int main() +{ +int number; +cout <<"Enter number >= 1"; +cin >> number; +if(isPrime(number)) + { + return + cout << "Yes"; + else + return + cout << "No"; + } + return 0; +} + bool isPrime(int n, int d) + { + if(n<2) + return 0; + if(d == 1) + return true; + else + { + if(n % d == 0) + return false; + else + return isPrime(n, d - 1); + } + } From c34fe9d11826e4bb2d70e7e0abd9e9749bdd9f67 Mon Sep 17 00:00:00 2001 From: ayush-1998 <64705130+ayush-1998@users.noreply.github.com> Date: Sun, 18 Oct 2020 00:16:16 +0530 Subject: [PATCH 541/781] Lex Program to find length of string Lex Program to find length of a string. Lex reads an input stream specifying the lexical analyzer and outputs source code implementing the lexer in the C programming language. --- Program to find length of String | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Program to find length of String diff --git a/Program to find length of String b/Program to find length of String new file mode 100644 index 00000000..dbca6eb2 --- /dev/null +++ b/Program to find length of String @@ -0,0 +1,18 @@ +/*lex program to find the length of a string*/ + +%{ + #include + int length; +%} + +/* Rules Section*/ +%% + [a-z A-Z 0-9]+ {length=yyleng; } +%% + +int main() + { + yylex(); + printf("length of given string is : %d", length); + return 0; + } From c0aa454d23bc17c5dc38d31bc52281a9b6d001dd Mon Sep 17 00:00:00 2001 From: Ayush-Aryan-0 <72189464+Ayush-Aryan-0@users.noreply.github.com> Date: Sun, 18 Oct 2020 00:21:36 +0530 Subject: [PATCH 542/781] Create convert Integers into a Strings using c++ --- convert Integers into a Strings using c++ | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 convert Integers into a Strings using c++ diff --git a/convert Integers into a Strings using c++ b/convert Integers into a Strings using c++ new file mode 100644 index 00000000..efe3cb38 --- /dev/null +++ b/convert Integers into a Strings using c++ @@ -0,0 +1,18 @@ +#include +#include +#include +template +std::string to_string(T t, std::ios_base & (*f)(std::ios_base&)) +{ + std::ostringstream oss; + oss << f << t; + return oss.str(); +} +int main() +{ + // the second parameter of to_string() should be one of + // std::hex, std::dec or std::oct + std::cout<(123456, std::hex)<(123456, std::oct)< Date: Sun, 18 Oct 2020 00:28:47 +0530 Subject: [PATCH 543/781] Reverse an array using pointers In this program, we make use of * operator. In the reverse function, we take two pointers one pointing at the beginning of the array, other pointing at end of the array. The contents of the memory location pointed by these two pointers are swapped and then the value of the first pointer is increased and that of the second pointer is decreased. --- Reverse an array using pointers | 57 +++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 Reverse an array using pointers diff --git a/Reverse an array using pointers b/Reverse an array using pointers new file mode 100644 index 00000000..f9abab55 --- /dev/null +++ b/Reverse an array using pointers @@ -0,0 +1,57 @@ + +#include +using namespace std; + +// Function to swap two memory contents +void swap(int* a, int* b) +{ + int temp = *a; + *a = *b; + *b = temp; +} + +// Function to reverse the array through pointers +void reverse(int array[], int array_size) +{ + + // pointer1 pointing at the beginning of the array + int *pointer1 = array, + + // pointer2 pointing at end of the array + *pointer2 = array + array_size - 1; + while (pointer1 < pointer2) { + swap(pointer1, pointer2); + pointer1++; + pointer2--; + } +} + +// Function to print the array +void print(int* array, int array_size) +{ + + // Length pointing at end of the array + int *length = array + array_size, + + // Position pointing to the beginning of the array + *position = array; + cout << "Array = "; + for (position = array; position < length; position++) + cout << *position << " "; +} + +// Driver function +int main() +{ + + // Array to hold the values + int array[] = { 2, 4, -6, 5, 8, -1 }; + + cout << "Original "; + print(array, 6); + + cout << "Reverse "; + reverse(array, 6); + print(array, 6); + return 0; +} From 42a64daff6501faedd0f6843b07a9db09c43df05 Mon Sep 17 00:00:00 2001 From: AaronF3PS <43633555+AaronF3PS@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:00:00 +0300 Subject: [PATCH 544/781] Create Fibonacci Series-Recursion-C Used recursion to solve Fibonacci Series. Language used:C .Done by Aaron for Hacktoberfest --- Fibonnaci Series/Fibonacci Series-Recursion-C | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Fibonnaci Series/Fibonacci Series-Recursion-C diff --git a/Fibonnaci Series/Fibonacci Series-Recursion-C b/Fibonnaci Series/Fibonacci Series-Recursion-C new file mode 100644 index 00000000..bb84cf84 --- /dev/null +++ b/Fibonnaci Series/Fibonacci Series-Recursion-C @@ -0,0 +1,30 @@ +#include + +int fibonacci(int); + +int main() +{ + int n, i = 0, c; + + scanf("%d",&n); + + printf("Fibonacci series\n"); + + for ( c = 1 ; c <= n ; c++ ) + { + printf("%d\n", fibonacci(i)); + i++; + } + + return 0; +} + +int fibonacci(int n) +{ + if ( n == 0 ) + return 0; + else if ( n == 1 ) + return 1; // 0+1=1 + else + return ( Fibonacci(n-1) + Fibonacci(n-2) );//recursively calls fibonacci function +} From 0ff680b989a825912f799276acf11f063f460120 Mon Sep 17 00:00:00 2001 From: AaronF3PS <43633555+AaronF3PS@users.noreply.github.com> Date: Sat, 17 Oct 2020 22:06:04 +0300 Subject: [PATCH 545/781] Create Power of Number-C Used C to find the Power of any Number. Done by Aaron for Hacktoberfest. --- Power of Number-C | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Power of Number-C diff --git a/Power of Number-C b/Power of Number-C new file mode 100644 index 00000000..f77375a2 --- /dev/null +++ b/Power of Number-C @@ -0,0 +1,24 @@ +#include + +int main() +{ + int base, exp; + long long pow = 1; + int i; + + + printf("Enter base: "); + scanf("%d", &base); + printf("Enter exponent: "); + scanf("%d", &exp); + + + for(i=1; i<=exp; i++) + { + power = pow*base; + } + + printf("%d ^ %d = %lld", base, exp, pow); + + return 0; +} From 00108b34e13608ecec75143f9b1dad79803644fd Mon Sep 17 00:00:00 2001 From: Samiksha sandip sankar Date: Sun, 18 Oct 2020 00:36:32 +0530 Subject: [PATCH 546/781] Program to find larget number in array This is program in java using for loop --- Program to find larget number in array | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Program to find larget number in array diff --git a/Program to find larget number in array b/Program to find larget number in array new file mode 100644 index 00000000..9b282b67 --- /dev/null +++ b/Program to find larget number in array @@ -0,0 +1,17 @@ +public class Largest { + + public static void main(String[] args) { + + + int[] numFirstArray = { 3,6,8,9,6,2}; + + int largest = numFirstArray[0]; + + for (int num: numFirstArray) { + if(largest < num) + largest = num; + } + + System.out.format("Largest element in array : "+ largest); + } +} From c321e1ac6e48480610a0a67fa5d7aaeb4c55b58d Mon Sep 17 00:00:00 2001 From: Samiksha sandip sankar Date: Sun, 18 Oct 2020 00:45:34 +0530 Subject: [PATCH 547/781] Program to find smallest number in array This program is in java --- Program to find smallest number in array | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Program to find smallest number in array diff --git a/Program to find smallest number in array b/Program to find smallest number in array new file mode 100644 index 00000000..333d9092 --- /dev/null +++ b/Program to find smallest number in array @@ -0,0 +1,17 @@ +public class Smallest{ + + public static void main(String[] args) { + + + int[] numFirstArray = { 3,6,8,9,6,2}; + + int smallest = numFirstArray[0]; + + for (int num: numFirstArray) { + if(smallest > num) + smallest = num; + } + + System.out.format("Smallest element in array : "+ smallest); + } +} From fa7f026e11fca99ce37a5474f61863774d609f6f Mon Sep 17 00:00:00 2001 From: Jatin Mankar <62370452+jatinmankar8@users.noreply.github.com> Date: Sun, 18 Oct 2020 00:59:18 +0530 Subject: [PATCH 548/781] Program to find factorial of number using C++ Optimised code to find factorial of a number --- Program to find factorial of number using C++ | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program to find factorial of number using C++ diff --git a/Program to find factorial of number using C++ b/Program to find factorial of number using C++ new file mode 100644 index 00000000..2dba75a8 --- /dev/null +++ b/Program to find factorial of number using C++ @@ -0,0 +1,10 @@ +##Program to find factorial of number +main(){ +int n,fact=1; +cin>>n; +if(n==0) +cout<<"1"; +if(n>1){ +for(int i=1;i<=n;i++){ +fact=fact*i;} +cout< Date: Sun, 18 Oct 2020 01:00:50 +0530 Subject: [PATCH 549/781] Update BinarySearch.cpp simpler and direct code --- BinarySearch.cpp | 65 ++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 41 deletions(-) diff --git a/BinarySearch.cpp b/BinarySearch.cpp index 7c9fe7db..8afb3afc 100644 --- a/BinarySearch.cpp +++ b/BinarySearch.cpp @@ -1,44 +1,27 @@ -// BINARY SEARCH - -#include +#include using namespace std; -clock_t start; -int Bin_Search(int x,int arr[],int n){ - start=clock(); - int low=0,high=n-1; - while(low<=high){ - int mid=low+(high-low)/2; - if(arr[mid]==x) return mid; - if(arr[mid]num) + end=middle-1; + else + start=middle+1; + + } + return -1; } -int main(){ - int n; cin>>n; - int arr[n]; - for(int i=0;i>num; + int n = sizeof(arr)/ sizeof(arr[0]); + int ans=binarysearch(arr,num,0,n-1); + cout< Date: Sun, 18 Oct 2020 01:06:06 +0530 Subject: [PATCH 550/781] Create Number of leap years in between a range --- Find leap year in a given range | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Find leap year in a given range diff --git a/Find leap year in a given range b/Find leap year in a given range new file mode 100644 index 00000000..2a718199 --- /dev/null +++ b/Find leap year in a given range @@ -0,0 +1,33 @@ +#include + +using namespace std; + +// Function to calculate the number +// of leap years in range of (1, year) +int calNum(int year) +{ + return (year / 4) - (year / 100) + + (year / 400); +} + +// Function to calculate the number +// of leap years in given range +void leapNum(int l, int r) +{ + l--; + int num1 = calNum(r); + int num2 = calNum(l); + cout<<"Number of leap years : "; + cout << num1 - num2 << endl; +} + + +int main() +{ + int l,r; + cout<<"Enter range for which we want to calculate leap years"<>l>>r; + leapNum(l, r); + + return 0; +} From 677dfa530193299f1b3708e6570e8fd41a6e0e64 Mon Sep 17 00:00:00 2001 From: Jatin Mankar <62370452+jatinmankar8@users.noreply.github.com> Date: Sun, 18 Oct 2020 01:08:39 +0530 Subject: [PATCH 551/781] Program to find smallest element in array using C++ Optimized Code of Program to find the smallest element in the array --- ...ram to find smallest element in array using C++ | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Program to find smallest element in array using C++ diff --git a/Program to find smallest element in array using C++ b/Program to find smallest element in array using C++ new file mode 100644 index 00000000..b79eafdf --- /dev/null +++ b/Program to find smallest element in array using C++ @@ -0,0 +1,14 @@ +##Program to find smallest element in array +main(){ +int n; +cout<<"Enter length of arrays" +cin>>n; +int s[n]; +for(int i=0;i>s[i];} +int min=s[0] +for(int j=0;js[i]) +max=s[i]; +} +cout< Date: Sun, 18 Oct 2020 01:09:08 +0530 Subject: [PATCH 552/781] Program to find largest element in array using C++ Optimized code to Program to find largest element in array --- Program to find largest element in array using C++ | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Program to find largest element in array using C++ diff --git a/Program to find largest element in array using C++ b/Program to find largest element in array using C++ new file mode 100644 index 00000000..cb472b6d --- /dev/null +++ b/Program to find largest element in array using C++ @@ -0,0 +1,14 @@ +##Program to find largest element in array +main(){ +int n; +cout<<"Enter length of arrays" +cin>>n; +int s[n]; +for(int i=0;i>s[i];} +int max=s[0] +for(int j=0;j Date: Sun, 18 Oct 2020 01:14:14 +0530 Subject: [PATCH 553/781] Update C Program for Insertion Sort --- C Program for Insertion Sort | 62 +++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/C Program for Insertion Sort b/C Program for Insertion Sort index 36b44bfb..174ba4fd 100644 --- a/C Program for Insertion Sort +++ b/C Program for Insertion Sort @@ -1,30 +1,54 @@ #include -#include +#include -int main() +void insert(int arr[], int i) { -int a[50],c,n,i,j,key; -printf("enter number of elements to enter"); -scanf("%d",&n); -for(i=0;i= 0 && arr[j] > key) + { + arr[j + 1] = arr[j]; + j = j - 1; + } + arr[j + 1] = key; } -for(j=1;j=1 && a[j-1]>key){ -a[j]=a[j-1]; - -j--; +void insertionSort(int arr[], int n) +{ + int i; + for (i = 1; i Date: Sun, 18 Oct 2020 01:14:21 +0530 Subject: [PATCH 554/781] Program to count sum of all numbers in array in C++ Optimized code to Program to count sum of all numbers in array using C++ --- ...am to count sum of all numbers in array using C++ | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Program to count sum of all numbers in array using C++ diff --git a/Program to count sum of all numbers in array using C++ b/Program to count sum of all numbers in array using C++ new file mode 100644 index 00000000..f0e02078 --- /dev/null +++ b/Program to count sum of all numbers in array using C++ @@ -0,0 +1,12 @@ +##Program to count sum of all numbers in array +main(){ +int n; +cout<<"Enter the length of array"; +cin>>n; +int s[n]; +for(int j=0;j>s[j];} +long long int sum=0; +for(int i=0;i Date: Sun, 18 Oct 2020 02:49:46 +0530 Subject: [PATCH 555/781] Create program to find largest element in array Optimization code for( Program to find largest element in array) --- program to find largest element in array | 46 ++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 program to find largest element in array diff --git a/program to find largest element in array b/program to find largest element in array new file mode 100644 index 00000000..b1d0629c --- /dev/null +++ b/program to find largest element in array @@ -0,0 +1,46 @@ +#include + +int main() +{ + printf("\n\n\t\tStudytonight - Best place to learn\n\n\n"); + int a[50], size, i, big, small; + + printf("\nEnter the size of the array: "); + scanf("%d", &size); + + printf("\n\nEnter the %d elements of the array: \n\n", size); + for(i = 0; i < size; i++) + scanf("%d", &a[i]); + + big = a[0]; + /* + from 2nd element to the last element + find the bigger element than big and + update the value of big + */ + for(i = 1; i < size; i++) + { + if(big < a[i]) + { + big = a[i]; + } + } + printf("\n\nThe largest element is: %d", big); + + small = a[0]; + /* + from 2nd element to the last element + find the smaller element than small and + update the value of small + */ + for(i = 1; i < size; i++) + { + if(small>a[i]) + { + small = a[i]; + } + } + printf("\n\nThe smallest element is: %d", small); + printf("\n\n\t\t\tCoding is Fun !\n\n\n"); + return 0; +} From d1c5b4a87620defa8a6b7bb9acc13184a5545697 Mon Sep 17 00:00:00 2001 From: Supratik Chakraborty <66419293+DeagleOfficial@users.noreply.github.com> Date: Sun, 18 Oct 2020 03:25:03 +0530 Subject: [PATCH 556/781] Create ReverseOfAnArray Program to display the reverse of an array. --- ReverseOfAnArray | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ReverseOfAnArray diff --git a/ReverseOfAnArray b/ReverseOfAnArray new file mode 100644 index 00000000..ae158afb --- /dev/null +++ b/ReverseOfAnArray @@ -0,0 +1,31 @@ +import java.util.*; +class ReverseOfAnArray { + public static void main(String []args){ + Scanner sc = new Scanner(System.in); + + System.out.print("Enter array size: "); + int n = sc.nextInt(); + + int[] arr = new int[n]; + for (int i=0; i Date: Sun, 18 Oct 2020 03:34:33 +0530 Subject: [PATCH 557/781] Create Find Factorial of a number Wrote code to compute factorial of a number --- Find Factorial of a number | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Find Factorial of a number diff --git a/Find Factorial of a number b/Find Factorial of a number new file mode 100644 index 00000000..1d9303a3 --- /dev/null +++ b/Find Factorial of a number @@ -0,0 +1,16 @@ +#include +using namespace std; +int main() { + int n; + cout << "Enter the number: "; + cin >> n; + + long long fact = 1; + + for (int i=2; i<=n; i++) { + fact = fact*i; + } + + cout << "Factorial: " << fact; + return 0; +} From 2bd76f913246eb49f3b347d860678937ac321b7b Mon Sep 17 00:00:00 2001 From: Supratik Chakraborty <66419293+DeagleOfficial@users.noreply.github.com> Date: Sun, 18 Oct 2020 03:39:10 +0530 Subject: [PATCH 558/781] Create Print Fibonacci Series Wrote code to display the Fibonacci series --- Print Fibonacci Series | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Print Fibonacci Series diff --git a/Print Fibonacci Series b/Print Fibonacci Series new file mode 100644 index 00000000..734f8d2b --- /dev/null +++ b/Print Fibonacci Series @@ -0,0 +1,19 @@ +#include +using namespace std; +int main() { + int n; + cout << "Enter number of terms: "; + cin >> n; + + int a = 0; + int b = 1; + int c = 0; + + for (int i=0; i Date: Sun, 18 Oct 2020 03:43:46 +0530 Subject: [PATCH 559/781] Create Print ASCII Value of Character Wrote code to display the ASCII value of a given character. --- Print ASCII Value of Character | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Print ASCII Value of Character diff --git a/Print ASCII Value of Character b/Print ASCII Value of Character new file mode 100644 index 00000000..bf3322df --- /dev/null +++ b/Print ASCII Value of Character @@ -0,0 +1,9 @@ +#include +using namespace std; +int main() { + char c; + cout << "Enter character: "; + cin >> c; + + cout << "ASCII Value: " << (int)c; +} From beadc97c308cbc329feb759659127d20a4ce22c3 Mon Sep 17 00:00:00 2001 From: KARAN152 <46127185+KARAN152@users.noreply.github.com> Date: Sun, 18 Oct 2020 05:44:47 +0530 Subject: [PATCH 560/781] Create program to find length of a string in java code for find length of a string --- program to find length of a string in java | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 program to find length of a string in java diff --git a/program to find length of a string in java b/program to find length of a string in java new file mode 100644 index 00000000..49ea7f0a --- /dev/null +++ b/program to find length of a string in java @@ -0,0 +1,12 @@ +public class LengthExample2 { + public static void main(String[] args) { + String str = "Javatpoint"; + if(str.length()>0) { + System.out.println("String is not empty and length is: "+str.length()); + } + str = ""; + if(str.length()==0) { + System.out.println("String is empty now: "+str.length()); + } + } +} From 6315ff80f1b8cb957cafa7db96d8af201e74c2b7 Mon Sep 17 00:00:00 2001 From: KARAN152 <46127185+KARAN152@users.noreply.github.com> Date: Sun, 18 Oct 2020 05:52:09 +0530 Subject: [PATCH 561/781] Create Program to count sum of all numbers in array .. code for count sum of number in array --- ...am to count sum of all numbers in array .. | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Program to count sum of all numbers in array .. diff --git a/Program to count sum of all numbers in array .. b/Program to count sum of all numbers in array .. new file mode 100644 index 00000000..63a985c9 --- /dev/null +++ b/Program to count sum of all numbers in array .. @@ -0,0 +1,28 @@ +#include +using namespace std; + +// Returns number of pairs in arr[0..n-1] with sum equal +// to 'sum' +int getPairsCount(int arr[], int n, int sum) +{ + int count = 0; // Initialize result + + // Consider all possible pairs and check their sums + for (int i=0; i Date: Sun, 18 Oct 2020 08:44:57 +0700 Subject: [PATCH 562/781] Create PHP Casting Strings and Floats to Integers Create PHP Casting Strings and Floats to Integers --- Create PHP Casting Strings and Floats to Integers | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Create PHP Casting Strings and Floats to Integers diff --git a/Create PHP Casting Strings and Floats to Integers b/Create PHP Casting Strings and Floats to Integers new file mode 100644 index 00000000..92950c4b --- /dev/null +++ b/Create PHP Casting Strings and Floats to Integers @@ -0,0 +1,13 @@ + "; + +// Cast string to int +$x = "23465.768"; +$int_cast = (int)$x; +echo $int_cast; +?> From f77aec73a37f710a416442f9ce1d9cdfe0e2bb9d Mon Sep 17 00:00:00 2001 From: andianiputrii <72190229+andianiputrii@users.noreply.github.com> Date: Sun, 18 Oct 2020 08:49:21 +0700 Subject: [PATCH 563/781] Create Looping Array Elements Create Looping Array Elements --- Create Looping Array Elements | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Create Looping Array Elements diff --git a/Create Looping Array Elements b/Create Looping Array Elements new file mode 100644 index 00000000..db6c736d --- /dev/null +++ b/Create Looping Array Elements @@ -0,0 +1,9 @@ +var fruits, text, fLen, i; +fruits = ["Banana", "Orange", "Apple", "Mango"]; +fLen = fruits.length; + +text = "
    "; +for (i = 0; i < fLen; i++) { + text += "
  • " + fruits[i] + "
  • "; +} +text += "
"; From 57b8386d51999e0e8a29ce7b76e3ff0f952273d2 Mon Sep 17 00:00:00 2001 From: Apurba Roy <55590340+apurbar06@users.noreply.github.com> Date: Sun, 18 Oct 2020 07:51:41 +0530 Subject: [PATCH 564/781] Create C++ code to count factorial of a given number c++ code for counting factorial of a given number. --- C++ code to count factorial of a given number | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 C++ code to count factorial of a given number diff --git a/C++ code to count factorial of a given number b/C++ code to count factorial of a given number new file mode 100644 index 00000000..f6b1d2a1 --- /dev/null +++ b/C++ code to count factorial of a given number @@ -0,0 +1,22 @@ +// C++ program to find factorial of given number +#include +using namespace std; + +// function to find factorial of given number +unsigned int factorial(unsigned int n) +{ + if (n == 0) + return 1; + return n * factorial(n - 1); +} + +// Driver code +int main() +{ + int num; + cout << "Enter a value : "; + cin >> num; + cout << "Factorial of " + << num << " is " << factorial(num) << endl; + return 0; +} From 6087f5138443c57d3da545d40b7be00e68245b48 Mon Sep 17 00:00:00 2001 From: Apurba Roy <55590340+apurbar06@users.noreply.github.com> Date: Sun, 18 Oct 2020 07:59:20 +0530 Subject: [PATCH 565/781] Create C++ code to find the largest element in array --- C++ code to find the largest element in array | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 C++ code to find the largest element in array diff --git a/C++ code to find the largest element in array b/C++ code to find the largest element in array new file mode 100644 index 00000000..38961ee3 --- /dev/null +++ b/C++ code to find the largest element in array @@ -0,0 +1,31 @@ +// C++ program to find maximum +// in arr[] of size n +#include +using namespace std; + +int largest(int arr[], int n) +{ + int i; + + // Initialize maximum element + int max = arr[0]; + + // Traverse array elements + // from second and compare + // every element with current max + for (i = 1; i < n; i++) + if (arr[i] > max) + max = arr[i]; + + return max; +} + +// Driver Code +int main() +{ + int arr[] = {10, 324, 45, 90, 9808}; + int n = sizeof(arr) / sizeof(arr[0]); + cout << "Largest in given array is " + << largest(arr, n); + return 0; +} From 717974735cf1a03907e43167fae8c6570511e164 Mon Sep 17 00:00:00 2001 From: andianiputrii <72190229+andianiputrii@users.noreply.github.com> Date: Sun, 18 Oct 2020 09:33:07 +0700 Subject: [PATCH 566/781] FIBONANCI --- FIBONANCI | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 FIBONANCI diff --git a/FIBONANCI b/FIBONANCI new file mode 100644 index 00000000..9c82a47a --- /dev/null +++ b/FIBONANCI @@ -0,0 +1,33 @@ +#include +using namespace std; + +int main() +{ + int n, t1 = 0, t2 = 1, nextTerm = 0; + + cout << "Enter the number of terms: "; + cin >> n; + + cout << "Fibonacci Series: "; + + for (int i = 1; i <= n; ++i) + { + // Prints the first two terms. + if(i == 1) + { + cout << " " << t1; + continue; + } + if(i == 2) + { + cout << t2 << " "; + continue; + } + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + + cout << nextTerm << " "; + } + return 0; +} From 4dd93b9851e30c6838d1731adc36221f7dfe474d Mon Sep 17 00:00:00 2001 From: andianiputrii <72190229+andianiputrii@users.noreply.github.com> Date: Sun, 18 Oct 2020 09:34:40 +0700 Subject: [PATCH 567/781] BUBBLE SORT --- BUBBLE SORT | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 BUBBLE SORT diff --git a/BUBBLE SORT b/BUBBLE SORT new file mode 100644 index 00000000..97a6f877 --- /dev/null +++ b/BUBBLE SORT @@ -0,0 +1,34 @@ +#include +void swap(int *k, int *l); +void main(){ + + int a[100],i,j,n,temp; + printf("enter number of elements"); + scanf("%d",&n); + for (i = 0; i < 5 ; i++) + { + scanf("%d",&a[i]); + } + for(i=0;ia[j+1]) + { + swap(&a[j],&a[j+1]); + } + + } + } + for (j = 0; j < n ; j++) + { + printf("%d ",a[j]); + } + +} +void swap(int *k,int *l){ + int temp; + temp=*k; + *k=*l; + *l=temp; +} From 765947f72fc4b886d3623a35809d84d108492a11 Mon Sep 17 00:00:00 2001 From: Apurba Roy <55590340+apurbar06@users.noreply.github.com> Date: Sun, 18 Oct 2020 08:08:15 +0530 Subject: [PATCH 568/781] Create C++ code to find the smallest element in array --- ...code to find the smallest element in array | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 C++ code to find the smallest element in array diff --git a/C++ code to find the smallest element in array b/C++ code to find the smallest element in array new file mode 100644 index 00000000..f9d55188 --- /dev/null +++ b/C++ code to find the smallest element in array @@ -0,0 +1,32 @@ +//C++ programe to find the smallest element of an array +#include +using namespace std; +int findSmallestElement(int arr[], int n){ + /* We are assigning the first array element to + * the temp variable and then we are comparing + * all the array elements with the temp inside + * loop and if the element is smaller than temp + * then the temp value is replaced by that. This + * way we always have the smallest value in temp. + * Finally we are returning temp. + */ + int temp = arr[0]; + for(int i=0; iarr[i]) { + temp=arr[i]; + } + } + return temp; +} +int main() { + int n; + cout<<"Enter the size of array: "; + cin>>n; int arr[n-1]; + cout<<"Enter array elements: "; + for(int i=0; i>arr[i]; + } + int smallest = findSmallestElement(arr, n); + cout<<"Smallest Element is: "< Date: Sun, 18 Oct 2020 09:39:36 +0700 Subject: [PATCH 569/781] C Program to Sort the Array in Descending Order --- ...gram to Sort the Array in Descending Order | 83 +++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 C Program to Sort the Array in Descending Order diff --git a/C Program to Sort the Array in Descending Order b/C Program to Sort the Array in Descending Order new file mode 100644 index 00000000..d0c6de44 --- /dev/null +++ b/C Program to Sort the Array in Descending Order @@ -0,0 +1,83 @@ + /* + + * C program to accept a set of numbers and arrange them + + * in a descending order + + */ + + + + #include + + void main () + + { + + + + int number[30]; + + + + int i, j, a, n; + + printf("Enter the value of N\n"); + + scanf("%d", &n); + + + + printf("Enter the numbers \n"); + + for (i = 0; i < n; ++i) + + scanf("%d", &number[i]); + + + + /* sorting begins ... */ + + + + for (i = 0; i < n; ++i) + + { + + for (j = i + 1; j < n; ++j) + + { + + if (number[i] < number[j]) + + { + + a = number[i]; + + number[i] = number[j]; + + number[j] = a; + + } + + } + + } + + + + printf("The numbers arranged in descending order are given below\n"); + + + + for (i = 0; i < n; ++i) + + { + + printf("%d\n", number[i]); + + } + + + + } From b1190e98336a9edb79422a0c8dda9fa1fd4bf43e Mon Sep 17 00:00:00 2001 From: Apurba Roy <55590340+apurbar06@users.noreply.github.com> Date: Sun, 18 Oct 2020 08:14:48 +0530 Subject: [PATCH 570/781] Create C++ code to find the length of a string --- C++ code to find the length of a string | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 C++ code to find the length of a string diff --git a/C++ code to find the length of a string b/C++ code to find the length of a string new file mode 100644 index 00000000..bfa79765 --- /dev/null +++ b/C++ code to find the length of a string @@ -0,0 +1,14 @@ +// C++ code to count the length of a string +#include +#include +using namespace std; +int main () +{ + char str[50]; + int len; + cout << "Enter an array or string : "; + gets(str); + len = strlen(str); + cout << "Length of the string is : " << len; + return 0; +} From 33185de27e72dec54c5c83c7b29789bea59025b5 Mon Sep 17 00:00:00 2001 From: Manas Garg Date: Sun, 18 Oct 2020 08:32:34 +0530 Subject: [PATCH 571/781] Create Sum_Elements_In.Array_Manas Hey!, Please accept my pull request --- Sum_Elements_In.Array_Manas | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Sum_Elements_In.Array_Manas diff --git a/Sum_Elements_In.Array_Manas b/Sum_Elements_In.Array_Manas new file mode 100644 index 00000000..74c8c6c0 --- /dev/null +++ b/Sum_Elements_In.Array_Manas @@ -0,0 +1,22 @@ +# Python 3 code to find sum +# of elements in given array +def _sum(arr,n): + + # return sum using sum + # inbuilt sum() function + return(sum(arr)) + +# driver function +arr=[] +# input values to list +arr = [12, 3, 4, 15] + +# calculating length of array +n = len(arr) + +ans = _sum(arr,n) + +# display sum +print ('Sum of the array is ', ans) + +# This code is contributed by Manas Garg From d1ae09a49a636116751eced9967ec9c1491c81b6 Mon Sep 17 00:00:00 2001 From: Shaurya Choudhary Date: Sun, 18 Oct 2020 08:47:06 +0530 Subject: [PATCH 572/781] Create Python program for factorial of number A python3 program using recursion to find factorial of a number using Command Line interface. --- Python program for factorial of number | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Python program for factorial of number diff --git a/Python program for factorial of number b/Python program for factorial of number new file mode 100644 index 00000000..1bab9651 --- /dev/null +++ b/Python program for factorial of number @@ -0,0 +1,17 @@ +# Python3 script to print Factorial of a number + + +def fact(num): + if num == 1 or num == 0: + return 1 + elif num == 2: + return 2 + else: + return num * fact(num - 1) + + +n = int(input("Enter your number:\t")) +if n >= 0: + print("The factorial of {} is: {}".format(n, fact(n))) +else: + raise Exception("Invalid Input. Try Again") From 79fc2eb02b70ff3d22d475a89f7ef3939856465b Mon Sep 17 00:00:00 2001 From: Andiani Putri <56747639+andianiputri@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:31:13 +0700 Subject: [PATCH 573/781] All Arithmetic Operations C Program To Enter 2 Number and Perform All Arithmetic Operations --- ...mber and Perform All Arithmetic Operations | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 C Program To Enter 2 Number and Perform All Arithmetic Operations diff --git a/C Program To Enter 2 Number and Perform All Arithmetic Operations b/C Program To Enter 2 Number and Perform All Arithmetic Operations new file mode 100644 index 00000000..52112d93 --- /dev/null +++ b/C Program To Enter 2 Number and Perform All Arithmetic Operations @@ -0,0 +1,29 @@ +#include + +int main() +{ + int p, q; + int sum, sub, mul, mod; + float div; + + /** Input two numbers from user **/ + printf("Enter any two numbers::\n"); + scanf("%d%d", &p, &q, "\n"); + + /** Perform all arithmetic operations **/ + sum = p + q; + sub = p - q; + mul = p * q; + div = (float)p / q; + mod = p % q; + + /** Print result of all arithmetic operations **/ + printf("\n"); + printf("SUM %d + %d = %d\n", p, q, sum); + printf("DIFFERENCE %d - %d = %d\n", p, q, sub); + printf("PRODUCT %d * %d = %d\n", p, q, mul); + printf("QUOTIENT %d / %d = %f\n", p, q, div); + printf("MODULUS %d %% %d = %d\n", p, q, mod); + + return 0; +} From 9ed38db1b54d6b7ba09b0c7fd1a096a613b32da7 Mon Sep 17 00:00:00 2001 From: Shaurya Choudhary Date: Sun, 18 Oct 2020 09:04:03 +0530 Subject: [PATCH 574/781] Create Python script to sort and reverse the Array Python3 script for sorting and reversing the array. --- Python script to sort and reverse the Array | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Python script to sort and reverse the Array diff --git a/Python script to sort and reverse the Array b/Python script to sort and reverse the Array new file mode 100644 index 00000000..841af9cd --- /dev/null +++ b/Python script to sort and reverse the Array @@ -0,0 +1,15 @@ +# Python3 script to reverse the array + + +def rev(ls): + return ls[::-1] + + +num = int(input("Enter the length of your array:\t")) +arr = list(map(int, input().strip().split())) + +print("Your original array is: ", arr) +print("The reversed array is: ", rev(arr)) + +print("Sorted Array is: ", sorted(arr)) +print("Sorted Array in descending order is: ", rev(sorted(arr))) From 2afa6f0eb73226b9dadd9792866cc1c166b2e3c0 Mon Sep 17 00:00:00 2001 From: Shaurya Choudhary Date: Sun, 18 Oct 2020 09:08:20 +0530 Subject: [PATCH 575/781] Create Matrix multiplication through a C++ program Matrix multiplication program on C++ to multiply any compatible matrices and display the resultant matrix. --- Matrix multiplication through a C++ program | 62 +++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 Matrix multiplication through a C++ program diff --git a/Matrix multiplication through a C++ program b/Matrix multiplication through a C++ program new file mode 100644 index 00000000..be69e00d --- /dev/null +++ b/Matrix multiplication through a C++ program @@ -0,0 +1,62 @@ +#include +using namespace std; + +int main() +{ + int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, i, j, k; + + cout << "Enter rows and columns for first matrix: "; + cin >> r1 >> c1; + cout << "Enter rows and columns for second matrix: "; + cin >> r2 >> c2; + + while (c1!=r2) + { + cout << "Error! column of first matrix not equal to row of second."; + + cout << "Enter rows and columns for first matrix: "; + cin >> r1 >> c1; + + cout << "Enter rows and columns for second matrix: "; + cin >> r2 >> c2; + } + + cout << endl << "Enter elements of matrix 1:" << endl; + for(i = 0; i < r1; ++i) + for(j = 0; j < c1; ++j) + { + cout << "Enter element a" << i + 1 << j + 1 << " : "; + cin >> a[i][j]; + } + + cout << endl << "Enter elements of matrix 2:" << endl; + for(i = 0; i < r2; ++i) + for(j = 0; j < c2; ++j) + { + cout << "Enter element b" << i + 1 << j + 1 << " : "; + cin >> b[i][j]; + } + for(i = 0; i < r1; ++i) + for(j = 0; j < c2; ++j) + { + mult[i][j]=0; + } + + for(i = 0; i < r1; ++i) + for(j = 0; j < c2; ++j) + for(k = 0; k < c1; ++k) + { + mult[i][j] += a[i][k] * b[k][j]; + } + + cout << endl << "Output Matrix: " << endl; + for(i = 0; i < r1; ++i) + for(j = 0; j < c2; ++j) + { + cout << " " << mult[i][j]; + if(j == c2-1) + cout << endl; + } + + return 0; +} From b5d497e6511140b7bff1d7bee1db2ef0fbb1ab75 Mon Sep 17 00:00:00 2001 From: Satish Kollu <48837350+satishkollu@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:00:18 +0530 Subject: [PATCH 576/781] Create Program to add two numbers in pyhton Optimized code for the sum of two numbers in python. --- Program to add two numbers in pyhton | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Program to add two numbers in pyhton diff --git a/Program to add two numbers in pyhton b/Program to add two numbers in pyhton new file mode 100644 index 00000000..01e1e135 --- /dev/null +++ b/Program to add two numbers in pyhton @@ -0,0 +1,6 @@ +x = input("Type a number: ") +y = input("Type another number: ") + +sum = int(x) + int(y) + +print("The sum is: ", sum) From 7e448d9c28bab1989a3853e8133b3fa34c068d98 Mon Sep 17 00:00:00 2001 From: Ram Vivek Singh Date: Sun, 18 Oct 2020 10:01:08 +0530 Subject: [PATCH 577/781] Create Prime_in_Range.py Created a Python Program to Print all Prime Numbers in given range --- Prime_in_Range.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Prime_in_Range.py diff --git a/Prime_in_Range.py b/Prime_in_Range.py new file mode 100644 index 00000000..741b6682 --- /dev/null +++ b/Prime_in_Range.py @@ -0,0 +1,10 @@ +lower = int(input("Enter lower range: ")) +upper = int(input("Enter upper range: ")) + +for num in range(lower,upper + 1): + if num > 1: + for i in range(2,num): + if (num % i) == 0: + break + else: + print(num) From 31fd7e45326eada8b80fde7ced943d7aea1c0706 Mon Sep 17 00:00:00 2001 From: Niranjana K <71917062+NiranjanaK03@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:05:49 +0530 Subject: [PATCH 578/781] Create Program to print the Fibonacci series using python. Optimized code for getting Fibonacci series upto n-th term using python language. --- ...o print the Fibonacci series using python. | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Program to print the Fibonacci series using python. diff --git a/Program to print the Fibonacci series using python. b/Program to print the Fibonacci series using python. new file mode 100644 index 00000000..9f6b1b3d --- /dev/null +++ b/Program to print the Fibonacci series using python. @@ -0,0 +1,23 @@ +# Program to display the Fibonacci sequence up to n-th term + +nterms = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + # update values + n1 = n2 + n2 = nth + count += 1 From 3ac388a97065a76bcc37126c8ed6e942a1fc07b2 Mon Sep 17 00:00:00 2001 From: Kunchana Gayashan Ekanayaka <36447494+Kuncha98@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:09:41 +0530 Subject: [PATCH 579/781] Convert Binary to Decimal Number in Java --- ...o convert binary to decimal number in Java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Program to convert binary to decimal number in Java diff --git a/Program to convert binary to decimal number in Java b/Program to convert binary to decimal number in Java new file mode 100644 index 00000000..650775b6 --- /dev/null +++ b/Program to convert binary to decimal number in Java @@ -0,0 +1,21 @@ +public class BinaryToDecimalExample3{ +public static int getDecimal(int binary){ + int decimal = 0; + int n = 0; + while(true){ + if(binary == 0){ + break; + } else { + int temp = binary%10; + decimal += temp*Math.pow(2, n); + binary = binary/10; + n++; + } + } + return decimal; +} +public static void main(String args[]){ +System.out.println("Decimal of 1010 is: "+getDecimal(1010)); +System.out.println("Decimal of 10101 is: "+getDecimal(10101)); +System.out.println("Decimal of 11111 is: "+getDecimal(11111)); +}} From d4755d6d93fce82df2e1124bdcb8958921a46963 Mon Sep 17 00:00:00 2001 From: Kunchana Gayashan Ekanayaka <36447494+Kuncha98@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:15:12 +0530 Subject: [PATCH 580/781] Triangle is Equilateral, Isosceles or Scalene --- ...angle is Equilateral, Isosceles or Scalene | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 whether a Triangle is Equilateral, Isosceles or Scalene diff --git a/whether a Triangle is Equilateral, Isosceles or Scalene b/whether a Triangle is Equilateral, Isosceles or Scalene new file mode 100644 index 00000000..a995ee18 --- /dev/null +++ b/whether a Triangle is Equilateral, Isosceles or Scalene @@ -0,0 +1,26 @@ +# Function to check if the triangle +# is equilateral or isosceles or scalene +def checkTriangle(x, y, z): + + # _Check for equilateral triangle + if x == y == z: + print("Equilateral Triangle") + + # Check for isoceles triangle + elif x == y or y == z or z == x: + print("Isoceles Triangle") + + # Otherwise scalene triangle + else: + print("Scalene Triangle") + + +# Driver Code + +# Given sides of triangle +x = 8 +y = 7 +z = 9 + +# Function Call +checkTriangle(x, y, z) From d2b0286a702b59d4ebbdd4936aaca0aaaa837d51 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Sharma <53513799+shubhamkumarcs@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:25:50 +0530 Subject: [PATCH 581/781] Linear search C program for linear search --- Linear search in array | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Linear search in array diff --git a/Linear search in array b/Linear search in array new file mode 100644 index 00000000..8e625c7c --- /dev/null +++ b/Linear search in array @@ -0,0 +1,29 @@ +#include +int main() +{ + int array[100], search, c, n; + + printf("Enter number of elements in array\n"); + scanf("%d", &n); + + printf("Enter %d integer(s)\n", n); + + for (c = 0; c < n; c++) + scanf("%d", &array[c]); + + printf("Enter a number to search\n"); + scanf("%d", &search); + + for (c = 0; c < n; c++) + { + if (array[c] == search) /* If required element is found */ + { + printf("%d is present at location %d.\n", search, c+1); + break; + } + } + if (c == n) + printf("%d isn't present in the array.\n", search); + + return 0; +} From fc4889777dd5d27fd6fa31e003f03516b5293a06 Mon Sep 17 00:00:00 2001 From: jainNiharika <73049797+jainNiharika@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:29:27 +0530 Subject: [PATCH 582/781] Create Program to reverse an array Optimized C Program to reverse an array --- Program to reverse an array | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Program to reverse an array diff --git a/Program to reverse an array b/Program to reverse an array new file mode 100644 index 00000000..4d709868 --- /dev/null +++ b/Program to reverse an array @@ -0,0 +1,18 @@ +#include +int main() +{ +int n; +scanf(“%d”,&n); +int arr[n]; +int i; +for(i = 0; i < n; i++) +{ +scanf(“%d”,&arr[i]); +} +printf(“Reversed array is:\n”); +for(i = n-1; i >= 0; i–) +{ +printf(“%d\n”,arr[i]); +} +return 0; +} From 4077eba899c48dcac479e403a7f31010124e9f5b Mon Sep 17 00:00:00 2001 From: Jerome Wilson <64187954+Jerry-dev233@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:31:14 +0530 Subject: [PATCH 583/781] Create Python Program to check Triangles Checks the length of sides and provides the type of triangle --- Python Program to check Triangles | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Python Program to check Triangles diff --git a/Python Program to check Triangles b/Python Program to check Triangles new file mode 100644 index 00000000..03eae8fd --- /dev/null +++ b/Python Program to check Triangles @@ -0,0 +1,24 @@ +#code +#enter the values +print("Input lengths of the triangle sides: ") +x = int(input("x: ")) +y = int(input("y: ")) +z = int(input("z: ")) + +#providing the conditions +if x == y == z: + print("Equilateral triangle") +elif x==y or y==z or z==x: + print("Isosceles triangle") +else: + print("Scalene triangle") + +#output +x: 6 +y: 8 +z: 12 +Scalene triangle +x: 7 +y: 7 +z: 7 +Equilateral triangle From 21ffe7e05b082691872b88f3b4ef8fade6d431f6 Mon Sep 17 00:00:00 2001 From: jainNiharika <73049797+jainNiharika@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:31:16 +0530 Subject: [PATCH 584/781] Create Power of a Number Using the while Loop Optimized C Program for Power of a Number Using the while Loop --- Power of a Number Using the while Loop | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Power of a Number Using the while Loop diff --git a/Power of a Number Using the while Loop b/Power of a Number Using the while Loop new file mode 100644 index 00000000..e7d59525 --- /dev/null +++ b/Power of a Number Using the while Loop @@ -0,0 +1,16 @@ +#include +int main() { + int base, exp; + long long result = 1; + printf("Enter a base number: "); + scanf("%d", &base); + printf("Enter an exponent: "); + scanf("%d", &exp); + + while (exp != 0) { + result *= base; + --exp; + } + printf("Answer = %lld", result); + return 0; +} From 9e776ca8ea32839d42d61d7a35f17175b16b9415 Mon Sep 17 00:00:00 2001 From: sg5915076 <72183990+sg5915076@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:33:05 +0530 Subject: [PATCH 585/781] Create Factorial of number sg Optimized Code for Factorial of number in C programming quickly. --- Factorial of number sg | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Factorial of number sg diff --git a/Factorial of number sg b/Factorial of number sg new file mode 100644 index 00000000..07b09ea2 --- /dev/null +++ b/Factorial of number sg @@ -0,0 +1,19 @@ +#include +int main() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows error if the user enters a negative integer + if (n < 0) + printf("Error! Factorial of a negative number doesn't exist."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + return 0; +} From d0a98d4d884a96670fc9555ed58b3ad6f123ab4d Mon Sep 17 00:00:00 2001 From: jainNiharika <73049797+jainNiharika@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:33:22 +0530 Subject: [PATCH 586/781] Create Program to subtract 2D or 3D Matrices Optimized Program to subtract 2D or 3D Matrices --- Program to subtract 2D or 3D Matrices | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Program to subtract 2D or 3D Matrices diff --git a/Program to subtract 2D or 3D Matrices b/Program to subtract 2D or 3D Matrices new file mode 100644 index 00000000..6d2570ca --- /dev/null +++ b/Program to subtract 2D or 3D Matrices @@ -0,0 +1,37 @@ +int main() +{ + int rowCount, columnCount, i, j; + int firstMatrix[10][10], secondMatrix[10][10], resultMatrix[10][10]; + + printf("Number of rows of matrices to be subtracted : "); + scanf("%d", &rowCount); + + printf("Number of columns matrices to be subtracted : "); + scanf("%d", &columnCount); + + printf("Elements of first matrix : \n"); + + for (i = 0; i < rowCount; i++) + for (j = 0; j < columnCount; j++) + scanf("%d", &firstMatrix[i][j]); + + printf("Elements of second matrix : \n"); + + for (i = 0; i < rowCount; i++) + for (j = 0; j < columnCount; j++) + scanf("%d", &secondMatrix[i][j]); + + printf("Difference of entered matrices : \n"); + + for (i = 0; i < rowCount; i++) + { + for (j = 0; j < columnCount; j++) + { + resultMatrix[i][j] = firstMatrix[i][j] - secondMatrix[i][j]; + printf("%d\t",resultMatrix[i][j]); + } + printf("\n"); + } + + return 0; +} From 7329932aff546eb92268dfd541bfa7b0eab7bcf2 Mon Sep 17 00:00:00 2001 From: jainNiharika <73049797+jainNiharika@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:35:00 +0530 Subject: [PATCH 587/781] Create Program to count vowels, consonants Optimized Program to count vowels, consonants --- Program to count vowels, consonants | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Program to count vowels, consonants diff --git a/Program to count vowels, consonants b/Program to count vowels, consonants new file mode 100644 index 00000000..c9c1d5b1 --- /dev/null +++ b/Program to count vowels, consonants @@ -0,0 +1,31 @@ +#include +int main() { + char line[150]; + int vowels, consonant, digit, space; + + vowels = consonant = digit = space = 0; + + printf("Enter a line of string: "); + fgets(line, sizeof(line), stdin); + + for (int i = 0; line[i] != '\0'; ++i) { + if (line[i] == 'a' || line[i] == 'e' || line[i] == 'i' || + line[i] == 'o' || line[i] == 'u' || line[i] == 'A' || + line[i] == 'E' || line[i] == 'I' || line[i] == 'O' || + line[i] == 'U') { + ++vowels; + } else if ((line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z')) { + ++consonant; + } else if (line[i] >= '0' && line[i] <= '9') { + ++digit; + } else if (line[i] == ' ') { + ++space; + } + } + + printf("Vowels: %d", vowels); + printf("\nConsonants: %d", consonant); + printf("\nDigits: %d", digit); + printf("\nWhite spaces: %d", space); + return 0; +} From a77de66ae05bba2f77fef91a24ecdfcb6bcd68df Mon Sep 17 00:00:00 2001 From: kname776 <73050013+kname776@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:35:51 +0530 Subject: [PATCH 588/781] Create Binary_Search_Tree.py Binary Search Tree operations in Python data structures and algorithms programming --- Binary_Search_Tree.py | 101 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 Binary_Search_Tree.py diff --git a/Binary_Search_Tree.py b/Binary_Search_Tree.py new file mode 100644 index 00000000..b21004d1 --- /dev/null +++ b/Binary_Search_Tree.py @@ -0,0 +1,101 @@ +# Create a node +class Node: + def __init__(self, key): + self.key = key + self.left = None + self.right = None + + +# Inorder traversal +def inorder(root): + if root is not None: + # Traverse left + inorder(root.left) + + # Traverse root + print(str(root.key) + "->", end=' ') + + # Traverse right + inorder(root.right) + + +# Insert a node +def insert(node, key): + + # Return a new node if the tree is empty + if node is None: + return Node(key) + + # Traverse to the right place and insert the node + if key < node.key: + node.left = insert(node.left, key) + else: + node.right = insert(node.right, key) + + return node + + +# Find the inorder successor +def minValueNode(node): + current = node + + # Find the leftmost leaf + while(current.left is not None): + current = current.left + + return current + + +# Deleting a node +def deleteNode(root, key): + + # Return if the tree is empty + if root is None: + return root + + # Find the node to be deleted + if key < root.key: + root.left = deleteNode(root.left, key) + elif(key > root.key): + root.right = deleteNode(root.right, key) + else: + # If the node is with only one child or no child + if root.left is None: + temp = root.right + root = None + return temp + + elif root.right is None: + temp = root.left + root = None + return temp + + # If the node has two children, + # place the inorder successor in position of the node to be deleted + temp = minValueNode(root.right) + + root.key = temp.key + + # Delete the inorder successor + root.right = deleteNode(root.right, temp.key) + + return root + + +root = None +root = insert(root, 8) +root = insert(root, 5) +root = insert(root, 1) +root = insert(root, 6) +root = insert(root, 7) +root = insert(root, 10) +root = insert(root, 14) +root = insert(root, 4) + +print("Inorder traversal: ", end=' ') +inorder(root) + +print("\nDelete 10") +root = deleteNode(root, 10) +print("Inorder traversal: ", end=' ') +inorder(root) From a7fbec3d0c4c627cdbedd7a3000d3c11ec3226c2 Mon Sep 17 00:00:00 2001 From: sg5915076 <72183990+sg5915076@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:42:45 +0530 Subject: [PATCH 589/781] Create Largest element in array sg Optimize Code of largest element in an array quickly --- Largest element in array sg | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Largest element in array sg diff --git a/Largest element in array sg b/Largest element in array sg new file mode 100644 index 00000000..98a77125 --- /dev/null +++ b/Largest element in array sg @@ -0,0 +1,22 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + // storing the largest number to arr[0] + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From ca34efdbb81c115f9e0f9ed7dbe4151cfeb6670f Mon Sep 17 00:00:00 2001 From: Jerome Wilson <64187954+Jerry-dev233@users.noreply.github.com> Date: Sun, 18 Oct 2020 10:45:16 +0530 Subject: [PATCH 590/781] Create Python program to multiply two matrices Using numpy library to perform multiplication of matrices --- Python program to multiply two matrices | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Python program to multiply two matrices diff --git a/Python program to multiply two matrices b/Python program to multiply two matrices new file mode 100644 index 00000000..613293ce --- /dev/null +++ b/Python program to multiply two matrices @@ -0,0 +1,22 @@ +#code +#giving input +X = [[12,7,3], +[4 ,5,6], +[7 ,8,9]] +Y = [[5,8,1,2], +[6,7,3,0], +[4,5,9,1]] +#providing empty matrice to store result +result = [[0,0,0,0], +[0,0,0,0], +[0,0,0,0]] +for i in range(len(X)): + for j in range(len(Y[0])): + for k in range(len(Y)): + result[i][j] += X[i][k] * Y[k][j] +print(np.array(result)) + +#Output +[[114 160 60 27] +[ 74 97 73 14] +[119 157 112 23]] From 2d929690c234644c421f9a3fba3de02cd5e4fa4f Mon Sep 17 00:00:00 2001 From: Ridwan Kustanto Date: Sun, 18 Oct 2020 12:27:27 +0700 Subject: [PATCH 591/781] Create find_factorial_of_number_by_ridwankustanto.go --- find_factorial_of_number_by_ridwankustanto.go | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 find_factorial_of_number_by_ridwankustanto.go diff --git a/find_factorial_of_number_by_ridwankustanto.go b/find_factorial_of_number_by_ridwankustanto.go new file mode 100644 index 00000000..ab11c2c0 --- /dev/null +++ b/find_factorial_of_number_by_ridwankustanto.go @@ -0,0 +1,31 @@ +package main + +import ( + "flag" + "fmt" +) + +func main() { + + factorial := 1 + + num := flag.Int("num", 0, "num of factorial") + flag.Parse() + + if *num < 0 { + fmt.Println("try another number, factorial does not exist for negative numbers") + return + } + + if *num == 0 { + fmt.Println("the factorial of 0 is 1") + return + } + + for i := 0; i < *num; { + i++ + factorial *= i + } + + fmt.Println(fmt.Sprintf("The factorial of %v, is %v", *num, factorial)) +} From 3456c05805bd430ff78cc868a9d21c4df7a666e0 Mon Sep 17 00:00:00 2001 From: Pratx-404 <32536443+Pratx-404@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:07:11 +0530 Subject: [PATCH 592/781] Create Print Factorial Series --- Print Factorial Series | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Print Factorial Series diff --git a/Print Factorial Series b/Print Factorial Series new file mode 100644 index 00000000..e8a41591 --- /dev/null +++ b/Print Factorial Series @@ -0,0 +1,9 @@ +def fibonacci(n): + if n <= 1: + return n + else: + return fibonacci(n-1) + fibonacci(n-2) + +n=int(input()) +for i in range(n): + print(fibonacci(i),end=" ") From d2e5c59cf2a2d8f3637556de1edbbc0f71aa254f Mon Sep 17 00:00:00 2001 From: Ayoma Katuwawala <55722961+A-Chathumini@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:10:10 +0530 Subject: [PATCH 593/781] Create factorial program in c program to find a factorial of a given number using a loop --- factorial program in c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 factorial program in c diff --git a/factorial program in c b/factorial program in c new file mode 100644 index 00000000..3637389b --- /dev/null +++ b/factorial program in c @@ -0,0 +1,12 @@ +#include +int main() +{ + int i,factorial=1,num; + printf("Enter a number to find factorial: "); + scanf("%d",&num); + for(i=1;i<=num;i++){ + factorial=factorial*i; + } + printf("Factorial of %d is: %d",num,factorial); +return 0; +} From 364b61fe266007363bbfce7d44bd1ce536dba700 Mon Sep 17 00:00:00 2001 From: Pratx-404 <32536443+Pratx-404@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:11:36 +0530 Subject: [PATCH 594/781] Create Print ASCII value of a character --- Print ASCII value of a character | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Print ASCII value of a character diff --git a/Print ASCII value of a character b/Print ASCII value of a character new file mode 100644 index 00000000..430e833a --- /dev/null +++ b/Print ASCII value of a character @@ -0,0 +1,2 @@ +n=input() +print(ord(n)) From 104f399f6d626eed4c710cfa1b9f3943811d2cca Mon Sep 17 00:00:00 2001 From: Apurba Roy <55590340+apurbar06@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:13:15 +0530 Subject: [PATCH 595/781] Create C code for sorting a given array (ascending & descending) --- ...ing a given array (ascending & descending) | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 C code for sorting a given array (ascending & descending) diff --git a/C code for sorting a given array (ascending & descending) b/C code for sorting a given array (ascending & descending) new file mode 100644 index 00000000..53757006 --- /dev/null +++ b/C code for sorting a given array (ascending & descending) @@ -0,0 +1,54 @@ +// C code for sorting a array in ascending and descinding +#include //including stdio.h for printf and other functions +#include + + +int main() //default function for call +{ + int a[100],n,i,j; + printf("Array size: "); + scanf("%d",&n); + printf("Elements: "); + + for(i=0;i a[i]) //Comparing other array elements + { + int tmp = a[i]; //Using temporary variable for storing last value + a[i] = a[j]; //replacing value + a[j] = tmp; //storing last value + } + } + } + printf("\n\nAscending : "); //Printing message + for (int i = 0; i < n; i++) //Loop for printing array data after sorting + { + printf(" %d ", a[i]); + } + for (int i = 0; i < n; i++) //Loop for descending ordering + { + for (int j = 0; j < n; j++) //Loop for comparing other values + { + if (a[j] < a[i]) //Comparing other array elements + { + int tmp = a[i]; //Using temporary variable for storing last value + a[i] = a[j]; //replacing value + a[j] = tmp; //storing last value + } + } + } + printf("\n\nDescending : "); //Printing message + for (int i = 0; i < n; i++) //Loop for printing array data after sorting + { + printf(" %d ", a[i]); //Printing data + } + + return 0; //returning 0 status to system + +} From 470ce7f7f036cb8d7c829e0c472cc433be3729f7 Mon Sep 17 00:00:00 2001 From: Pranjul Singhal Date: Sun, 18 Oct 2020 11:15:49 +0530 Subject: [PATCH 596/781] Create Cube of a number --- Cube of a number | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Cube of a number diff --git a/Cube of a number b/Cube of a number new file mode 100644 index 00000000..c91dee9f --- /dev/null +++ b/Cube of a number @@ -0,0 +1,15 @@ +import java.util.*; +class Cube +{ +public static void main(String args[]) +{ +int i,num,sq; +for(i=1;i<10;i++) +{ +num=i*i*i; +sq=(int)Math.sqrt(num); +if(sq*sq==num) +System.out.print(num); +} +} +} From cdeab8dad784fb18f68786d1b8816fb32b8bdaa5 Mon Sep 17 00:00:00 2001 From: Pranjul Singhal Date: Sun, 18 Oct 2020 11:17:46 +0530 Subject: [PATCH 597/781] Create Compare two strings --- Compare two strings | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Compare two strings diff --git a/Compare two strings b/Compare two strings new file mode 100644 index 00000000..52c5de66 --- /dev/null +++ b/Compare two strings @@ -0,0 +1,14 @@ +import java.util.*; +class Compare +{ +public static void main(String args[]) +{ +Scanner sc=new Scanner(System.in); +String s1=sc.nextLine(); +String s2=sc.nextLine(); +if(s1.equalsIgnoreCase(s2)) +System.out.println("Same"); +else +System.out.println("Not Same"); +} +} From 408fcbcd06b6340199c7a7e06c58c3ada625b740 Mon Sep 17 00:00:00 2001 From: dipsaili2001 <54875003+dipsaili2001@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:26:26 +0530 Subject: [PATCH 598/781] Create Sum of elements in an array --- Sum of elements in an array | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Sum of elements in an array diff --git a/Sum of elements in an array b/Sum of elements in an array new file mode 100644 index 00000000..5839023e --- /dev/null +++ b/Sum of elements in an array @@ -0,0 +1,23 @@ +class Test +{ + static int arr[] = {12,3,4,15}; + + // method for sum of elements in an array + static int sum() + { + int sum = 0; // initialize sum + int i; + + // Iterate through all elements and add them to sum + for (i = 0; i < arr.length; i++) + sum += arr[i]; + + return sum; + } + + // Driver method + public static void main(String[] args) + { + System.out.println("Sum of given array is " + sum()); + } + } From 857de8d7cbcc25f7ab7d46903693d9405025b3ed Mon Sep 17 00:00:00 2001 From: dipsaili2001 <54875003+dipsaili2001@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:31:24 +0530 Subject: [PATCH 599/781] Create PHP code for Fibonacci --- PHP code for Fibonacci | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 PHP code for Fibonacci diff --git a/PHP code for Fibonacci b/PHP code for Fibonacci new file mode 100644 index 00000000..ac5e43c3 --- /dev/null +++ b/PHP code for Fibonacci @@ -0,0 +1,20 @@ + From 77ecd3846d28853d22ec2e2bf3a0da7553601f16 Mon Sep 17 00:00:00 2001 From: dipsaili2001 <54875003+dipsaili2001@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:50:49 +0530 Subject: [PATCH 600/781] Create Find Factorial of a number (PHP) Find Factorial of a number in php --- Find Factorial of a number (PHP) | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Find Factorial of a number (PHP) diff --git a/Find Factorial of a number (PHP) b/Find Factorial of a number (PHP) new file mode 100644 index 00000000..46a77101 --- /dev/null +++ b/Find Factorial of a number (PHP) @@ -0,0 +1,16 @@ + From 2862a51c130c177e5432fb747917dcac1737030e Mon Sep 17 00:00:00 2001 From: dipsaili2001 <54875003+dipsaili2001@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:53:59 +0530 Subject: [PATCH 601/781] Create Add two 2D matrix --- Add two 2D matrix | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Add two 2D matrix diff --git a/Add two 2D matrix b/Add two 2D matrix new file mode 100644 index 00000000..18ba14f8 --- /dev/null +++ b/Add two 2D matrix @@ -0,0 +1,33 @@ +#include + +int main() { +int a[3][3],b[3][3],c[3][3],i,j; +char n; +printf ("\nenter 9 element of matrix1"); +for(i=0;i<3;i++) +{ + for(j=0;j<3;j++) + { + scanf ("%d",&a[i][j]); + } +} +printf ("\nenter 9 element of matrix2"); +for(i=0;i<3;i++) +{ + for(j=0;j<3;j++) + { + scanf ("%d",&b[i][j]); + } +} +printf ("\nadditon is:"); +for (i=0;i<3;i++) +{ + for(j=0;j<3;j++) + { + c[i][j]=a[i][j]+b[i][j]; + printf ("%d",c[i][j]); + } + printf ("\n"); +} +return 0; +} From 2abcc8480b5bf14800981714c36179d7e2ba07ad Mon Sep 17 00:00:00 2001 From: harshahvg7 <72880742+harshahvg7@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:58:43 +0530 Subject: [PATCH 602/781] Ds.md Optimised code for getting sum of elements in array quickly --- Sum of elements in array.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Sum of elements in array.cpp diff --git a/Sum of elements in array.cpp b/Sum of elements in array.cpp new file mode 100644 index 00000000..6e72f6ad --- /dev/null +++ b/Sum of elements in array.cpp @@ -0,0 +1,17 @@ + +#include +int main() +{ +int array [10] = {1, 2, 3, 4, 5, 6, 7, 8,9,0}; +int sum, Loop; +sum= 0; +for( loop = 9; loop >= 0; loop--) +{ +sum = sum+ array[loop]; + +} +printr("Sum of array is %d.", sum); + +return 0; + +} From 766729330440e74c395989e133f4093267420a55 Mon Sep 17 00:00:00 2001 From: Vipanshu Suman <73050057+vipu18@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:03:40 +0530 Subject: [PATCH 603/781] Create max_gcd_of_numbers.cpp Calculates the Greatest Common Divisor of Numbers. --- max_gcd_of_numbers.cpp | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 max_gcd_of_numbers.cpp diff --git a/max_gcd_of_numbers.cpp b/max_gcd_of_numbers.cpp new file mode 100644 index 00000000..5a2aa328 --- /dev/null +++ b/max_gcd_of_numbers.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; + +int max_gcd(int num) { + int m, res, i, a, cnt; + + m = num; + res = 0; + i = m; + + while (i > 0) { + a = i; + cnt = 0; + while (a <= m) { + cnt += 1; + a += i; + } + if (cnt >= 2) { + res = i; + break; + } + i -= 1; + } + return res; +} + +int main() { + int test_case, num; + cin >> test_case; + for (int i = 0; i < test_case; i++) { + cin >> num; + cout << max_gcd(num) << "\n"; + } + return 0; +} From bb30f6025dcf330f64442591ebb9c7c6d2e63093 Mon Sep 17 00:00:00 2001 From: utkarsh778 <73051697+utkarsh778@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:08:18 +0530 Subject: [PATCH 604/781] Create factorial_of_a_number.c --- factorial_of_a_number.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 factorial_of_a_number.c diff --git a/factorial_of_a_number.c b/factorial_of_a_number.c new file mode 100644 index 00000000..6095a083 --- /dev/null +++ b/factorial_of_a_number.c @@ -0,0 +1,12 @@ +#include +int main() +{ + int i,fact=1,number; + printf("Enter a number: "); + scanf("%d",&number); + for(i=1;i<=number;i++){ + fact=fact*i; + } + printf("Factorial of %d is: %d",number,fact); +return 0; +} From a7646fa416efdb130302d6981761d35a86dea1a0 Mon Sep 17 00:00:00 2001 From: utkarsh778 <73051697+utkarsh778@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:10:01 +0530 Subject: [PATCH 605/781] Create create_power_of_any_number --- create_power_of_any_number | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 create_power_of_any_number diff --git a/create_power_of_any_number b/create_power_of_any_number new file mode 100644 index 00000000..26c3b012 --- /dev/null +++ b/create_power_of_any_number @@ -0,0 +1,30 @@ +import java.util.*; +class Solution { + + static float power(float x, int y) + { + float result; + if( y == 0) + return 1; + result = power(x, y/2); + + if (y%2 == 0) + return result * result; + else + { + if(y > 0) + return x * result * result; + else + return (result * result) / x; + } + } + + /* Program to test function power */ + public static void main(String[] args) + { + Scanner sc= new Scanner(System.in); + float x = sc.nextFloat(); + int y = sc.nextInt(); + System.out.printf("%f", power(x, y)); + } +} From 32d4b01728d89f41eaa9752ec753f4531295d22e Mon Sep 17 00:00:00 2001 From: apurva0411 <44138819+apurva0411@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:10:52 +0530 Subject: [PATCH 606/781] PerfectSumProblem.java --- Perfect Sum probelm in java | 99 +++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Perfect Sum probelm in java diff --git a/Perfect Sum probelm in java b/Perfect Sum probelm in java new file mode 100644 index 00000000..2f97396e --- /dev/null +++ b/Perfect Sum probelm in java @@ -0,0 +1,99 @@ +import java.util.ArrayList; +public class SubSet_sum_problem +{ + // dp[i][j] is going to store true if sum j is + // possible with array elements from 0 to i. + static boolean[][] dp; + + static void display(ArrayList v) + { + System.out.println(v); + } + + // A recursive function to print all subsets with the + // help of dp[][]. Vector p[] stores current subset. + static void printSubsetsRec(int arr[], int i, int sum, + ArrayList p) + { + // If we reached end and sum is non-zero. We print + // p[] only if arr[0] is equal to sun OR dp[0][sum] + // is true. + if (i == 0 && sum != 0 && dp[0][sum]) + { + p.add(arr[i]); + display(p); + p.clear(); + return; + } + + // If sum becomes 0 + if (i == 0 && sum == 0) + { + display(p); + p.clear(); + return; + } + + // If given sum can be achieved after ignoring + // current element. + if (dp[i-1][sum]) + { + // Create a new vector to store path + ArrayList b = new ArrayList<>(); + b.addAll(p); + printSubsetsRec(arr, i-1, sum, b); + } + + // If given sum can be achieved after considering + // current element. + if (sum >= arr[i] && dp[i-1][sum-arr[i]]) + { + p.add(arr[i]); + printSubsetsRec(arr, i-1, sum-arr[i], p); + } + } + + // Prints all subsets of arr[0..n-1] with sum 0. + static void printAllSubsets(int arr[], int n, int sum) + { + if (n == 0 || sum < 0) + return; + + // Sum 0 can always be achieved with 0 elements + dp = new boolean[n][sum + 1]; + for (int i=0; i p = new ArrayList<>(); + printSubsetsRec(arr, n-1, sum, p); + } + + public static void main(String args[]) + { + int arr[] = {1, 2, 3, 4, 5}; + int n = arr.length; + int sum = 10; + printAllSubsets(arr, n, sum); + } +} From 49fb36a6c616d8ea49d523ca535552a2f3344441 Mon Sep 17 00:00:00 2001 From: awesomask <64328246+awesomask@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:11:48 +0530 Subject: [PATCH 607/781] Create Program to find the biggest of three integer using functions I have written a code for finding the biggest of three integers using functions in C language. It takes three inputs and gives the biggest of the three input integers as an output. --- ...e biggest of three integer using functions | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Program to find the biggest of three integer using functions diff --git a/Program to find the biggest of three integer using functions b/Program to find the biggest of three integer using functions new file mode 100644 index 00000000..59ec9a47 --- /dev/null +++ b/Program to find the biggest of three integer using functions @@ -0,0 +1,26 @@ +#include +int greater(int a,int b, int c); + +int main() +{ +int num1 , num2 , num3 , large; +printf("\n Enter the first number:"); +scanf("%d",&num1); +printf("\n Enter the second number:"); +scanf("%d",&num2); +printf("\n Enter the third number:"); +scanf("%d",&num3); + +large= greater(num1,num2,num3); +printf("\n Largest number=%d",large); +return0; +} +int greater{int a, int b, int c} +{ + if(a>b&&a>c) + return a; + if(b>a&&b>c) + return b; + else + return c; +} From 973e5f90464324b17f0bc149511e3b70070012fa Mon Sep 17 00:00:00 2001 From: utkarsh778 <73051697+utkarsh778@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:11:56 +0530 Subject: [PATCH 608/781] Create fibonacci_series_java --- fibonacci_series_java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 fibonacci_series_java diff --git a/fibonacci_series_java b/fibonacci_series_java new file mode 100644 index 00000000..0dc63143 --- /dev/null +++ b/fibonacci_series_java @@ -0,0 +1,17 @@ +import java.util.*; + +class Solution { + +static int fib(int n) { +double result = (1 + Math.sqrt(5)) / 2; +return (int) Math.round(Math.pow(result, n) + / Math.sqrt(5)); +} + +// Driver Code +public static void main(String[] args) { + Scanner sc=new Scanner(System.in); + int n=sc.nextInt(); + System.out.println(fib(n)); + } +} From fccdb1d8ac07d50f026e079098a7356ddf65482b Mon Sep 17 00:00:00 2001 From: pmanasi <36513491+pmanasi@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:14:14 +0530 Subject: [PATCH 609/781] Create Print fibonacci series Optimized python code for printing Fibonacci series. --- Print fibonacci series | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Print fibonacci series diff --git a/Print fibonacci series b/Print fibonacci series new file mode 100644 index 00000000..7ba45aa5 --- /dev/null +++ b/Print fibonacci series @@ -0,0 +1,18 @@ +nterms = int(input("How many terms? ")) + +n1, n2 = 0, 1 +count = 0 + +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + n1 = n2 + n2 = nth + count += 1 From a6200b7151391f154906433e1af82ea884515f66 Mon Sep 17 00:00:00 2001 From: Aswinipai <57011217+Aswinipai@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:50:05 +0530 Subject: [PATCH 610/781] Create Program to convert binary to decimal.c Optimized code for converting binary to decimal --- Program to convert binary to decimal.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Program to convert binary to decimal.c diff --git a/Program to convert binary to decimal.c b/Program to convert binary to decimal.c new file mode 100644 index 00000000..b721e0bc --- /dev/null +++ b/Program to convert binary to decimal.c @@ -0,0 +1,20 @@ + +#include +#include +#include + +int main() +{ + char binaryNumber[] = "1001"; + int bin, decimal = 0; + + bin = atoi(binaryNumber); + + for(int i = 0; bin; i++, bin /= 10) + if (bin % 10) + decimal += pow(2, i); + + printf("%d", decimal); + + return 0; +} From 6daf54a1b60e2e3691ab0e8fdb5ad8dfcada1751 Mon Sep 17 00:00:00 2001 From: Samiksha sandip sankar Date: Sun, 18 Oct 2020 12:55:21 +0530 Subject: [PATCH 611/781] Program to print Fibonnaci Series in java --- Program to print Fibonnaci Series in java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Program to print Fibonnaci Series in java diff --git a/Program to print Fibonnaci Series in java b/Program to print Fibonnaci Series in java new file mode 100644 index 00000000..15325705 --- /dev/null +++ b/Program to print Fibonnaci Series in java @@ -0,0 +1,21 @@ +public class Fibonacci { + + public static void main(String[] args) { + + int n = 10, n1 = 0, n2 = 1; + + System.out.print(" Fibonacci Series : "); + + for (int i = 1; i <= n; ++i) + { + + System.out.print(n1 + " "); + + int sum = n1 + n2; + n1 = n2; + n2 = sum; + + } + + } +} From 96d94cfba5fda3a3eaa1344003de1baece76082e Mon Sep 17 00:00:00 2001 From: jatinmankar <57310502+jatinmankar@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:56:22 +0530 Subject: [PATCH 612/781] Program to find largest element in array optimised code to Program to find largest element in array using C++ --- ...ind largest element in array using C++ language | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Program to find largest element in array using C++ language diff --git a/Program to find largest element in array using C++ language b/Program to find largest element in array using C++ language new file mode 100644 index 00000000..8862a95b --- /dev/null +++ b/Program to find largest element in array using C++ language @@ -0,0 +1,14 @@ +##Program to find largest element in array +main(){ +int n; +cout<<"Enter length of arrays" +cin>>n; +int s[n]; +for(int i=0;i>s[i];} +int max=s[0] +for(int j=0;j Date: Sun, 18 Oct 2020 12:56:55 +0530 Subject: [PATCH 613/781] Create Reversing the array Reverse the array --- Reversing the array | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Reversing the array diff --git a/Reversing the array b/Reversing the array new file mode 100644 index 00000000..e363d7bb --- /dev/null +++ b/Reversing the array @@ -0,0 +1,27 @@ +#include +#include +using namespace std; + +int main() +{ + int n; + cout << "Enter the size of array: "; + cin >> n; + int arr[n]; + cout << "Enter array elements: "; + + for(int i=0; i> arr[i]; + + + cout << "Entered array is: "; + for (int i = 0; i < n; i++) + cout << arr[i] << " "; + + reverse(arr, arr + n); + + cout << "\nReversed Array: "; + for (int i = 0; i < n; i++) + cout << arr[i] << " "; + return 0; +} From 7c49398ca9fb21915b08cdd934ae88e14e28d7cb Mon Sep 17 00:00:00 2001 From: awesomask <64328246+awesomask@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:57:51 +0530 Subject: [PATCH 614/781] Create Program to print the position of the smallest of n numbers using array. Using this program we can obtain the smallest number and where it is located in the series. The random numbers are taken by the user as an input and then the program finds the smallest number and its position from the input as an output. This program is made using C language. --- ...of the smallest of n numbers using array. | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Program to print the position of the smallest of n numbers using array. diff --git a/Program to print the position of the smallest of n numbers using array. b/Program to print the position of the smallest of n numbers using array. new file mode 100644 index 00000000..81cfd076 --- /dev/null +++ b/Program to print the position of the smallest of n numbers using array. @@ -0,0 +1,22 @@ + +#include +#include +int main() +{ +int i, n , arr[20], small=1234, pos = -1; +clrscr(); + +printf("\n Enter the number of elements in the array; "); +scanf("%d",&n); +for(i=0;i Date: Sun, 18 Oct 2020 12:58:19 +0530 Subject: [PATCH 615/781] Create Fibonocci series Optimized file for fibonocci series --- Fibonocci series | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Fibonocci series diff --git a/Fibonocci series b/Fibonocci series new file mode 100644 index 00000000..1d7ff90c --- /dev/null +++ b/Fibonocci series @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nT; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nT; + } + + return 0; +} From ce2838636bd65a91f7c19ce555be20da958bc5d1 Mon Sep 17 00:00:00 2001 From: theartemis23 <73038140+theartemis23@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:58:33 +0530 Subject: [PATCH 616/781] Create To find the largest element in an array Optimized Code For Largest Elements in an array. --- To find the largest element in an array | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 To find the largest element in an array diff --git a/To find the largest element in an array b/To find the largest element in an array new file mode 100644 index 00000000..f9d7bf15 --- /dev/null +++ b/To find the largest element in an array @@ -0,0 +1,20 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From d5b9b3dfc600a71a31f251ba633d22e05259443c Mon Sep 17 00:00:00 2001 From: utkarsh778 <73051697+utkarsh778@users.noreply.github.com> Date: Sun, 18 Oct 2020 12:59:43 +0530 Subject: [PATCH 617/781] Create Finding the power of any numbers Finding the power of any numbers --- Finding the power of any numbers | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Finding the power of any numbers diff --git a/Finding the power of any numbers b/Finding the power of any numbers new file mode 100644 index 00000000..5fa94a86 --- /dev/null +++ b/Finding the power of any numbers @@ -0,0 +1,24 @@ +#include +using namespace std; + +int power(int base , int exp) +{ + long long int power_of_num = 1; + + while(exp!=0) + { + power_of_num *= base; + exp -= 1; + } + + return power_of_num; +} + +int main() +{ + int base, exp; + cin>>base>>exp; + cout< Date: Sun, 18 Oct 2020 12:59:43 +0530 Subject: [PATCH 618/781] Program to count sum of all numbers in array optimised the code to Program to count sum of all numbers in array --- ...count sum of all numbers in array in C++ language | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Program to count sum of all numbers in array in C++ language diff --git a/Program to count sum of all numbers in array in C++ language b/Program to count sum of all numbers in array in C++ language new file mode 100644 index 00000000..f0e02078 --- /dev/null +++ b/Program to count sum of all numbers in array in C++ language @@ -0,0 +1,12 @@ +##Program to count sum of all numbers in array +main(){ +int n; +cout<<"Enter the length of array"; +cin>>n; +int s[n]; +for(int j=0;j>s[j];} +long long int sum=0; +for(int i=0;i Date: Sun, 18 Oct 2020 13:01:29 +0530 Subject: [PATCH 619/781] Program to find factorial of number using C++ Optimised the code to Program to find factorial of number using C++ --- Program to find factorial of number using C++ language | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program to find factorial of number using C++ language diff --git a/Program to find factorial of number using C++ language b/Program to find factorial of number using C++ language new file mode 100644 index 00000000..2dba75a8 --- /dev/null +++ b/Program to find factorial of number using C++ language @@ -0,0 +1,10 @@ +##Program to find factorial of number +main(){ +int n,fact=1; +cin>>n; +if(n==0) +cout<<"1"; +if(n>1){ +for(int i=1;i<=n;i++){ +fact=fact*i;} +cout< Date: Sun, 18 Oct 2020 13:02:40 +0530 Subject: [PATCH 620/781] Create ASCII value Optimized file for ASCII value --- ASCII value | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 ASCII value diff --git a/ASCII value b/ASCII value new file mode 100644 index 00000000..087d70d5 --- /dev/null +++ b/ASCII value @@ -0,0 +1,3 @@ +inp = str(input("Enter the character ")) + +print(f"ASCII value of {inp} is "+str(ord(inp))) From 98075cd871360981cc0a94b194c18d2ec9169cd6 Mon Sep 17 00:00:00 2001 From: Aswinipai <57011217+Aswinipai@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:05:19 +0530 Subject: [PATCH 621/781] Create To find the length of a string Optimized program to find the length of a string --- To find the length of a string | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 To find the length of a string diff --git a/To find the length of a string b/To find the length of a string new file mode 100644 index 00000000..c8f5c534 --- /dev/null +++ b/To find the length of a string @@ -0,0 +1,11 @@ + +#include +int main() { + char s[] = "I love programming"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 4504f8c5fddbd7bea5eeb7e9dd2bc606075e9f60 Mon Sep 17 00:00:00 2001 From: awesomask <64328246+awesomask@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:08:03 +0530 Subject: [PATCH 622/781] Create Program to convert lower case to upper and upper case to lower This program using C language can convert any charecter alphabet from A-Z into lower cae if it is in upper case or vice-versa. --- ...t lower case to upper and upper case to lower | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program to convert lower case to upper and upper case to lower diff --git a/Program to convert lower case to upper and upper case to lower b/Program to convert lower case to upper and upper case to lower new file mode 100644 index 00000000..65416059 --- /dev/null +++ b/Program to convert lower case to upper and upper case to lower @@ -0,0 +1,16 @@ +#include +#include +int main() +{ + char ch; + clrscr(); + printf("\n Enter any charecter:"); + scanf("%c",&ch); + + if (ch>= 'A'&& ch<='Z') + printf("\n The entered charecter was in upper case. In lower case it is : %c",(ch+32)); + + else + printf("\n The entered charecter was in lower case.In upper case it is : %c",(ch-32)); + return 0; + } From e229e0b1068c84d8007413024898b7d3bdaea912 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Sharma <53513799+shubhamkumarcs@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:08:28 +0530 Subject: [PATCH 623/781] Fibonacci series print --- To obtain the Fibonacci series | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 To obtain the Fibonacci series diff --git a/To obtain the Fibonacci series b/To obtain the Fibonacci series new file mode 100644 index 00000000..2ae3e317 --- /dev/null +++ b/To obtain the Fibonacci series @@ -0,0 +1,14 @@ +#include +int main() { + + printf("enter the value"); + scanf("%d",&n); + for(i=1;i<=n;i++) + { + printf("%d",a); + c=a+b; + a=b; + b=c; + } + return 0; +}int n,i,a=0,b=1,c; From 8e142830cb788cfddd5747eb210d8406339addf6 Mon Sep 17 00:00:00 2001 From: theartemis23 <73038140+theartemis23@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:10:03 +0530 Subject: [PATCH 624/781] Create Program to find the smallest element in an array Optimized code to find the smallest element in an array. --- ...m to find the smallest element in an array | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Program to find the smallest element in an array diff --git a/Program to find the smallest element in an array b/Program to find the smallest element in an array new file mode 100644 index 00000000..441e2ce4 --- /dev/null +++ b/Program to find the smallest element in an array @@ -0,0 +1,26 @@ +#include + +int main() { + int a[30], i, num, smallest; + + printf("\nEnter no of elements :"); + scanf("%d", &num); + + //Read n elements in an array + for (i = 0; i < num; i++) + scanf("%d", &a[i]); + + //Consider first element as smallest + smallest = a[0]; + + for (i = 0; i < num; i++) { + if (a[i] < smallest) { + smallest = a[i]; + } + } + + // Print out the Result + printf("\nSmallest Element : %d", smallest); + + return (0); +} From d816dddf90ea7e6267ba9f2b9a6086c1de6a1814 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Sharma <53513799+shubhamkumarcs@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:11:27 +0530 Subject: [PATCH 625/781] Create To find the length of any string like "Shubham" --- ...ind the length of any string like \"Shubham\"" | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 "To find the length of any string like \"Shubham\"" diff --git "a/To find the length of any string like \"Shubham\"" "b/To find the length of any string like \"Shubham\"" new file mode 100644 index 00000000..acd0b0e3 --- /dev/null +++ "b/To find the length of any string like \"Shubham\"" @@ -0,0 +1,15 @@ +# Python code to demonstrate string length +# using for loop + +# Returns length of string +def findLen(str): + counter = 0 + for i in str: + counter += 1 + return counter + + +str = "Shubham" +print(findLen(str)) + +# This code is contributed by Shubham Kumar Sharma From 79d9eb92dd3dc38ac1d4968178d2b335834d6968 Mon Sep 17 00:00:00 2001 From: theartemis23 <73038140+theartemis23@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:13:47 +0530 Subject: [PATCH 626/781] Create Program to find the sum of all element in an array Optimized code to find the sum of all elements in an array. --- ... find the sum of all element in an array | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Program to find the sum of all element in an array diff --git a/Program to find the sum of all element in an array b/Program to find the sum of all element in an array new file mode 100644 index 00000000..60e55679 --- /dev/null +++ b/Program to find the sum of all element in an array @@ -0,0 +1,26 @@ +#include + + +int main() +{ + int a[1000],i,n,sum=0; + + printf("Enter size of the array : "); + scanf("%d",&n); + + printf("Enter elements in array : "); + for(i=0; i Date: Sun, 18 Oct 2020 13:14:01 +0530 Subject: [PATCH 627/781] Create This code is for finding the length of a string --- This code is for finding the length of a string | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 This code is for finding the length of a string diff --git a/This code is for finding the length of a string b/This code is for finding the length of a string new file mode 100644 index 00000000..99be0d52 --- /dev/null +++ b/This code is for finding the length of a string @@ -0,0 +1,15 @@ +# Python code to demonstrate string length +# using for loop + +# Returns length of string +def findLen(str): + counter = 0 + for i in str: + counter += 1 + return counter + + +str = "Shubham" +print(findLen(str)) + +# This code is contributed by Shubham From 568b61b22536b4584a33f59a6967d053e6f9676b Mon Sep 17 00:00:00 2001 From: Aswinipai <57011217+Aswinipai@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:15:16 +0530 Subject: [PATCH 628/781] Create Bubble sort Optimized program for bubble sort --- Bubble sort | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 Bubble sort diff --git a/Bubble sort b/Bubble sort new file mode 100644 index 00000000..c7b34f8e --- /dev/null +++ b/Bubble sort @@ -0,0 +1,34 @@ +#include + +int main(){ + + int count, temp, i, j, n[30]; + + printf("How many numbers are u going to enter?: "); + scanf("%d",&count); + + printf("Enter %d numbers: ",count); + + for(i=0;i=0;i--) + { + for(j=0;j<=i;j++) + { + if(n[j]>n[j+1]) + { + temp=n[j]; + n[j]=n[j+1]; + n[j+1]=temp; + } + } + } + + printf("Sorted elements: "); + for(i=0;i Date: Sun, 18 Oct 2020 13:17:07 +0530 Subject: [PATCH 629/781] Create To find the length of the string --- To find the length of the string | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 To find the length of the string diff --git a/To find the length of the string b/To find the length of the string new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/To find the length of the string @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From f1e4a4490de24011e6bc639f357d00f8dd31296f Mon Sep 17 00:00:00 2001 From: jatinmankar <57310502+jatinmankar@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:17:13 +0530 Subject: [PATCH 630/781] Program to calculate count of vowels & consonants in string Optimised code to Program to calculate count of vowels & consonants in string using C++. --- ... count of vowels & consonants in string using C++ | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Program to calculate count of vowels & consonants in string using C++ diff --git a/Program to calculate count of vowels & consonants in string using C++ b/Program to calculate count of vowels & consonants in string using C++ new file mode 100644 index 00000000..79411dd6 --- /dev/null +++ b/Program to calculate count of vowels & consonants in string using C++ @@ -0,0 +1,12 @@ +##Program to calculate count of vowels & consonants in string +main(){ +int n,vov=0,con=0; +string s; +cin>>s; +n=s.length(); +for(int i=0;i Date: Sun, 18 Oct 2020 13:17:36 +0530 Subject: [PATCH 631/781] Create Program to find the length of a string. (Without strlen() function ) Optimized code to find the length of a string without predefined function. --- ...he length of a string. (Without strlen() function ) | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Program to find the length of a string. (Without strlen() function ) diff --git a/Program to find the length of a string. (Without strlen() function ) b/Program to find the length of a string. (Without strlen() function ) new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/Program to find the length of a string. (Without strlen() function ) @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 068792e9d113ec74fa1ae0695e949eb2206b2ede Mon Sep 17 00:00:00 2001 From: awesomask <64328246+awesomask@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:18:24 +0530 Subject: [PATCH 632/781] Create Program to classify a number as prime number or composite, In this program using C language we take a input from user which can be any number and as an output we tell if the number is a priome number or a composite number. --- ...ify a number as prime number or composite, | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Program to classify a number as prime number or composite, diff --git a/Program to classify a number as prime number or composite, b/Program to classify a number as prime number or composite, new file mode 100644 index 00000000..f540b7f5 --- /dev/null +++ b/Program to classify a number as prime number or composite, @@ -0,0 +1,24 @@ +#include +#include +int main() +{ +int flag=0,i,num; +clrscr(); + +prontf("\n Enter any number:"); +scanf("%d",&num); +for(i=2; i Date: Sun, 18 Oct 2020 13:22:02 +0530 Subject: [PATCH 633/781] Create How to reverse a number in C Optimized program for reversing a number --- How to reverse a number in C | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 How to reverse a number in C diff --git a/How to reverse a number in C b/How to reverse a number in C new file mode 100644 index 00000000..2555af0a --- /dev/null +++ b/How to reverse a number in C @@ -0,0 +1,13 @@ +#include +int main() { + int n, rev = 0, remainder; + printf("Enter an integer: "); + scanf("%d", &n); + while (n != 0) { + remainder = n % 10; + rev = rev * 10 + remainder; + n /= 10; + } + printf("Reversed number = %d", rev); + return 0; +} From ec3a60f45568f378c5294d49b4fb52447144d235 Mon Sep 17 00:00:00 2001 From: Niranjana K <71917062+NiranjanaK03@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:33:33 +0530 Subject: [PATCH 634/781] Create program to print the ASCII value of a character Optimized code in C language to print the ASCII value of a given character. --- program to print the ASCII value of a character | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 program to print the ASCII value of a character diff --git a/program to print the ASCII value of a character b/program to print the ASCII value of a character new file mode 100644 index 00000000..a73b9c24 --- /dev/null +++ b/program to print the ASCII value of a character @@ -0,0 +1,12 @@ +#include +int main() { + char c; + printf("Enter a character: "); + scanf("%c", &c); + + // %d displays the integer value of a character + // %c displays the actual character + printf("ASCII value of %c = %d", c, c); + + return 0; +} From 804e22eab79ad27cc04d6a8e54dc795121879975 Mon Sep 17 00:00:00 2001 From: Jerome Wilson <64187954+Jerry-dev233@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:53:14 +0530 Subject: [PATCH 635/781] Create Python program to reverse an array Reversing the order of an array --- Python program to reverse an array | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Python program to reverse an array diff --git a/Python program to reverse an array b/Python program to reverse an array new file mode 100644 index 00000000..09caa7eb --- /dev/null +++ b/Python program to reverse an array @@ -0,0 +1,19 @@ +#code +# function to reverse A[] +def reverseList(A, start, end): + while start < end: + A[start], A[end] = A[end], A[start] + start += 1 + end -= 1 + +# driver function +A = [1, 2, 3, 4, 5, 6] +print(A) +reverseList(A, 0, 5) +print("Reversed list is") +print(A) + +#output +1 2 3 4 5 6 +Reversed array is +6 5 4 3 2 1 From 0be244c955a1e444fe5ffe3e90c7951d34b39be8 Mon Sep 17 00:00:00 2001 From: akshay7789 <73055763+akshay7789@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:53:31 +0530 Subject: [PATCH 636/781] Create Primee numbers between interval Primee numbers between interval --- Primee numbers between interval | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 Primee numbers between interval diff --git a/Primee numbers between interval b/Primee numbers between interval new file mode 100644 index 00000000..8bd09df4 --- /dev/null +++ b/Primee numbers between interval @@ -0,0 +1,55 @@ +import java.util.*; + +class Main { + + // driver code + public static void main(String[] args) + { + Scanner sc = new Scanner(System.in); + + int a, b, i, j,flag; + + // enter lower value of interval + System.out.printf( "Enter lower bound of the interval: "); + a = sc.nextInt(); + + // enter upper value of interval + System.out.printf( "\nEnter upper bound of the interval: "); + b = sc.nextInt(); + + System.out.printf("\nPrime numbers between %d and %d are: ", a, b); + + // Explicitly handling the cases when a is less than 2 + if (a == 1) { + System.out.println(a); + a++; + if (b >= 2) { + System.out.println(a); + a++; + } + } + if (a == 2) + System.out.println(a); + + + if (a % 2 == 0) + a++; + + + for (i = a; i <= b; i = i + 2) { + + + flag = 1; + + for (j = 2; j * j <= i; ++j) { + if (i % j == 0) { + flag = 0; + break; + } + } + if (flag == 1) + System.out.println(i); + } + + } +} From fc97813ba534f1f9d2bdc6b49e548dc36a6465a1 Mon Sep 17 00:00:00 2001 From: akshay7789 <73055763+akshay7789@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:55:04 +0530 Subject: [PATCH 637/781] Create Matrix multiplications matrix multiplications --- Matrix multiplications | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Matrix multiplications diff --git a/Matrix multiplications b/Matrix multiplications new file mode 100644 index 00000000..566c725d --- /dev/null +++ b/Matrix multiplications @@ -0,0 +1,42 @@ +#include +#define N 4 + +// This function multiplies mat1[][] and mat2[][], +// and stores the result in res[][] +void multiply(int mat1[][N], int mat2[][N], int res[][N]) +{ + int i, j, k; + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) { + res[i][j] = 0; + for (k = 0; k < N; k++) + res[i][j] += mat1[i][k] * mat2[k][j]; + } + } +} + +int main() +{ + int mat1[N][N] = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + int mat2[N][N] = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + int res[N][N]; // To store result + int i, j; + multiply(mat1, mat2, res); + + printf("Result matrix is \n"); + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) + printf("%d ", res[i][j]); + printf("\n"); + } + + return 0; +} From cdd2fea35caf69f550472a2d513df0e22fe838ee Mon Sep 17 00:00:00 2001 From: akshay7789 <73055763+akshay7789@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:56:35 +0530 Subject: [PATCH 638/781] Create Counting number of digits in an integers Counting number of digits in an integers --- Counting number of digits in an integers | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Counting number of digits in an integers diff --git a/Counting number of digits in an integers b/Counting number of digits in an integers new file mode 100644 index 00000000..f8c75237 --- /dev/null +++ b/Counting number of digits in an integers @@ -0,0 +1,15 @@ +#include + +int main(){ +int n,count=0; + +printf("Enter an integer:"); +scanf("%d",&n); + +while(n!=0){ +n/=10; +count++; +} + +printf("Number of digits:%d",count); +} From f597d3f1a651ba9fb29828c45f3cb1e15ec37a00 Mon Sep 17 00:00:00 2001 From: Ridwan Kustanto Date: Sun, 18 Oct 2020 15:27:07 +0700 Subject: [PATCH 639/781] Create array_reverser_by_ridwankustanto.go --- array_reverser_by_ridwankustanto.go | 36 +++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 array_reverser_by_ridwankustanto.go diff --git a/array_reverser_by_ridwankustanto.go b/array_reverser_by_ridwankustanto.go new file mode 100644 index 00000000..41a9c207 --- /dev/null +++ b/array_reverser_by_ridwankustanto.go @@ -0,0 +1,36 @@ +package main + +import ( + "flag" + "fmt" + "strings" +) + +func main() { + + defaultArr := "1,31,october,hacktoberfest" + fmt.Println("Default array value: ", defaultArr) + + var ( + arr, arrReversed []interface{} + ) + + str := flag.String("array", defaultArr, "set of array that want to be reversed. must be separated by ',' between the items") + flag.Parse() + + arrStr := strings.Split(*str, ",") + for _, item := range arrStr { + arr = append(arr, item) + } + + fmt.Println("set of array: ", arr) + + arrLenght := len(arr) + + for i := arrLenght-1; i >= 0; i-- { + arrReversed = append(arrReversed, arr[i]) + } + + fmt.Println("set of reversed array: ", arrReversed) + +} From 26ed0899ee2d3e9bbabeaa48b7b30822386d4083 Mon Sep 17 00:00:00 2001 From: akshay7789 <73055763+akshay7789@users.noreply.github.com> Date: Sun, 18 Oct 2020 13:58:14 +0530 Subject: [PATCH 640/781] Create Comparing the two strings --- Comparing the two strings | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Comparing the two strings diff --git a/Comparing the two strings b/Comparing the two strings new file mode 100644 index 00000000..52c5de66 --- /dev/null +++ b/Comparing the two strings @@ -0,0 +1,14 @@ +import java.util.*; +class Compare +{ +public static void main(String args[]) +{ +Scanner sc=new Scanner(System.in); +String s1=sc.nextLine(); +String s2=sc.nextLine(); +if(s1.equalsIgnoreCase(s2)) +System.out.println("Same"); +else +System.out.println("Not Same"); +} +} From 94dff35c134cdff096fbd150e9cfbb677130f259 Mon Sep 17 00:00:00 2001 From: utkarsh778 <73051697+utkarsh778@users.noreply.github.com> Date: Sun, 18 Oct 2020 14:01:04 +0530 Subject: [PATCH 641/781] Create Creating a matrix multiplications Creating a matrix multiplications --- Creating a matrix multiplications | 43 +++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Creating a matrix multiplications diff --git a/Creating a matrix multiplications b/Creating a matrix multiplications new file mode 100644 index 00000000..786b5649 --- /dev/null +++ b/Creating a matrix multiplications @@ -0,0 +1,43 @@ +// C program to multiply two square matrices. +#include +#define N 4 + +// This function multiplies mat1[][] and mat2[][], +// and stores the result in res[][] +void multiply(int mat1[][N], int mat2[][N], int res[][N]) +{ + int i, j, k; + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) { + res[i][j] = 0; + for (k = 0; k < N; k++) + res[i][j] += mat1[i][k] * mat2[k][j]; + } + } +} + +int main() +{ + int mat1[N][N] = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + int mat2[N][N] = { { 1, 1, 1, 1 }, + { 2, 2, 2, 2 }, + { 3, 3, 3, 3 }, + { 4, 4, 4, 4 } }; + + int res[N][N]; // To store result + int i, j; + multiply(mat1, mat2, res); + + printf("Result matrix is \n"); + for (i = 0; i < N; i++) { + for (j = 0; j < N; j++) + printf("%d ", res[i][j]); + printf("\n"); + } + + return 0; +} From 5475069983cf54399e5cb2f11c4e914df370f832 Mon Sep 17 00:00:00 2001 From: Jerome Wilson <64187954+Jerry-dev233@users.noreply.github.com> Date: Sun, 18 Oct 2020 14:04:24 +0530 Subject: [PATCH 642/781] Create Python program to convert binary to decimal conversion Binary to decimal conversion --- ...am to convert binary to decimal conversion | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Python program to convert binary to decimal conversion diff --git a/Python program to convert binary to decimal conversion b/Python program to convert binary to decimal conversion new file mode 100644 index 00000000..b1da451e --- /dev/null +++ b/Python program to convert binary to decimal conversion @@ -0,0 +1,28 @@ +#code +# function to convert decimal to binary +def decToBinary(n): + + # array to store binary number + binaryNum = [0] * n; + + # counter for binary array + i = 0; + while (n > 0): + + # storing remainder + # in binary array + binaryNum[i] = n % 2; + n = int(n / 2); + i += 1; + + # printing binary array + # in reverse order + for j in range(i - 1, -1, -1): + print(binaryNum[j], end = ""); + +# driver Code +n = 23; +decToBinary(n); + +#output +10111 From 8dc4338d5b1af21a78fb943f51148c76cf6bce3b Mon Sep 17 00:00:00 2001 From: PA_NQT Date: Sun, 18 Oct 2020 15:35:55 +0700 Subject: [PATCH 643/781] Create sum of elements in a array... Create sum of elements in an array.... --- sum of elements in a array... | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum of elements in a array... diff --git a/sum of elements in a array... b/sum of elements in a array... new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/sum of elements in a array... @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From 76de52a1431dcdc52eb859b7ab8e17de837b2b55 Mon Sep 17 00:00:00 2001 From: PA_NQT Date: Sun, 18 Oct 2020 15:37:56 +0700 Subject: [PATCH 644/781] Create sum of elements in a array.... Create sum of elements in Array.... --- sum of elements in a array.... | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum of elements in a array.... diff --git a/sum of elements in a array.... b/sum of elements in a array.... new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/sum of elements in a array.... @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From ed577aee96f303b9d97500f3e2d0eb3d87af3d24 Mon Sep 17 00:00:00 2001 From: PA_NQT Date: Sun, 18 Oct 2020 15:39:13 +0700 Subject: [PATCH 645/781] Create sum of elements in a array..... MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create sum ò elements in a array..... --- sum of elements in a array..... | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum of elements in a array..... diff --git a/sum of elements in a array..... b/sum of elements in a array..... new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/sum of elements in a array..... @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From 88fd4690134d4295387d4421de612c89a91bc81a Mon Sep 17 00:00:00 2001 From: PA_NQT Date: Sun, 18 Oct 2020 15:40:11 +0700 Subject: [PATCH 646/781] Create sum of elements in a array...... Create sum of elements in a array...... --- sum of elements in a array...... | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 sum of elements in a array...... diff --git a/sum of elements in a array...... b/sum of elements in a array...... new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/sum of elements in a array...... @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From cdcf8f1df449349775cc9451d6fd80358d5727d4 Mon Sep 17 00:00:00 2001 From: harshahvg7 <72880742+harshahvg7@users.noreply.github.com> Date: Sun, 18 Oct 2020 14:14:43 +0530 Subject: [PATCH 647/781] Factorial.md Optimised code of factorial of number in quick way --- Factorial of number.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Factorial of number.py diff --git a/Factorial of number.py b/Factorial of number.py new file mode 100644 index 00000000..c18e6746 --- /dev/null +++ b/Factorial of number.py @@ -0,0 +1,19 @@ +#Python program to find the factorial of a number provided by the user. + +# change the value for a different result +num = 7 + +# To take input from the user +#num = int(input("Enter a number: ")) + +factorial = 1 + +# check if the number is negative, positive or zero +if num < 0: + print("Sorry, factorial does not exist for negative numbers") +elif num == 0: + print("The factorial of 0 is 1") +else: + for i in range(1,num + 1): + factorial = factorial*i + print("The factorial of",num,"is",factorial) From c909053d131dfbeb15d147a88d1bf4421520fc05 Mon Sep 17 00:00:00 2001 From: AaronF3PS <43633555+AaronF3PS@users.noreply.github.com> Date: Sun, 18 Oct 2020 11:54:31 +0300 Subject: [PATCH 648/781] Create Dijkstras Algorithm for Single Source Path-C++ Used Dijkstra's Algorithm to find the Single Source Shortest Path in a Graph. Done by Aaron --- ...stras Algorithm for Single Source Path-C++ | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Dijkstras Algorithm for Single Source Path-C++ diff --git a/Dijkstras Algorithm for Single Source Path-C++ b/Dijkstras Algorithm for Single Source Path-C++ new file mode 100644 index 00000000..828c5b11 --- /dev/null +++ b/Dijkstras Algorithm for Single Source Path-C++ @@ -0,0 +1,59 @@ +#include +#include +using namespace std; +#define INFINITY 9999 +#define max 5 + +void dijkstra(int G[max][max],int n,int startnode) +{ + int cost[max][max],distance[max],pred[max]; + int visited[max],count,mindistance,nextnode,i,j; + for(i=0;i Date: Sun, 18 Oct 2020 11:57:40 +0300 Subject: [PATCH 649/781] Create Linear Search Using Recursion-C++ Used recursion to solve linear search. Language used C++ Done by Aaron --- Linear Search Using Recursion-C++ | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Linear Search Using Recursion-C++ diff --git a/Linear Search Using Recursion-C++ b/Linear Search Using Recursion-C++ new file mode 100644 index 00000000..dbcb51f8 --- /dev/null +++ b/Linear Search Using Recursion-C++ @@ -0,0 +1,39 @@ +#include +using namespace std; + +int linear_search(int num,int low, int high,int a[]) +{ +if(high<1) +{ +return -1; +} +if(a[low]==num) +{ +return low; +} +else if(a[high]==num) +{ +return high; +} +else +{ +return linear_search(num,low+1,high-1,a); +} +} + int main() +{ +int i,a[100],num,position,n; cout<<"Enter the length of the array:"; cin>>n; cout<<"Enter the elements of the array:"; for(i=0;i>a[i]; +} +cout<<"Enter the element to be searched:"; cin>>num; +position=linear_search(num,0,n+1,a); +if(position!=-1) +{ +cout<<"The given element is present a t "< Date: Sun, 18 Oct 2020 14:42:50 +0530 Subject: [PATCH 650/781] Create Sum of elements in a array.. --- Sum of elements in a array.. | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Sum of elements in a array.. diff --git a/Sum of elements in a array.. b/Sum of elements in a array.. new file mode 100644 index 00000000..b8f40776 --- /dev/null +++ b/Sum of elements in a array.. @@ -0,0 +1,16 @@ +#include + +int main() { + int arry{10} = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}: + int sum, loop; + + sum = 0; + + for(loop = 9; loop >= 0; loop--) { + sum = sum + array[loop]; + } + + printf("sum of array is %d.", sum); + + return 0; +} From b15a007b82deab11f64abbf78c264f16f96e01d4 Mon Sep 17 00:00:00 2001 From: Madhusudan Anand <54022235+MadhusudanAnand@users.noreply.github.com> Date: Sun, 18 Oct 2020 14:44:59 +0530 Subject: [PATCH 651/781] Create C program for febonacci siries optimise program for fibonacci siries --- C program for febonacci siries | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 C program for febonacci siries diff --git a/C program for febonacci siries b/C program for febonacci siries new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/C program for febonacci siries @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 4511d2384ef7000535dcc3b5d39679cca41eb0be Mon Sep 17 00:00:00 2001 From: harshahvg7 <72880742+harshahvg7@users.noreply.github.com> Date: Sun, 18 Oct 2020 14:52:06 +0530 Subject: [PATCH 652/781] Smallest.md Optimized code for finding d smallest element in array in a quick way --- Smallest element in array.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Smallest element in array.py diff --git a/Smallest element in array.py b/Smallest element in array.py new file mode 100644 index 00000000..de939d35 --- /dev/null +++ b/Smallest element in array.py @@ -0,0 +1,14 @@ +#Initialize array +arr = [25, 11, 7, 75, 56]; + +#Initialize min with the first element of the array. + +min = arr[0]; + +#Loop through the array +for i in range(0, len(arr)): + #Compare elements of array with min + if(arr[i] < min): + min = arr[i]; + +print("Smallest element present in given array: " + str(min)); From bc499962a382e1ce0e1b6d139f97bbddebbaf8b8 Mon Sep 17 00:00:00 2001 From: Madhusudan Anand <54022235+MadhusudanAnand@users.noreply.github.com> Date: Sun, 18 Oct 2020 14:52:34 +0530 Subject: [PATCH 653/781] Create 2D Matrices using C optimized 2D Matrices using C --- 2D Matrices using C | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 2D Matrices using C diff --git a/2D Matrices using C b/2D Matrices using C new file mode 100644 index 00000000..136681df --- /dev/null +++ b/2D Matrices using C @@ -0,0 +1,40 @@ +#include +int main() { + int r, c, a[100][100], b[100][100], sum[100][100], i, j; + printf("Enter the number of rows (between 1 and 100): "); + scanf("%d", &r); + printf("Enter the number of columns (between 1 and 100): "); + scanf("%d", &c); + + printf("\nEnter elements of 1st matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &a[i][j]); + } + + printf("Enter elements of 2nd matrix:\n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("Enter element a%d%d: ", i + 1, j + 1); + scanf("%d", &b[i][j]); + } + + // adding two matrices + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + sum[i][j] = a[i][j] + b[i][j]; + } + + // printing the result + printf("\nSum of two matrices: \n"); + for (i = 0; i < r; ++i) + for (j = 0; j < c; ++j) { + printf("%d ", sum[i][j]); + if (j == c - 1) { + printf("\n\n"); + } + } + + return 0; +} From 9af14cb1e5aab7480070db7d36173699ed017d30 Mon Sep 17 00:00:00 2001 From: Madhusudan Anand <54022235+MadhusudanAnand@users.noreply.github.com> Date: Sun, 18 Oct 2020 14:59:44 +0530 Subject: [PATCH 654/781] Create code for ASCII code for ASCII --- code for ASCII | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 code for ASCII diff --git a/code for ASCII b/code for ASCII new file mode 100644 index 00000000..e84fc638 --- /dev/null +++ b/code for ASCII @@ -0,0 +1,11 @@ +#include +using namespace std; + +int main() +{ + char x; + cin>>x; + + cout<<"the ASCII value of "< Date: Sun, 18 Oct 2020 15:18:21 +0545 Subject: [PATCH 655/781] Ceiling and floor value I have import math and used different methods of it to print ceiling and floor value. --- Simple interest floor and ceiling value | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Simple interest floor and ceiling value diff --git a/Simple interest floor and ceiling value b/Simple interest floor and ceiling value new file mode 100644 index 00000000..5d93203d --- /dev/null +++ b/Simple interest floor and ceiling value @@ -0,0 +1,10 @@ +import math +p=3500 +r=3.15 +t=2.5 +interest=((p*t*r)/100) +print("The interest is",round(interest)) +ceil=math.ceil(interest) +print("The celing value is",ceil) +floor=math.floor(interest) +print("The floor value is",floor) From 19e5c499ec2b3cccce56012dd1707c3bea402acd Mon Sep 17 00:00:00 2001 From: Madhusudan Anand <54022235+MadhusudanAnand@users.noreply.github.com> Date: Sun, 18 Oct 2020 15:09:40 +0530 Subject: [PATCH 656/781] Create left rotate array using c left rotate array using c --- left rotate array using c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 left rotate array using c diff --git a/left rotate array using c b/left rotate array using c new file mode 100644 index 00000000..ade267a3 --- /dev/null +++ b/left rotate array using c @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(){ +int x,d,n,i,a[1000000],j; + +scanf("%d",&n); + +scanf("%d",&d); + +for(i=0;i Date: Sun, 18 Oct 2020 16:43:58 +0700 Subject: [PATCH 657/781] Create binary search tree Create binary search tree --- binary search tree | 101 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 binary search tree diff --git a/binary search tree b/binary search tree new file mode 100644 index 00000000..b21004d1 --- /dev/null +++ b/binary search tree @@ -0,0 +1,101 @@ +# Create a node +class Node: + def __init__(self, key): + self.key = key + self.left = None + self.right = None + + +# Inorder traversal +def inorder(root): + if root is not None: + # Traverse left + inorder(root.left) + + # Traverse root + print(str(root.key) + "->", end=' ') + + # Traverse right + inorder(root.right) + + +# Insert a node +def insert(node, key): + + # Return a new node if the tree is empty + if node is None: + return Node(key) + + # Traverse to the right place and insert the node + if key < node.key: + node.left = insert(node.left, key) + else: + node.right = insert(node.right, key) + + return node + + +# Find the inorder successor +def minValueNode(node): + current = node + + # Find the leftmost leaf + while(current.left is not None): + current = current.left + + return current + + +# Deleting a node +def deleteNode(root, key): + + # Return if the tree is empty + if root is None: + return root + + # Find the node to be deleted + if key < root.key: + root.left = deleteNode(root.left, key) + elif(key > root.key): + root.right = deleteNode(root.right, key) + else: + # If the node is with only one child or no child + if root.left is None: + temp = root.right + root = None + return temp + + elif root.right is None: + temp = root.left + root = None + return temp + + # If the node has two children, + # place the inorder successor in position of the node to be deleted + temp = minValueNode(root.right) + + root.key = temp.key + + # Delete the inorder successor + root.right = deleteNode(root.right, temp.key) + + return root + + +root = None +root = insert(root, 8) +root = insert(root, 5) +root = insert(root, 1) +root = insert(root, 6) +root = insert(root, 7) +root = insert(root, 10) +root = insert(root, 14) +root = insert(root, 4) + +print("Inorder traversal: ", end=' ') +inorder(root) + +print("\nDelete 10") +root = deleteNode(root, 10) +print("Inorder traversal: ", end=' ') +inorder(root) From f80e503d348b43e8154cade2cf56bf4bd3208685 Mon Sep 17 00:00:00 2001 From: PA_NQT Date: Sun, 18 Oct 2020 16:45:32 +0700 Subject: [PATCH 658/781] Create valleys counting Create valleys counting --- valleys counting | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 valleys counting diff --git a/valleys counting b/valleys counting new file mode 100644 index 00000000..95496ec1 --- /dev/null +++ b/valleys counting @@ -0,0 +1,36 @@ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(){ + int n,i,u=1,d=-1,sum=0,countv=0,counth=0; + + scanf("%d",&n); + char steps[n]; + + scanf("%s",steps); + + for(i=0;i Date: Sun, 18 Oct 2020 16:50:31 +0700 Subject: [PATCH 659/781] Create java inheritance Create java inheritance --- java inheritance | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 java inheritance diff --git a/java inheritance b/java inheritance new file mode 100644 index 00000000..bc975c2e --- /dev/null +++ b/java inheritance @@ -0,0 +1,19 @@ + +class A +{ + int a=7; + int + b=11; +} +class B extends A +{ + int c=a+b; +} +class add +{ + public static void main(String[] args) + { + B obj1 = new B(); + System.out.println("sum is " + obj1.c); + } +} From 4baa184d9fe78a52fbc1de6ed9722d7bb7ae7276 Mon Sep 17 00:00:00 2001 From: harshahvg7 <72880742+harshahvg7@users.noreply.github.com> Date: Sun, 18 Oct 2020 15:22:44 +0530 Subject: [PATCH 660/781] Length.md Optimised code of length of string in a quick way --- Length of string.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 Length of string.py diff --git a/Length of string.py b/Length of string.py new file mode 100644 index 00000000..71e761a6 --- /dev/null +++ b/Length of string.py @@ -0,0 +1,10 @@ +#Python program to demonstrate the use of +# len() method + +# Length of below string is 5 +string = "geeks" +print(len(string)) + +# Length of below string is 15 +string = "geeks for geeks" +print(len(string)) From c0c4ccde1e005948d6b270ec1f33fd65c8383a7a Mon Sep 17 00:00:00 2001 From: babyshreeshma <41548553+babyshreeshma@users.noreply.github.com> Date: Sun, 18 Oct 2020 15:58:48 +0530 Subject: [PATCH 661/781] Create Dining Philosopher Problem Dining Philosopher Problem implemented with C language --- Dining Philosopher Problem | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 Dining Philosopher Problem diff --git a/Dining Philosopher Problem b/Dining Philosopher Problem new file mode 100644 index 00000000..f281763a --- /dev/null +++ b/Dining Philosopher Problem @@ -0,0 +1,95 @@ +#include +#define n 5 +int compltedPhilo = 0,i; +struct fork +{ + int taken; + } +ForkAvil[n]; + +struct philosp +{ + int left; + int right; +} +Philostatus[n]; + +void goForDinner(int philID) +{ + if(Philostatus[philID].left==10 && Philostatus[philID].right==10) + printf("Philosopher %d completed his dinner\n",philID+1); + + else if(Philostatus[philID].left==1 && Philostatus[philID].right==1) +{ + + printf("Philosopher %d completed his dinner\n",philID+1); + + Philostatus[philID].left = Philostatus[philID].right = 10; + int otherFork = philID-1; + + if(otherFork== -1) + otherFork=(n-1); + + ForkAvil[philID].taken = ForkAvil[otherFork].taken = 0; + printf("Philosopher %d released fork %d and fork %d\n",philID+1,philID+1,otherFork+1); + compltedPhilo++; + } + else if(Philostatus[philID].left==1 && Philostatus[philID].right==0) + { + if(philID==(n-1)){ + if(ForkAvil[philID].taken==0){ + ForkAvil[philID].taken = Philostatus[philID].right = 1; + printf("Fork %d taken by philosopher %d\n",philID+1,philID+1); + } + else + { + printf("Philosopher %d is waiting for fork %d\n",philID+1,philID+1); + } + } + else + { + int dupphilID = philID; + philID-=1; + + if(philID== -1) + philID=(n-1); + + if(ForkAvil[philID].taken == 0){ + ForkAvil[philID].taken = Philostatus[dupphilID].right = 1; + printf("Fork %d taken by Philosopher %d\n",philID+1,dupphilID+1); + }else{ + printf("Philosopher %d is waiting for Fork %d\n",dupphilID+1,philID+1); + } + } + } + else if(Philostatus[philID].left==0){ + if(philID==(n-1)){ + if(ForkAvil[philID-1].taken==0){ + ForkAvil[philID-1].taken = Philostatus[philID].left = 1; + printf("Fork %d taken by philosopher %d\n",philID,philID+1); + }else{ + printf("Philosopher %d is waiting for fork %d\n",philID+1,philID); + } + }else{ + if(ForkAvil[philID].taken == 0){ + ForkAvil[philID].taken = Philostatus[philID].left = 1; + printf("Fork %d taken by Philosopher %d\n",philID+1,philID+1); + }else{ + printf("Philosopher %d is waiting for Fork %d\n",philID+1,philID+1); + } + } + }else{} +} + +int main() +{ + for(i=0;i Date: Sun, 18 Oct 2020 16:04:41 +0530 Subject: [PATCH 662/781] Create No of nodes in BST C++ program to find no of nodes in BST --- No of nodes in BST | 66 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 No of nodes in BST diff --git a/No of nodes in BST b/No of nodes in BST new file mode 100644 index 00000000..7080329d --- /dev/null +++ b/No of nodes in BST @@ -0,0 +1,66 @@ +#include +using namespace std; + +int n=1; + +struct node +{ + int data; + node* left; + node* right; +}; + +struct node* getNode(int data) +{ + node* newNode=new node(); + newNode->data=data; + newNode->left=NULL; + newNode->right=NULL; + return newNode; +} + +struct node* Insert(struct node* root, int data) +{ + if (root == NULL) + return getNode(data); + + if (data < root->data) + root->left = Insert(root->left, data); + else if (data > root->data) + root->right = Insert(root->right, data); + + return root; +} + + +int CountNodes(node*root) +{ + if(root==NULL) + return 0; + if(root->left!=NULL) + { + n=n+1; + n=CountNodes(root->left); + } + if(root->right!=NULL) + { + n=n+1; + n=CountNodes(root->right); + } + return n; +} + +int main() +{ + node* root=NULL; + root=Insert(root,3); + Insert(root,4); + Insert(root,2); + Insert(root,5); + Insert(root,1); + + cout<<"Total No. of Nodes in the BST = "< Date: Sun, 18 Oct 2020 16:09:48 +0530 Subject: [PATCH 663/781] Create Deletion of BST C++ Program for Deletion of BST(Binary Search Tree) --- Deletion of BST | 153 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 Deletion of BST diff --git a/Deletion of BST b/Deletion of BST new file mode 100644 index 00000000..32c6ca4d --- /dev/null +++ b/Deletion of BST @@ -0,0 +1,153 @@ +#include +using namespace std; + +bool c=false; + +struct node +{ + int data; + node* left; + node* right; +}; + +struct node* getNode(int data) +{ + node* newNode=new node(); + newNode->data=data; + newNode->left=NULL; + newNode->right=NULL; + return newNode; +} + +void inorder(struct node* root) +{ + if (root != NULL) + { + inorder(root->left); + cout<data<<" "; + inorder(root->right); + } +} + +node* findMin(node*root) +{ + while(root->left!=NULL) + { + root=root->left; + } + return root; +} + +struct node* Insert(struct node* root, int data) +{ + if (root == NULL) + return getNode(data); + + if (data < root->data) + root->left = Insert(root->left, data); + else if (data > root->data) + root->right = Insert(root->right, data); + + return root; +} + +bool Search(node*root,int value) +{ + if(root==NULL) + return false; + else if(root->data == value) + { + return true; + } + else if(value < root-> data) + Search(root->left,value); + else if(value > root->data) + Search(root->right,value); +} + + +node* Delete( node* root,int value) +{ + c=Search(root,value); + if(root==NULL) + return root; + else if(value< root->data) + { + root->left= Delete(root->left,value); + } + else if(value> root->data) + { + root->right= Delete(root->right,value); + } + + // Node deletion + else + { + //case 1: Leaf Node + if(root->left==NULL&&root->right==NULL) + { + delete root; + root=NULL; + return root; + } + //case 2: one child + else if(root->left==NULL) + { + struct node* temp=root; + root=root->right; + delete temp; + return root; + } + else if(root->right==NULL) + { + struct node* temp=root; + root=root->left; + delete temp; + return root; + } + //case 3: 2 child + else + { + struct node*temp=findMin(root->right); + root->data=temp->data; + root->right=Delete(root->right,temp->data); + } + } + return root; + +} + + +int main() +{ + node* root=NULL; + root=Insert(root,20); + Insert(root,15); + Insert(root,25); + Insert(root,18); + Insert(root,10); + Insert(root,16); + Insert(root,19); + Insert(root,17); + + cout<<"Before Deletion: "< Date: Sun, 18 Oct 2020 16:12:37 +0530 Subject: [PATCH 664/781] Create Graph in Data Structure C++ Program for Implementing Graph Data Structure --- Graph in Data Structure | 153 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 Graph in Data Structure diff --git a/Graph in Data Structure b/Graph in Data Structure new file mode 100644 index 00000000..2bf4a9c4 --- /dev/null +++ b/Graph in Data Structure @@ -0,0 +1,153 @@ +#include + +#include + +using namespace std; + +#define MAX 20 + +/* + + * Adjacency Matrix Class + + */ + +class AdjacencyMatrix + +{ + + private: + + int n; + + int **adj; + + bool *visited; + + public: + + AdjacencyMatrix(int n) + + { + + this->n = n; + + visited = new bool [n]; + + adj = new int* [n]; + + for (int i = 0; i < n; i++) + + { + + adj[i] = new int [n]; + + for(int j = 0; j < n; j++) + + { + + adj[i][j] = 0; + + } + + } + + } + + /* + + * Adding Edge to Graph + + */ + + void add_edge(int origin, int destin) + + { + + if( origin > n || destin > n || origin < 0 || destin < 0) + + { + + cout<<"Invalid edge!\n"; + + } + + else + + { + + adj[origin - 1][destin - 1] = 1; + + } + + } + + /* + + * Print the graph + + */ + + void display() + + { + + int i,j; + + for(i = 0;i < n;i++) + + { + + for(j = 0; j < n; j++) + + cout<>nodes; + + AdjacencyMatrix am(nodes); + + max_edges = nodes * (nodes - 1); + + for (int i = 0; i < max_edges; i++) + + { + + cout<<"Enter edge (-1 -1 to exit): "; + + cin>>origin>>destin; + + if((origin == -1) && (destin == -1)) + + break; + + am.add_edge(origin, destin); + + } + + am.display(); + + return 0; + +} From dee20fb86508804d08bedbc07680292c126b41d3 Mon Sep 17 00:00:00 2001 From: Shubham Kumar Sharma <53513799+shubhamkumarcs@users.noreply.github.com> Date: Sun, 18 Oct 2020 16:41:04 +0530 Subject: [PATCH 665/781] Create Program to find the sum of array elements --- Program to find the sum of array elements | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Program to find the sum of array elements diff --git a/Program to find the sum of array elements b/Program to find the sum of array elements new file mode 100644 index 00000000..b42c2100 --- /dev/null +++ b/Program to find the sum of array elements @@ -0,0 +1,20 @@ +import java.util.Scanner; +public class AdditionOfElements { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.println("Enter the no. of elements you want to add in array : "); + int n= sc.nextInt(); + int arr[] = new int[n]; + System.out.println("Enter the numbers : "); + for(int i=0;i Date: Sun, 18 Oct 2020 17:02:09 +0530 Subject: [PATCH 666/781] Update C++ minor changes --- Fibonnaci Series/C++ | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Fibonnaci Series/C++ b/Fibonnaci Series/C++ index 9c82a47a..f7cb6b4d 100644 --- a/Fibonnaci Series/C++ +++ b/Fibonnaci Series/C++ @@ -27,7 +27,7 @@ int main() t1 = t2; t2 = nextTerm; - cout << nextTerm << " "; + cout << nextTerm is << " "; } return 0; } From bfd604617055b6c62454de4537d381de4a769504 Mon Sep 17 00:00:00 2001 From: Sarthak Agarwal <48758971+shadoww19@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:03:26 +0530 Subject: [PATCH 667/781] Update C_Program Factorial minor changes --- C_Program Factorial | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C_Program Factorial b/C_Program Factorial index cf5490fd..23eab865 100644 --- a/C_Program Factorial +++ b/C_Program Factorial @@ -4,7 +4,7 @@ int main() { int c, n, f = 1; - printf("Enter a number to calculate its factorial\n"); + printf("Enter number to calculate its factorial\n"); scanf("%d", &n); for (c = 1; c <= n; c++) f = f * c; From 5e17181ca446cb3bfb333e14c7c892a71ddbd0d3 Mon Sep 17 00:00:00 2001 From: Khushi Jain <56038894+KhushiJain2810@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:14:35 +0530 Subject: [PATCH 668/781] Heap Sort C++ Program --- Heap_Sort | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Heap_Sort diff --git a/Heap_Sort b/Heap_Sort new file mode 100644 index 00000000..5a99865d --- /dev/null +++ b/Heap_Sort @@ -0,0 +1,59 @@ +// C++ program for implementation of Heap Sort + +// To heapify a subtree rooted with node i which is +// an index in arr[]. n is size of heap + +#include + +using namespace std; + +void heapify(int array[], int numOfElements, int current) +{ + int leftChild = 2 * current + 1; + int rightChild = 2 * current + 2; + int largest = current; + // If left child is larger than root + if(leftChild < numOfElements && array[leftChild] > array[current]) + largest = leftChild; + // If right child is larger than root + if(rightChild < numOfElements && array[rightChild] > array[largest]) + largest = rightChild; + // If largest element is not root + if(largest != current) + { + swap(array[largest], array[current]); + // Recursively heapify the subtree + heapify(array, numOfElements, largest); + } +} + +// Function for heap sort +void heapSort(int *array, int numOfElements) +{ + // heapify the array + for(int i = numOfElements/2 - 1; i >= 0; i--) + heapify(array, numOfElements, i); + + for(int i = numOfElements-1; i > 0; i--) + { + // swap first and last + swap(array[0], array[i]); + heapify(array, i, 0); } +} + +//Function printing the array +void printArray(int array[], int numOfElements) +{ + for (int i = 0; i < numOfElements; ++i) + cout << array[i] << " "; + cout << "\n"; +} + +int main() +{ + int array[] = { 12, 11, 13, 5, 6, 1, 7 }; + int numOfElements = sizeof(array) / sizeof(array[0]); + heapSort(array, numOfElements); + printArray(array, numOfElements); + return 0; +} From 12c1cd837362fb3740f261566ae0e9431d677f3e Mon Sep 17 00:00:00 2001 From: shaonidutta <65228179+shaonidutta@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:29:37 +0530 Subject: [PATCH 669/781] Create Binary to decimal using python Code to convert binary to decimal in python with user input --- Binary to decimal using python | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Binary to decimal using python diff --git a/Binary to decimal using python b/Binary to decimal using python new file mode 100644 index 00000000..f725730f --- /dev/null +++ b/Binary to decimal using python @@ -0,0 +1,9 @@ +# convert binary to decimal +num = list(input('Enter a binary number: ')) +result = 0 + +for k in range(len(num)): + digit=num.pop() + if digit == '1': + result = result + pow(2,k) +print('The decimal value is',result) From 659f7beb5135f49f8e2a02c67b4df5adef229831 Mon Sep 17 00:00:00 2001 From: Anjali401 <68481082+Anjali401@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:30:44 +0530 Subject: [PATCH 670/781] Create To-Reverse-the-array-in-java code to reverse an array using java --- To-Reverse-the-array-in-java | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 To-Reverse-the-array-in-java diff --git a/To-Reverse-the-array-in-java b/To-Reverse-the-array-in-java new file mode 100644 index 00000000..4bda7b15 --- /dev/null +++ b/To-Reverse-the-array-in-java @@ -0,0 +1,23 @@ +import java.util.Scanner; +class ReverseNumberWhile +{ + public static void main(String args[]) + { + int num=0; + int reversenum =0; + System.out.println("Input your number and press enter: "); + + Scanner in = new Scanner(System.in); + + num = in.nextInt(); + + while( num != 0 ) + { + reversenum = reversenum * 10; + reversenum = reversenum + num%10; + num = num/10; + } + + System.out.println("Reverse of input number is: "+reversenum); + } +} From 0185b3de02d96fd1a086810fa95b57c0810f9143 Mon Sep 17 00:00:00 2001 From: Banjade17 <57613370+Banjade17@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:47:00 +0545 Subject: [PATCH 671/781] Find any word form text There is long paragraph and if you want to find some word then you can enter and find their position --- Finding word in long text | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Finding word in long text diff --git a/Finding word in long text b/Finding word in long text new file mode 100644 index 00000000..e3437ec8 --- /dev/null +++ b/Finding word in long text @@ -0,0 +1,4 @@ +text='''Python is an interpreted, high-level and general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects Python is dynamically typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly, procedural), object-oriented, and functional programming. Python is often described as a "batteries included" language due to its comprehensive standard library.Python was created in the late 1980s as a successor to the ABC language. Python 2.0, released in 2000, introduced features like list comprehensions and a garbage collection system with reference counting.Python 3.0, released in 2008, was a major revision of the language that is not completely backward-compatible, and much P''' +a=input("Enter text to search ") +print(text.find(a)) +print(a.lower() in text.lower()) From 982f0d8d32397a230545542e0aabca605fd44e04 Mon Sep 17 00:00:00 2001 From: shaonidutta <65228179+shaonidutta@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:46:10 +0530 Subject: [PATCH 672/781] Create Convert Decimal to Binary, Octal and Hexadecimal using python code to convert decimal to binary, octal and hexadecimal using python taking user input --- ...l to Binary, Octal and Hexadecimal using python | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Convert Decimal to Binary, Octal and Hexadecimal using python diff --git a/Convert Decimal to Binary, Octal and Hexadecimal using python b/Convert Decimal to Binary, Octal and Hexadecimal using python new file mode 100644 index 00000000..a573dbd3 --- /dev/null +++ b/Convert Decimal to Binary, Octal and Hexadecimal using python @@ -0,0 +1,14 @@ +#convert decimal to binary,octal, hexadecimal +#taking user input + +decimal = int(input("Enter Decimal Value: \n")) +convert = int(input("Convert into: [1] Binary, [2] Octal, [3] Hexadecimal: ")) + +if convert == 1: + print("Binary valure is \n",bin(decimal)) +elif convert == 2: + print("Octal valure is \n",oct(decimal)) +elif convert == 3: + print("Hexadecimal Value is \n",hex(decimal)) +else: + print("Invalid Input") From ed11d600b6cd32abdf4fcb9057e285348560330d Mon Sep 17 00:00:00 2001 From: hack1920 <64920053+hack1920@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:50:46 +0530 Subject: [PATCH 673/781] Create Program to find largest element in array using c C program to find largest number in array. --- ...m to find largest element in array using c | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Program to find largest element in array using c diff --git a/Program to find largest element in array using c b/Program to find largest element in array using c new file mode 100644 index 00000000..98a77125 --- /dev/null +++ b/Program to find largest element in array using c @@ -0,0 +1,22 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + // storing the largest number to arr[0] + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From 2e8bcf579545b34848eb5c1c09c97925dca4cab8 Mon Sep 17 00:00:00 2001 From: hack1920 <64920053+hack1920@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:54:01 +0530 Subject: [PATCH 674/781] Create Program to print prime numbers in given range using c C program to find prime number between two given numbers. --- ...print prime numbers in given range using c | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Program to print prime numbers in given range using c diff --git a/Program to print prime numbers in given range using c b/Program to print prime numbers in given range using c new file mode 100644 index 00000000..c64ec6b2 --- /dev/null +++ b/Program to print prime numbers in given range using c @@ -0,0 +1,77 @@ + #include + + #include + + + + void main() + + { + + int num1, num2, i, j, flag, temp, count = 0; + + + + printf("Enter the value of num1 and num2 \n"); + + scanf("%d %d", &num1, &num2); + + if (num2 < 2) + + { + + printf("There are no primes upto %d\n", num2); + + exit(0); + + } + + printf("Prime numbers are \n"); + + temp = num1; + + if ( num1 % 2 == 0) + + { + + num1++; + + } + + for (i = num1; i <= num2; i = i + 2) + + { + + flag = 0; + + for (j = 2; j <= i / 2; j++) + + { + + if ((i % j) == 0) + + { + + flag = 1; + + break; + + } + + } + + if (flag == 0) + + { + + printf("%d\n", i); + + count++; + + } + + } + + printf("Number of primes between %d & %d = %d\n", temp, num2, count); + + } From a56f1f8f3e86c10a12465d0a6c524934cd76f3f8 Mon Sep 17 00:00:00 2001 From: hack1920 <64920053+hack1920@users.noreply.github.com> Date: Sun, 18 Oct 2020 17:57:54 +0530 Subject: [PATCH 675/781] Create Program to find lenght of a string using python Python program to calculate length of a String without using len() function. --- Program to find lenght of a string using python | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Program to find lenght of a string using python diff --git a/Program to find lenght of a string using python b/Program to find lenght of a string using python new file mode 100644 index 00000000..301fe632 --- /dev/null +++ b/Program to find lenght of a string using python @@ -0,0 +1,7 @@ +str = input("Enter a string: ") + +# counter variable to count the character in a string +counter = 0 +for s in str: + counter = counter+1 +print("Length of the input string is:", counter) From a37f56824c7d0232b437931aea67559bc30bc240 Mon Sep 17 00:00:00 2001 From: Harish Chavan Date: Sun, 18 Oct 2020 17:59:15 +0530 Subject: [PATCH 676/781] Create Multiplicative Inverse using Extended Euclidean Algorithm This code will give you multiplicative inverse of any number on any complex plane denoted and **Zq** here **q** is any number. --- ...Inverse using Extended Euclidean Algorithm | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Multiplicative Inverse using Extended Euclidean Algorithm diff --git a/Multiplicative Inverse using Extended Euclidean Algorithm b/Multiplicative Inverse using Extended Euclidean Algorithm new file mode 100644 index 00000000..b6b5f8e7 --- /dev/null +++ b/Multiplicative Inverse using Extended Euclidean Algorithm @@ -0,0 +1,44 @@ +def extended_euclidean(p, q): + """(int, int) -> list + + Return the list : [greatest_common_divisor, multiplicative_inverse(1), multiplicative_inverse (if multiplicative_inverse(1) is negative)] + + >>> extended_euclidean(10, 23) + [1, [7]] + + >>> extended_euclidean(11, 2) + [1, [-5, -3]] + """ + #Initalizing table of Extended Euclidean algorithm + table = {'quotent':0, 'remainder_temp1':max(p, q), 'remainder_temp2':min(p, q), 'remainder':0, 'multiplicative_inverse1':0, 'multiplicative_inverse2':1, 'multiplicative_inverse':0} + + while(True): + try: #Break condition for loop + table['remainder'] = table['remainder_temp1'] % table['remainder_temp2'] + if table['remainder'] < 0: + break + except: + break + #From here we calculate value of q + table['quotent'] = (table['remainder_temp1'] - table['remainder'])/table['remainder_temp2'] + + table['multiplicative_inverse'] = table['multiplicative_inverse1'] - table['multiplicative_inverse2'] * table['quotent'] + + #From here we shift values about column to right + table['remainder_temp1'] = table['remainder_temp2'] + table['remainder_temp2'] = table['remainder'] + + table['multiplicative_inverse1'] = table['multiplicative_inverse2'] + table['multiplicative_inverse2'] = table['multiplicative_inverse'] + + if table['multiplicative_inverse1'] > 0: #Returning [greatest_common_divisor, [multiplicative inverse(s)]] + return [int(table['remainder_temp1']), [int(table['multiplicative_inverse1'])]] + return [int(table['remainder_temp1']), [int(table['multiplicative_inverse1']), q + int(table['multiplicative_inverse1'])]] + +if __name__=='__main__': + p = int(input("ENter p: ")) + q = int(input("ENter q: ")) + + result = extended_euclidean(p, q) + + print(result[1]) From 31d054a7a69fa92956c25e1fb896cf2d2b0c772b Mon Sep 17 00:00:00 2001 From: hack1920 <64920053+hack1920@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:00:57 +0530 Subject: [PATCH 677/781] Create Program to count sum of all numbers in array using c C program to calculate sum of all element in array. --- ... count sum of all numbers in array using c | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Program to count sum of all numbers in array using c diff --git a/Program to count sum of all numbers in array using c b/Program to count sum of all numbers in array using c new file mode 100644 index 00000000..60e55679 --- /dev/null +++ b/Program to count sum of all numbers in array using c @@ -0,0 +1,26 @@ +#include + + +int main() +{ + int a[1000],i,n,sum=0; + + printf("Enter size of the array : "); + scanf("%d",&n); + + printf("Enter elements in array : "); + for(i=0; i Date: Sun, 18 Oct 2020 15:48:38 +0300 Subject: [PATCH 678/781] Find length of a string Find length of a string --- find-lenght-of-a-string.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 find-lenght-of-a-string.py diff --git a/find-lenght-of-a-string.py b/find-lenght-of-a-string.py new file mode 100644 index 00000000..7c21b6e9 --- /dev/null +++ b/find-lenght-of-a-string.py @@ -0,0 +1,3 @@ +string = input("Give me a string:") + +print(len(string)) From 205ddb45b6d9954a252b7661f16567b611f5f209 Mon Sep 17 00:00:00 2001 From: Sarthak Agarwal <48758971+shadoww19@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:19:56 +0530 Subject: [PATCH 679/781] Update ProgramToConvertBinaryToDecimalNumber.cpp minor changes --- .../ProgramToConvertBinaryToDecimalNumber.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp index c1a4a0b8..d3691328 100644 --- a/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp +++ b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp @@ -28,7 +28,7 @@ int binaryToDecimal(int n) int main() { int num; - cout<<"Enter the binary no. : "; + cout<<"Enter binary no. : "; cin>>num; cout << binaryToDecimal(num) << endl; From 4e9b8c09fd300a0c2c549bd1c9e1137e9cfb4394 Mon Sep 17 00:00:00 2001 From: Sarthak Agarwal <48758971+shadoww19@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:22:52 +0530 Subject: [PATCH 680/781] Update C String Initialization minor changes --- C String Initialization | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/C String Initialization b/C String Initialization index 369aa566..823f756b 100644 --- a/C String Initialization +++ b/C String Initialization @@ -3,6 +3,6 @@ char name[] = "Tutorial Gateway"; // Declare String with Size char name[50] = "Tutorial Gateway"; // Declare String of Characters -char name[] = {'T', 'u', 't', 'o', 'r', 'i', 'a', 'l', 'G', 'a', 't', 'e', 'w', 'a', 'y', '\0'}; +char name[] = {'T', 'u', 't', 'o', 'r', 'i', 'a', 'l', 'G', 'a', 't', 'e', 'w', 'a', 'Y', '\0'}; -char name[16] = {'T', 'u', 't', 'o', 'r', 'i', 'a', 'l',' G', 'a', 't', 'e', 'w', 'a', 'y', '\0'}; +char name[16] = {'T', 'u', 't', 'o', 'r', 'i', 'a', 'l',' G', 'a', 't', 'e', 'w', 'a', 'Y', '\0'}; From 86e1e35caa432cf4a22e03ce713e5bb584b586dc Mon Sep 17 00:00:00 2001 From: pr4n4vs <52619463+pr4n4vs@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:30:41 +0530 Subject: [PATCH 681/781] Create Program to print Fibonnaci Series using python --- ...ram to print Fibonnaci Series using python | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Program to print Fibonnaci Series using python diff --git a/Program to print Fibonnaci Series using python b/Program to print Fibonnaci Series using python new file mode 100644 index 00000000..17e24228 --- /dev/null +++ b/Program to print Fibonnaci Series using python @@ -0,0 +1,21 @@ +nterms = int(input("How many terms? ")) + +# first two terms +n1, n2 = 0, 1 +count = 0 + +# check if the number of terms is valid +if nterms <= 0: + print("Please enter a positive integer") +elif nterms == 1: + print("Fibonacci sequence upto",nterms,":") + print(n1) +else: + print("Fibonacci sequence:") + while count < nterms: + print(n1) + nth = n1 + n2 + # update values + n1 = n2 + n2 = nth + count += 1 From 717e14380d1c5319b3b53926e9d57b0d382d92a5 Mon Sep 17 00:00:00 2001 From: Khushi Jain <56038894+KhushiJain2810@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:34:35 +0530 Subject: [PATCH 682/781] C++ Program for Linked List Insert a node at any Position Delete a node at any Position Reverse a Linked List Swap any two nodes in a Linked List --- C++ Program for Linked List | 199 ++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 C++ Program for Linked List diff --git a/C++ Program for Linked List b/C++ Program for Linked List new file mode 100644 index 00000000..de5c40fc --- /dev/null +++ b/C++ Program for Linked List @@ -0,0 +1,199 @@ +#include + +using namespace std; + +class node +{ +public: + int data; + node* next; +}; + +node* newNode(int data) +{ + node* new_node = new node(); + new_node->data = data; + new_node->next = NULL; + return new_node; +} + +void append(node** head_ref, int data) +{ + node* temp = *head_ref; + if(*head_ref == NULL) + *head_ref = newNode(data); + else + { + while(temp->next != NULL) + temp = temp->next; + temp->next = newNode(data); + } +} + +void append_at_start(node** head_ref, int data) +{ + node* temp = *head_ref; + node* newnode = newNode(data); + *head_ref = newnode; + newnode->next = temp; +} + +void append_at_position(node** head_ref, int pos, int data) +{ + int i = 0; + node *temp = *head_ref, *newnode = newNode(data);; + if(*head_ref == NULL) + { + *head_ref = newnode; + return; + } + if(pos == 1) + { + newnode->next = *head_ref; + *head_ref = newnode; + return; + } + while(i < pos-2 && temp != NULL) + { + temp = temp->next; + i++; + } + if(temp == NULL) + { + cout << "Cann't Add, Invalid Position\n"; + return; + } + newnode->next = temp->next; + temp->next = newnode; +} + +void popStart(node** head_ref) +{ + if(*head_ref == NULL) + { + cout << "Empty List\n"; + return; + } + *head_ref = (*head_ref)->next; +} + +void popLast(node** head_ref) +{ + node* temp = *head_ref; + if(*head_ref == NULL) + { + cout << "Empty List\n"; + return; + } + if(temp->next == NULL) + { + *head_ref = NULL; + return; + } + while(temp->next->next != NULL) + temp = temp->next; + temp->next = NULL; +} + +void popPosition(node** head_ref, int pos) +{ + int i = 0; + node* temp = *head_ref; + if(*head_ref == NULL) + { + cout << "Empty List\n"; + return; + } + if(pos == 1) + { + *head_ref = (*head_ref)->next; + return; + } + while(i < pos-2 && temp != NULL) + { + temp = temp->next; + i++; + } + if(temp == NULL || temp->next == NULL) + { + cout << "Cann't Pop, Invalid Position\n"; + return; + } + temp->next = temp->next->next; +} + +void reverse_list(node** head_ref) +{ + node *current = *head_ref, *prev = NULL, *after = NULL; + if(*head_ref == NULL) + return; + while(current != NULL) + { + after = current->next; + current->next = prev; + prev = current; + current = after; + } + *head_ref = prev; +} + +void swap(node** head_ref, int x, int y) +{ + node *prev1 = NULL, *prev2 = NULL, *curr1 = *head_ref, *curr2 = *head_ref; + if(x == y) + return; + while(curr1 && curr1->data != x) + { + prev1 = curr1; + curr1 = curr1->next; + } + while(curr2 && curr2->data != y) + { + prev2 = curr2; + curr2 = curr2->next; + } + if(curr1 == NULL || curr2 == NULL) + return; + if(prev1 != NULL) + prev1->next = curr2; + else + *head_ref = curr2; + if(prev2 != NULL) + prev2->next = curr1; + else + *head_ref = curr1; + node* temp = curr1->next; + curr1->next = curr2->next; + curr2->next = temp; +} + +void print(node* head) +{ + while(head != NULL) + { + cout << head->data << " "; + head = head->next; + } + cout << endl; +} + +int main() +{ + node* head = NULL; + append(&head, 6); + append(&head, 7); + append(&head, 8); + append(&head, 9); + append(&head, 10); + append(&head, 11); + append_at_start(&head, 1); + append_at_position(&head, 4, 10); + popStart(&head); + popLast(&head); + popPosition(&head, 6); + print(head); + reverse_list(&head); + swap(&head, 7, 11); + print(head); + return 0; +} From 3dee2caa750567f5f8b08096dca369318f85b279 Mon Sep 17 00:00:00 2001 From: pr4n4vs <52619463+pr4n4vs@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:35:12 +0530 Subject: [PATCH 683/781] Create Program to find power of any number using c C program to find power of any number using recursion --- Program to find power of any number using c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Program to find power of any number using c diff --git a/Program to find power of any number using c b/Program to find power of any number using c new file mode 100644 index 00000000..cd8ae7c1 --- /dev/null +++ b/Program to find power of any number using c @@ -0,0 +1,19 @@ +#include +int power(int n1, int n2); +int main() { + int base, a, result; + printf("Enter base number: "); + scanf("%d", &base); + printf("Enter power number(positive integer): "); + scanf("%d", &a); + result = power(base, a); + printf("%d^%d = %d", base, a, result); + return 0; +} + +int power(int base, int a) { + if (a != 0) + return (base * power(base, a - 1)); + else + return 1; +} From 99fe5b189395ef9053653e463bd794b5eda0b28a Mon Sep 17 00:00:00 2001 From: technicalreju <73017717+technicalreju@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:37:01 +0530 Subject: [PATCH 684/781] Create Print leap year in a given year range Improved program of leap year in given range --- Print leap year in a given year range | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Print leap year in a given year range diff --git a/Print leap year in a given year range b/Print leap year in a given year range new file mode 100644 index 00000000..5dfe31bb --- /dev/null +++ b/Print leap year in a given year range @@ -0,0 +1,27 @@ + class DOT +{ + +static int calNum(int year) +{ + return (year / 4) - (year / 100) + + (year / 400); +} + + +static void leapNum(int l, int r) +{ + l--; + int num1 = calNum(r); + int num2 = calNum(l); + System.out.print(num1 - num2 +"\n"); +} + +public static void main(String[] args) +{ + int l1 = 1, r1 = 400; + leapNum(l1, r1); + + int l2 = 400, r2 = 2000; + leapNum(l2, r2); +} +} From b2a9195f2e6bca01db8dac854ea9dcb9c6d2e8b3 Mon Sep 17 00:00:00 2001 From: pr4n4vs <52619463+pr4n4vs@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:37:55 +0530 Subject: [PATCH 685/781] Create Program to find largest element in array using c++ --- ...to find largest element in array using c++ | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Program to find largest element in array using c++ diff --git a/Program to find largest element in array using c++ b/Program to find largest element in array using c++ new file mode 100644 index 00000000..1e909f66 --- /dev/null +++ b/Program to find largest element in array using c++ @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main() +{ + int i, n; + float arr[100]; + + cout << "Enter total number of elements(1 to 100): "; + cin >> n; + cout << endl; + + // Store number entered by the user + for(i = 0; i < n; ++i) + { + cout << "Enter Number " << i + 1 << " : "; + cin >> arr[i]; + } + + // Loop to store largest number to arr[0] + for(i = 1;i < n; ++i) + { + // Change < to > if you want to find the smallest element + if(arr[0] < arr[i]) + arr[0] = arr[i]; + } + cout << "Largest element = " << arr[0]; + + return 0; +} From 5383d0c0975bc7bc6f62d57585a3438e675cb58f Mon Sep 17 00:00:00 2001 From: pr4n4vs <52619463+pr4n4vs@users.noreply.github.com> Date: Sun, 18 Oct 2020 18:45:35 +0530 Subject: [PATCH 686/781] Create Program to convert binary to decimal number using c --- ...o convert binary to decimal number using c | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Program to convert binary to decimal number using c diff --git a/Program to convert binary to decimal number using c b/Program to convert binary to decimal number using c new file mode 100644 index 00000000..6b73a730 --- /dev/null +++ b/Program to convert binary to decimal number using c @@ -0,0 +1,21 @@ +#include +#include +int convert(long long n); +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +int convert(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From 5068b636d413d29db81950a23f4d0bb32ce21795 Mon Sep 17 00:00:00 2001 From: Shubzedm007 <72625065+Shubzedm007@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:27:30 +0530 Subject: [PATCH 687/781] Create Length of a String Optimized code for finding length of a string. --- Length of a String | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Length of a String diff --git a/Length of a String b/Length of a String new file mode 100644 index 00000000..5036b276 --- /dev/null +++ b/Length of a String @@ -0,0 +1,13 @@ + #include + #include + using namespace std; + int main () + { + char str[50]; + int len; + cout << "Enter a string : "; + gets(str); + len = strlen(str); + cout << "Length of the string is : " << len; + return 0; + } From 77c4a005991c5eef5486b52300a849f574263ac0 Mon Sep 17 00:00:00 2001 From: aaryaab Date: Sun, 18 Oct 2020 19:30:13 +0530 Subject: [PATCH 688/781] Create Invisibility using Python --- Invisibility using Python | 71 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Invisibility using Python diff --git a/Invisibility using Python b/Invisibility using Python new file mode 100644 index 00000000..f2f3e73a --- /dev/null +++ b/Invisibility using Python @@ -0,0 +1,71 @@ +import cv2 +import time +import numpy as np + +#recording video from webcam + +camera=cv2.VideoCapture(0) +#For final outcome +frame_width = int(camera.get(3)) +frame_height = int(camera.get(4)) + +out =cv2.VideoWriter('output.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 10, (frame_width,frame_height)) +#time for webcamera to sleep(5s) before it works + +time.sleep(5) +count=0 +background=0 + +#capturing background which will work as invisible cloak + +for i in range(60): + ret,background=camera.read() + +background =np.flip(background,axis=1) + +# reading the frame from camera, till it is open + +while(camera.isOpened()): + ret,img=camera.read() + if not ret: + break + count+=1 + # laterally flipping the image + img=np.flip(img,axis=1) + # converting RGB to HSV + hsv=cv2.cvtColor(img,cv2.COLOR_BGR2HSV) + # Generating mask to detect Red Color + #Range for Lower Red + lower_red=np.array([0,125,50]) + upper_red=np.array([10,255,255]) + mask1=cv2.inRange(hsv,lower_red,upper_red) + + #Range for Upper Red + lower_red=np.array([170,120,70]) + upper_red=np.array([180,255,255]) + mask2=cv2.inRange(hsv,lower_red,upper_red) + mask1 = mask1+mask2 + + mask1 = cv2.morphologyEx(mask1, cv2.MORPH_OPEN, np.ones((3, 3), np.uint8)) + #Dilate the mask image + mask1=cv2.morphologyEx(mask1,cv2.MORPH_DILATE,np.ones((3,3),np.uint8)) + + # Creating an inverted Mask to segment out the red color from the image + mask2=cv2.bitwise_not(mask1) + + # Segmenting the cloth out of the frame using bitwise and inverted mask + res1=cv2.bitwise_and(img,img,mask=mask2) + + # Creating image showing static background pixels by pixels only for the masked region + res2=cv2.bitwise_and(background,background,mask=mask1) + + #Generating final output + + op=cv2.addWeighted(res1,1,res2,1,0) + out.write(op) + cv2.imshow("ABRACADABRA",op) + cv2.waitKey(1) + +camera.release() +out.release() +cv2.destroyAllWindows() From 930fcabd7e51ee2b8936860ffbec5dee72a8b603 Mon Sep 17 00:00:00 2001 From: Pankaj6198 <72489198+Pankaj6198@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:34:27 +0530 Subject: [PATCH 689/781] Patterns Program to print patterns --- patterns | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) create mode 100644 patterns diff --git a/patterns b/patterns new file mode 100644 index 00000000..8fed681c --- /dev/null +++ b/patterns @@ -0,0 +1,168 @@ +#include +#include + +void upper_tri(); +void lower_tri(); +void right_upperhalf(); +void right_lowerhalf(); +void pyramid(); + +void main() +{int ch; + while(1) +{ printf("\n"); + printf("Choose pattern\n1.Upper triangular\n2.Lower triangular\n3.Right Upper triangular\n4.Right Lower triangular\n5.Pyramid \t\t"); + scanf("%d",&ch); + switch(ch) + { + case 1:upper_tri(); + break; + case 2:lower_tri(); + break; + case 3:right_upperhalf(); + break; + case 4:right_lowerhalf(); + break; + case 5:pyramid(); + default:exit(0); + } +} +} + + +/* upper + +12345 +1234 +123 +12 +1 + +*/ +void upper_tri() +{ int i,j; +printf("\n"); + for(i=5;i>=1;i--)// Rows + { + for(j=1;j<=i;j++)//Col. + { + printf("%d",j); + + } + printf("\n"); + } + +} + + +/* Lower + +1 +12 +123 +1234 +12345 + +*/ +void lower_tri() +{int i,j; +printf("\n"); + for(i=1;i<=5;i++) + { + for(j=1;j<=i;j++) + { + printf("%d",j); + + } + printf("\n"); + } + +} + + +/* right upperhalf + +12345 + 1234 + 123 + 12 + 1 + +*/ +void right_upperhalf() +{ int i,j,k; +printf("\n"); + for(i=5;i>=1;i--)//rows + { + for(j=i;j<5;j++)// Spaces + { + printf(" "); + + } + for(k=1;k<=i;k++)//cols + { + printf("%d",k); + + } + printf("\n"); + } + +} + +/* right lowerhalf + + 1 + 12 + 123 + 1234 +12345 + + +*/ + +void right_lowerhalf() +{int i,j,k; +printf("\n"); + for(i=1;i<=5;i++)//Rows + { + for(j=i;j<5;j++)// Spaces + { + printf(" "); + + } + for(k=1;k<=i;k++)//Cols. + { + printf("%d",k); + + } + printf("\n"); + } +} + +/* Pyramid + * + *** + ***** + ******* + ********* +*/ + +void pyramid() +{int i,j,k,l=40; +printf("\n"); + for(i=1;i<=5;i++)//Rows + { + for(j=1;j<=l-i;j++)// Spaces + { + printf(" "); + + } + for(k=1;k<=2*i-1;k++)//Cols. + { + printf("*"); + + } + printf("\n"); + } + +} From f02ab5af2d299a8d1e2599296e451571046b25c0 Mon Sep 17 00:00:00 2001 From: Harish Chavan Date: Sun, 18 Oct 2020 19:35:20 +0530 Subject: [PATCH 690/781] Informed search algorithm (A* algorithm) Added code in Python for the Informed search algorithm (A* algorithm), which is used in AI basics. --- A star.py | 116 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 A star.py diff --git a/A star.py b/A star.py new file mode 100644 index 00000000..a332af0d --- /dev/null +++ b/A star.py @@ -0,0 +1,116 @@ +class Vertex: + def __init__(self, name, heuristic): + self.name = name + self.heuristic = heuristic + self.neighbors = [] + self.visited = 0 + + def add_neighbor(self, vertex): + if vertex not in self.neighbors: + self.neighbors.append(vertex) + self.neighbors.sort() + +class Graph: + vertices = {} + + def add_vertex(self, vertex): + if isinstance(vertex, Vertex) and vertex.name not in self.vertices: + self.vertices[vertex.name] = vertex + return True + return False + + def add_edge(self, u, v, d): + if u in self.vertices and v in self.vertices: + for key, value in self.vertices.items(): + if key == u: + value.add_neighbor([v, d]) + if key == v: + value.add_neighbor([u, d]) + return True + return False + + def priority(self, fx): + val = [] + for node in fx: + val.append(node[1] + self.vertices[node[0]].heuristic) + return self.vertices[fx[val.index(min(val))][0]] + + def cost(self, node, fx): + for i in fx: + if node.name == i[0]: + return i[1] + + def astar(self, start, end): + ol = [] + cl = [] + gx = 0 + fstr = '' + + ol.append(start) + while ol != []: + fx = [] + temp = ol.pop(0) + temp.visited = 1 + if temp.name == end.name: + cl.append(end.name) + break + cl.append(temp.name) + + for neighbor in temp.neighbors: + if self.vertices[neighbor[0]].visited == 0: + fx.append(neighbor) + ol.append(self.priority(fx)) + gx += self.cost(ol[0], fx) + for node in range(len(cl)): + if node == len(cl) - 1: + fstr += cl[node] + break + fstr += cl[node] + ' --> ' + print('Path to goal state is', fstr, 'with cost of', gx, '.') + +if __name__=='__main__': + graph = Graph() + + #Example 1: + a = Vertex('A', 14) + b = Vertex('B', 12) + c = Vertex('C', 11) + d = Vertex('D', 6) + e = Vertex('E', 4) + f = Vertex('F', 11) + g = Vertex('G', 0) + + graph.add_vertex(a) + graph.add_vertex(b) + graph.add_vertex(c) + graph.add_vertex(d) + graph.add_vertex(e) + graph.add_vertex(f) + graph.add_vertex(g) + + edges = [['AB', 4], ['AC', 3], ['CD', 7], ['CE', 10], ['DE', 2], ['BE', 12], ['BF', 6], ['FG', 16], ['EG', 5]] + for edge in edges: + graph.add_edge(edge[0][:1], edge[0][1:], edge[1]) + + graph.astar(a, g) + print('\n') + + + #Example 2: + p = Vertex('P', 7) + q = Vertex('Q', 6) + r = Vertex('R', 2) + s = Vertex('S', 1) + t = Vertex('T', 0) + + graph.add_vertex(p) + graph.add_vertex(q) + graph.add_vertex(r) + graph.add_vertex(s) + graph.add_vertex(t) + + edges = [['PQ', 1], ['PR', 4], ['QR', 2], ['QS', 5], ['RS', 2], ['QT', 12], ['ST', 3]] + for edge in edges: + graph.add_edge(edge[0][:1], edge[0][1:], edge[1]) + + graph.astar(p, t) \ No newline at end of file From 0fd6f9fe058195a33b813e50c9cc33db5665684b Mon Sep 17 00:00:00 2001 From: Shubzedm007 <72625065+Shubzedm007@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:35:30 +0530 Subject: [PATCH 691/781] Create Program to reverse the array element A C++ Program to reverse the array element --- Program to reverse the array element | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Program to reverse the array element diff --git a/Program to reverse the array element b/Program to reverse the array element new file mode 100644 index 00000000..716c3363 --- /dev/null +++ b/Program to reverse the array element @@ -0,0 +1,30 @@ +#include +using namespace std; + +int main() +{ + int Arr[100],n,temp,i,j; + + cout<<"Enter number of elements you want to insert "; + cin>>n; + + for(i=0;i>Arr[i]; + } + + for(i=0,j=n-1;i Date: Sun, 18 Oct 2020 19:38:34 +0530 Subject: [PATCH 692/781] Binary to Decimal Program Optimized program to convert the binary number to decimal --- Program to Convert Binary to Decimal | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Program to Convert Binary to Decimal diff --git a/Program to Convert Binary to Decimal b/Program to Convert Binary to Decimal new file mode 100644 index 00000000..103a0b7b --- /dev/null +++ b/Program to Convert Binary to Decimal @@ -0,0 +1,33 @@ +#include +using namespace std; + + +int binaryToDecimal(int n) +{ + int num = n; + int dec_value = 0; + + int base = 1; + + int temp = num; + while (temp) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base; + + base = base * 2; + } + + return dec_value; +} + + +int main() +{ + int num; + + cin >>num; + + cout << binaryToDecimal(num) << endl; +} From 4f33735c6fb9fcee2e165161103eb856f6cb8ff2 Mon Sep 17 00:00:00 2001 From: Shubzedm007 <72625065+Shubzedm007@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:39:30 +0530 Subject: [PATCH 693/781] Create A C++ Program to print ASCII value of given character A C++ Program to find the ASCII value of any character --- A C++ Program to print ASCII value of given character | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 A C++ Program to print ASCII value of given character diff --git a/A C++ Program to print ASCII value of given character b/A C++ Program to print ASCII value of given character new file mode 100644 index 00000000..3dc975bb --- /dev/null +++ b/A C++ Program to print ASCII value of given character @@ -0,0 +1,8 @@ +#include +using namespace std; +int main() +{ + char c = 'A'; + cout << "The ASCII value of " << c << " is " << int(c); + return 0; +} From af1a31a0b2f2a40ee9d04b4dca50681d338c2adb Mon Sep 17 00:00:00 2001 From: aaryaab Date: Sun, 18 Oct 2020 19:43:00 +0530 Subject: [PATCH 694/781] Create String Operation using Java Given two strings, append them together (known as "concatenation") and return the result. However, if the strings are different lengths, omit chars from the longer string so i --- String Operation using Java | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 String Operation using Java diff --git a/String Operation using Java b/String Operation using Java new file mode 100644 index 00000000..f045450e --- /dev/null +++ b/String Operation using Java @@ -0,0 +1,37 @@ +/*Given two strings, append them together (known as "concatenation") and return the result. However, if the strings are different lengths, omit chars from the longer string so it is the same length as the shorter string. So "Hello" and "Hi" yield "loHi". The strings may be any length. + + +minCat("Hello", "Hi") → "loHi" +minCat("Hello", "java") → "ellojava" +minCat("java", "Hello") → "javaello"*/ + +package zzz; +import java.util.Scanner; +import java.util.ArrayList; +public class practice { + + public static void main(String[] args) { + // TODO Auto-generated method stub + Scanner sc = new Scanner(System.in); + String a =sc.nextLine(); + String b[] =a.split(" "); + int b1[] = new int[b.length]; + int j = 0; + for(int i=0;i Date: Sun, 18 Oct 2020 19:44:09 +0530 Subject: [PATCH 695/781] Create Python Program to convert binary to decimal number A Python program for converting any binary number to the decimal number . --- ...rogram to convert binary to decimal number | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Python Program to convert binary to decimal number diff --git a/Python Program to convert binary to decimal number b/Python Program to convert binary to decimal number new file mode 100644 index 00000000..9d1c476b --- /dev/null +++ b/Python Program to convert binary to decimal number @@ -0,0 +1,21 @@ + +# Function calculates the decimal equivalent +# to given binary number + +def binaryToDecimal(binary): + + binary1 = binary + decimal, i, n = 0, 0, 0 + while(binary != 0): + dec = binary % 10 + decimal = decimal + dec * pow(2, i) + binary = binary//10 + i += 1 + print(decimal) + + +# Driver code +if __name__ == '__main__': + binaryToDecimal(100) + binaryToDecimal(101) + binaryToDecimal(1001) From e13f807acd2bf6e0aea6b94613107ecaa3cb501e Mon Sep 17 00:00:00 2001 From: Abhiram Rajeevan <54032786+AbhiramRajeevan@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:44:23 +0530 Subject: [PATCH 696/781] Create Menu Driven-Calculate Basic Arithmatic Operations This is a menu driven program to calculate all the basic arithmatic operations in c programing language --- ...iven-Calculate Basic Arithmatic Operations | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Menu Driven-Calculate Basic Arithmatic Operations diff --git a/Menu Driven-Calculate Basic Arithmatic Operations b/Menu Driven-Calculate Basic Arithmatic Operations new file mode 100644 index 00000000..912479e2 --- /dev/null +++ b/Menu Driven-Calculate Basic Arithmatic Operations @@ -0,0 +1,47 @@ +#include + +int main() +{ + float num1,num2,ans; + int opt; + + //taking user input + do + { + printf("\nEnter the First Number : "); + scanf("%f",&num1); + printf("\nEnter the Second Number : "); + scanf("%f",&num2); + + //Displaying menu + printf("\n-----Main Menu----\n1.Addition"); + printf("\n2.Subtraction\n3.Multiply\n4.Divide\n5.Exit"); + printf("\nEnter your choice : "); + scanf("%d",&opt); + switch(opt) + { + case 1: + ans = num1+num2; + printf("\nThe addition of 2 numbers is : %f",ans); + break; + case 2: + ans = num1-num2; + printf("\nThe differnce of 2 numbers is : %f",ans); + break; + case 3: + ans = num1*num2; + printf("\nThe product of 2 numbers is : %f",ans); + break; + case 4: + ans = num1/num2; + printf("\nThe division of 2 numbers is : %f",ans); + break; + case 5: + break; + default: //error message for wrong choice + printf("\nYou Entered Wrong Choice\n"); + break; + } + }while(opt!=5); + return 0; +} From 30848b6c1362e304484ee23cb6881a7a2f7b91ae Mon Sep 17 00:00:00 2001 From: Pankaj6198 <72489198+Pankaj6198@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:48:03 +0530 Subject: [PATCH 697/781] Matric addition Program to perform matrix addition --- Matrix addtion | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Matrix addtion diff --git a/Matrix addtion b/Matrix addtion new file mode 100644 index 00000000..d8eac647 --- /dev/null +++ b/Matrix addtion @@ -0,0 +1,32 @@ +#include +void main() +{ + int a[100][100],b[100][100],row,col,sum[100][100],i,j; + printf("Enter no of rows and cols"); + scanf("%d%d",&row,&col); + printf("Enter Matrix A"); + for(i=0;i Date: Sun, 18 Oct 2020 19:48:58 +0530 Subject: [PATCH 698/781] Create Calculate compound interest.java --- Calculate compound interest.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Calculate compound interest.java diff --git a/Calculate compound interest.java b/Calculate compound interest.java new file mode 100644 index 00000000..ca6b213a --- /dev/null +++ b/Calculate compound interest.java @@ -0,0 +1,21 @@ +public class JavaExample { + + public void calculate(int p, int t, double r, int n) { + + double amount = p * Math.pow(1 + (r / n), n * t); + + double cinterest = amount - p; + + System.out.println("Compound Interest after " + t + " years: "+cinterest); + + System.out.println("Amount after " + t + " years: "+amount); + + } + + public static void main(String args[]) { + + JavaExample obj = new JavaExample(); obj.calculate(2000, 5, .08, 12); + + } + +} From 7d1fd793f00e3c37042c42761002886645e52799 Mon Sep 17 00:00:00 2001 From: RummanAhmedFazil <72257305+RummanAhmedFazil@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:50:09 +0530 Subject: [PATCH 699/781] Create Calculate compound interest --- Calculate compound interest | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Calculate compound interest diff --git a/Calculate compound interest b/Calculate compound interest new file mode 100644 index 00000000..ca6b213a --- /dev/null +++ b/Calculate compound interest @@ -0,0 +1,21 @@ +public class JavaExample { + + public void calculate(int p, int t, double r, int n) { + + double amount = p * Math.pow(1 + (r / n), n * t); + + double cinterest = amount - p; + + System.out.println("Compound Interest after " + t + " years: "+cinterest); + + System.out.println("Amount after " + t + " years: "+amount); + + } + + public static void main(String args[]) { + + JavaExample obj = new JavaExample(); obj.calculate(2000, 5, .08, 12); + + } + +} From 261c547925839622935a8fa0a54e3d33d574f622 Mon Sep 17 00:00:00 2001 From: indrajitsinha88 <73067238+indrajitsinha88@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:50:14 +0530 Subject: [PATCH 700/781] Create Program to reverse the array in Java Language I have Created A Program to reverse the array in Java Using Eclipse --- Program to reverse the array in Java Language | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Program to reverse the array in Java Language diff --git a/Program to reverse the array in Java Language b/Program to reverse the array in Java Language new file mode 100644 index 00000000..b13b460b --- /dev/null +++ b/Program to reverse the array in Java Language @@ -0,0 +1,43 @@ +// Iterative java program to reverse an +// array +public class GFG { + +/* Function to reverse arr[] from + start to end*/ + static void rvereseArray(int arr[], + int start, int end) + { + int temp; + + while (start < end) + { + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } + } + + /* Utility that prints out an + array on a line */ + static void printArray(int arr[], + int size) + { + for (int i = 0; i < size; i++) + System.out.print(arr[i] + " "); + + System.out.println(); + } + + // Driver code + public static void main(String args[]) { + + int arr[] = {1, 2, 3, 4, 5, 6}; + printArray(arr, 6); + rvereseArray(arr, 0, 5); + System.out.print("Reversed array is \n"); + printArray(arr, 6); + + } +} From 86993254f46fae1ea9bcde0d427343d938496af7 Mon Sep 17 00:00:00 2001 From: Abhiram Rajeevan <54032786+AbhiramRajeevan@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:51:15 +0530 Subject: [PATCH 701/781] Create Program to print the fibonacci series -C++ This is a simple c++ program which will print the fibonacci series given number of terms --- Program to print the fibonacci series -C++ | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Program to print the fibonacci series -C++ diff --git a/Program to print the fibonacci series -C++ b/Program to print the fibonacci series -C++ new file mode 100644 index 00000000..9c82a47a --- /dev/null +++ b/Program to print the fibonacci series -C++ @@ -0,0 +1,33 @@ +#include +using namespace std; + +int main() +{ + int n, t1 = 0, t2 = 1, nextTerm = 0; + + cout << "Enter the number of terms: "; + cin >> n; + + cout << "Fibonacci Series: "; + + for (int i = 1; i <= n; ++i) + { + // Prints the first two terms. + if(i == 1) + { + cout << " " << t1; + continue; + } + if(i == 2) + { + cout << t2 << " "; + continue; + } + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + + cout << nextTerm << " "; + } + return 0; +} From 9e2cd3a50eb31b71f027d4de11cca4d68e3d5168 Mon Sep 17 00:00:00 2001 From: Abhiram Rajeevan <54032786+AbhiramRajeevan@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:56:41 +0530 Subject: [PATCH 702/781] Print leap years of given range C program to print the leap years in range n1 to n2 --- Print leap years in given range of numbers | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Print leap years in given range of numbers diff --git a/Print leap years in given range of numbers b/Print leap years in given range of numbers new file mode 100644 index 00000000..666987f7 --- /dev/null +++ b/Print leap years in given range of numbers @@ -0,0 +1,30 @@ +#include + +//function to check leap year +int checkLeapYear(int year) +{ + if( (year % 400==0)||(year%4==0 && year%100!=0) ) + return 1; + else + return 0; +} + +int main() +{ + int i,n1,n2; + + printf("Enter Starting Value "); + scanf("%d",&n1); + + printf("Enter Ending Value "); + scanf("%d",&n2); + + printf("Leap years from %d to %d:\n",n1,n2); + for(i=n1;i<=n2;i++) + { + if(checkLeapYear(i)) + printf("%d\t",i); + } + + return 0; +} From bbe1a2c691da44af20fec45aeda5d96d0ae647ef Mon Sep 17 00:00:00 2001 From: indrajitsinha88 <73067238+indrajitsinha88@users.noreply.github.com> Date: Sun, 18 Oct 2020 19:58:09 +0530 Subject: [PATCH 703/781] Create Program to count vowels, consonant, digits and special characters in string in Java Language Using Eclipse I Have Created a Program to count vowels, consonant, digits and special characters in string in Java Using Eclipse. --- ...s in string in Java Language Using Eclipse | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Program to count vowels, consonant, digits and special characters in string in Java Language Using Eclipse diff --git a/Program to count vowels, consonant, digits and special characters in string in Java Language Using Eclipse b/Program to count vowels, consonant, digits and special characters in string in Java Language Using Eclipse new file mode 100644 index 00000000..51546f95 --- /dev/null +++ b/Program to count vowels, consonant, digits and special characters in string in Java Language Using Eclipse @@ -0,0 +1,53 @@ +// Java Program to count vowels, consonant, digits and +// special character in a given string +import java.io.*; + +public class GFG { + + // Function to count number of vowels, consonant, + // digitsand special character in a string. + static void countCharacterType(String str) + { + // Declare the variable vowels, consonant, digit + // and special characters + int vowels = 0, consonant = 0, specialChar = 0, + digit = 0; + + // str.length() function to count number of + // character in given string. + for (int i = 0; i < str.length(); i++) { + + char ch = str.charAt(i); + + if ( (ch >= 'a' && ch <= 'z') || + (ch >= 'A' && ch <= 'Z') ) { + + // To handle upper case letters + ch = Character.toLowerCase(ch);; + + if (ch == 'a' || ch == 'e' || ch == 'i' || + ch == 'o' || ch == 'u') + vowels++; + else + consonant++; + } + else if (ch >= '0' && ch <= '9') + digit++; + else + specialChar++; + } + + System.out.println("Vowels: " + vowels); + System.out.println("Consonant: " + consonant); + System.out.println("Digit: " + digit); + System.out.println("Special Character: " + specialChar); + } + + // Driver function. + static public void main (String[] args) + { + String str = "geeks for geeks121"; + + countCharacterType(str); + } +} From 4cbfc2b18a0f3870fa44d5cfde0b28576c931fd3 Mon Sep 17 00:00:00 2001 From: indrajitsinha88 <73067238+indrajitsinha88@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:03:03 +0530 Subject: [PATCH 704/781] Create Program to find largest element in array in Java Using Eclipse Program to find largest element in array in Java Using Eclipse. --- ...est element in array in Java Using Eclipse | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Program to find largest element in array in Java Using Eclipse diff --git a/Program to find largest element in array in Java Using Eclipse b/Program to find largest element in array in Java Using Eclipse new file mode 100644 index 00000000..965f1fe1 --- /dev/null +++ b/Program to find largest element in array in Java Using Eclipse @@ -0,0 +1,22 @@ +import java .io.*; +import java.util.*; + +class GFG +{ + // returns maximum in arr[] of size n + static int largest(int []arr, + int n) + { + Arrays.sort(arr); + return arr[n - 1]; + } + + // Driver code + static public void main (String[] args) + { + int []arr = {10, 324, 45, + 90, 9808}; + int n = arr.length; + System.out.println(largest(arr, n)); + } +} From ccf945bed961d39c83f31fa814e8fa9cba6f6a2d Mon Sep 17 00:00:00 2001 From: indrajitsinha88 <73067238+indrajitsinha88@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:09:21 +0530 Subject: [PATCH 705/781] Create Simple Calculator in Bash Language Using Ubuntu Terminal Me Indrajit Sinha Simple Calculator in Bash Using Ubuntu Terminal. --- ...or in Bash Language Using Ubuntu Terminal | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Simple Calculator in Bash Language Using Ubuntu Terminal diff --git a/Simple Calculator in Bash Language Using Ubuntu Terminal b/Simple Calculator in Bash Language Using Ubuntu Terminal new file mode 100644 index 00000000..9928200a --- /dev/null +++ b/Simple Calculator in Bash Language Using Ubuntu Terminal @@ -0,0 +1,28 @@ +# !/bin/bash + +# Take user Input +echo "Enter Two numbers : " +read a +read b + +# Input type of operation +echo "Enter Choice :" +echo "1. Addition" +echo "2. Subtraction" +echo "3. Multiplication" +echo "4. Division" +read ch + +# Switch Case to perform +# calulator operations +case $ch in +1)res=`echo $a + $b | bc` +;; +2)res=`echo $a - $b | bc` +;; +3)res=`echo $a \* $b | bc` +;; +4)res=`echo "scale=2; $a / $b" | bc` +;; +esac +echo "Result : $res" From 99c63094b535c785c2b361ca98d0514110a5aa1f Mon Sep 17 00:00:00 2001 From: Divyanshu Singh <67826413+DivyanshuSingh2000@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:13:28 +0530 Subject: [PATCH 706/781] Create ProgramToMultiply2DMatrices --- ProgramToMultiply2DMatrices | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 ProgramToMultiply2DMatrices diff --git a/ProgramToMultiply2DMatrices b/ProgramToMultiply2DMatrices new file mode 100644 index 00000000..40781374 --- /dev/null +++ b/ProgramToMultiply2DMatrices @@ -0,0 +1,25 @@ +# Program to multiply two matrices using nested loops + +# 3x3 matrix +X = [[12,7,3], + [4 ,5,6], + [7 ,8,9]] +# 3x4 matrix +Y = [[5,8,1,2], + [6,7,3,0], + [4,5,9,1]] +# result is 3x4 +result = [[0,0,0,0], + [0,0,0,0], + [0,0,0,0]] + +# iterate through rows of X +for i in range(len(X)): + # iterate through columns of Y + for j in range(len(Y[0])): + # iterate through rows of Y + for k in range(len(Y)): + result[i][j] += X[i][k] * Y[k][j] + +for r in result: + print(r) From 13cf0099378db6b2598b3f4647af5615fb1b8385 Mon Sep 17 00:00:00 2001 From: Divyanshu Singh <67826413+DivyanshuSingh2000@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:16:27 +0530 Subject: [PATCH 707/781] Create PowerOfAnyNumber --- PowerOfAnyNumber | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 PowerOfAnyNumber diff --git a/PowerOfAnyNumber b/PowerOfAnyNumber new file mode 100644 index 00000000..f3fc8f14 --- /dev/null +++ b/PowerOfAnyNumber @@ -0,0 +1,8 @@ +def power(base,exp): + if(exp==1): + return(base) + if(exp!=1): + return(base*power(base,exp-1)) +base=int(input("Enter base: ")) +exp=int(input("Enter exponential value: ")) +print("Result:",power(base,exp)) From c05ac2827d7b3b3217d4604dd940c465b2c14528 Mon Sep 17 00:00:00 2001 From: technicalreju <73017717+technicalreju@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:18:38 +0530 Subject: [PATCH 708/781] Create Array Reversed A simple program written in C to reverse an array. --- Array Reversed | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Array Reversed diff --git a/Array Reversed b/Array Reversed new file mode 100644 index 00000000..f21e7916 --- /dev/null +++ b/Array Reversed @@ -0,0 +1,19 @@ +#include +int main() +{ + +int n; +scanf(“%d”,&n); +int arr[n]; +int i; +for(i = 0; i < n; i++) +{ +scanf(“%d”,&arr[i]); +} +printf(“Reversed array is:\n”); +for(i = n-1; i >= 0; i–) +{ +printf(“%d\n”,arr[i]); +} +return 0; +} From 61d2e93789af035ac36534784d38614d61db0715 Mon Sep 17 00:00:00 2001 From: aaryaab Date: Sun, 18 Oct 2020 20:23:37 +0530 Subject: [PATCH 709/781] Create Difference between Sum of Square using Java Write a program to find the difference between sum of the //squares and the square of the sums of n numbers? //Sum of the square(n) ,square of sum n// --- Difference between Sum of Square using Java | 30 +++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Difference between Sum of Square using Java diff --git a/Difference between Sum of Square using Java b/Difference between Sum of Square using Java new file mode 100644 index 00000000..49c00af8 --- /dev/null +++ b/Difference between Sum of Square using Java @@ -0,0 +1,30 @@ +//Write a program to find the difference between sum of the +//squares and the square of the sums of n numbers? +//Sum of the square(n) ,square of sum n// + +package practice; +import java.util.Scanner; +import java.util.ArrayList; +public class solution { + + public static void main(String[] args) { + // TODO Auto-generated method stub +Scanner sc = new Scanner(System.in); +int x =sc.nextInt(); +int a[] = new int[x]; +for(int i=0;i Date: Sun, 18 Oct 2020 20:27:28 +0530 Subject: [PATCH 710/781] Create ASCII value print A simple C program to print ASCII value --- ASCII value print | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 ASCII value print diff --git a/ASCII value print b/ASCII value print new file mode 100644 index 00000000..a2674cbc --- /dev/null +++ b/ASCII value print @@ -0,0 +1,8 @@ +#include +int main() { + char c; + printf("Enter a character: "); + scanf("%c", &c); + printf("ASCII value of %c = %d", c, c); + return 0; +} From b3de556873ea5a84cfa52957a4e0766426f2c870 Mon Sep 17 00:00:00 2001 From: aaryaab Date: Sun, 18 Oct 2020 20:29:07 +0530 Subject: [PATCH 711/781] Create Calculator using Java --- Calculator using Java | 47 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Calculator using Java diff --git a/Calculator using Java b/Calculator using Java new file mode 100644 index 00000000..736bfb76 --- /dev/null +++ b/Calculator using Java @@ -0,0 +1,47 @@ +package practice; +import java.util.Scanner; +import java.util.ArrayList; +import java.lang.Math.*; +class Calculation{ + public int add(int a, int b) { + return a+b; + } + + public int sub(int a, int b) { + if(a>b) { + return a-b; + }else { + return b-a; + } + } + public int mul(int a, int b) { + return a*b; + } + public int div(int a, int b) { + if(a>b) { + return a/b; + }else { + return b/a; + } + } +} + + + +public class solution { + + public static void main(String[] args) { + // TODO Auto-generated method stub +Scanner sc = new Scanner(System.in); +Calculation cal = new Calculation(); +int x =sc.nextInt(); +int y=sc.nextInt(); +int add = cal.add(x,y ); +int sub = cal.sub(x, y); +int mul=cal.mul(x, y); +int div=cal.div(y, x); + +System.out.println("add is "+add+" sub is "+sub+"mul is "+mul+" div is "+div); +} + +} From 129ae1b270989b576949c66fbfd90e71119da4c7 Mon Sep 17 00:00:00 2001 From: namita27 <60788694+namita27@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:48:49 +0530 Subject: [PATCH 712/781] Create Number raised to a power Power of a number using binary exponentiation algorithm. --- Number raised to a power | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Number raised to a power diff --git a/Number raised to a power b/Number raised to a power new file mode 100644 index 00000000..dc1b475f --- /dev/null +++ b/Number raised to a power @@ -0,0 +1,25 @@ +import java.util.*; +import java.lang.*; + +class power { + + static long power(long x,long y) + { + long temp; + if( y == 0) + return 1; + temp = power(x, y/2); + if (y%2 == 0) + return temp*temp; + else + return x*temp*temp; + } + + public static void main (String[] args) { + Scanner sc=new Scanner(System.in); + long a=sc.nextLong(); + long b=sc.nextLong(); + System.out.println(power(a,b)); + + } +} From 2742cb20b94325682915a67ecb663a89ff1ff8b2 Mon Sep 17 00:00:00 2001 From: Aswinipai <57011217+Aswinipai@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:49:11 +0530 Subject: [PATCH 713/781] Create Program to calculate the power of a number --- Program to calculate the power of a number | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Program to calculate the power of a number diff --git a/Program to calculate the power of a number b/Program to calculate the power of a number new file mode 100644 index 00000000..e7d59525 --- /dev/null +++ b/Program to calculate the power of a number @@ -0,0 +1,16 @@ +#include +int main() { + int base, exp; + long long result = 1; + printf("Enter a base number: "); + scanf("%d", &base); + printf("Enter an exponent: "); + scanf("%d", &exp); + + while (exp != 0) { + result *= base; + --exp; + } + printf("Answer = %lld", result); + return 0; +} From 6b4b09c4e805e85e037c3c4b2f4ba2261adef2ca Mon Sep 17 00:00:00 2001 From: Aswinipai <57011217+Aswinipai@users.noreply.github.com> Date: Sun, 18 Oct 2020 20:52:08 +0530 Subject: [PATCH 714/781] Create Merge sort --- Merge sort | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Merge sort diff --git a/Merge sort b/Merge sort new file mode 100644 index 00000000..42bf452f --- /dev/null +++ b/Merge sort @@ -0,0 +1,69 @@ +#include +void mergeSort(int[],int,int); +void merge(int[],int,int,int); +void main () +{ + int a[10]= {10, 9, 7, 101, 23, 44, 12, 78, 34, 23}; + int i; + mergeSort(a,0,9); + printf("printing the sorted elements"); + for(i=0;i<10;i++) + { + printf("\n%d\n",a[i]); + } + +} +void mergeSort(int a[], int beg, int end) +{ + int mid; + if(begmid) + { + while(j<=end) + { + temp[index] = a[j]; + index++; + j++; + } + } + else + { + while(i<=mid) + { + temp[index] = a[i]; + index++; + i++; + } + } + k = beg; + while(k Date: Sun, 18 Oct 2020 20:57:20 +0530 Subject: [PATCH 715/781] Create Fibonacci Printing Fibonacci series --- Fibonacci | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Fibonacci diff --git a/Fibonacci b/Fibonacci new file mode 100644 index 00000000..ea9a7240 --- /dev/null +++ b/Fibonacci @@ -0,0 +1,20 @@ +import java.util.*; +import java.lang.*; + +class fibo { + + public static void main (String[] args) { + Scanner sc=new Scanner(System.in); + int n=sc.nextInt(); + int a=0,b=1,c=0; + System.out.print(a+" "+b+" "); + for(int i=1;i<=n;i++){ + c=a+b; + System.out.print(c+" "); + a=b; + b=c; + } + + + } +} From ee6ff5eeb5a3d91c8a9f525690a0599b9cdc919b Mon Sep 17 00:00:00 2001 From: Ashishkhakurel <44515939+Ashishkhakurel@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:15:49 +0545 Subject: [PATCH 716/781] Create Palindrome program in C code to find palindrome using c --- Palindrome program in C | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Palindrome program in C diff --git a/Palindrome program in C b/Palindrome program in C new file mode 100644 index 00000000..f45798e8 --- /dev/null +++ b/Palindrome program in C @@ -0,0 +1,19 @@ +#include +int main() +{ +int n,r,sum=0,temp; +printf("enter the number="); +scanf("%d",&n); +temp=n; +while(n>0) +{ +r=n%10; +sum=(sum*10)+r; +n=n/10; +} +if(temp==sum) +printf("palindrome number "); +else +printf("not palindrome"); +return 0; +} From 7bb560a227cc14f6c11a38bfbcaff4da188ce1d3 Mon Sep 17 00:00:00 2001 From: Ashishkhakurel <44515939+Ashishkhakurel@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:19:18 +0545 Subject: [PATCH 717/781] Create Fibonacci Series in C optimized code to find fibonacci series. --- Fibonacci Series in C | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Fibonacci Series in C diff --git a/Fibonacci Series in C b/Fibonacci Series in C new file mode 100644 index 00000000..1a7861e7 --- /dev/null +++ b/Fibonacci Series in C @@ -0,0 +1,16 @@ +#include +int main() +{ + int n1=0,n2=1,n3,i,number; + printf("Enter the number of elements:"); + scanf("%d",&number); + printf("\n%d %d",n1,n2);//printing 0 and 1 + for(i=2;i Date: Sun, 18 Oct 2020 21:22:11 +0545 Subject: [PATCH 718/781] Create Armstrong Number in C code to create armstrong number --- Armstrong Number in C | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Armstrong Number in C diff --git a/Armstrong Number in C b/Armstrong Number in C new file mode 100644 index 00000000..e2fd95a4 --- /dev/null +++ b/Armstrong Number in C @@ -0,0 +1,19 @@ +#include + int main() +{ +int n,r,sum=0,temp; +printf("enter the number="); +scanf("%d",&n); +temp=n; +while(n>0) +{ +r=n%10; +sum=sum+(r*r*r); +n=n/10; +} +if(temp==sum) +printf("armstrong number "); +else +printf("not armstrong number"); +return 0; +} From 5ededdae78aab597abb1f9e7c28f3713e676a5cb Mon Sep 17 00:00:00 2001 From: namita27 <60788694+namita27@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:07:30 +0530 Subject: [PATCH 719/781] Create DecimalToBinary Converting a binary number to a decimal number --- DecimalToBinary | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 DecimalToBinary diff --git a/DecimalToBinary b/DecimalToBinary new file mode 100644 index 00000000..bbef45b3 --- /dev/null +++ b/DecimalToBinary @@ -0,0 +1,12 @@ +import java.util.*; +import java.lang.*; + +class deciToBin { + + public static void main (String[] args) { + Scanner sc=new Scanner(System.in); + String binaryString=sc.next(); + int decimal=Integer.parseInt(binaryString,2); + System.out.println(decimal); + } +} From 77ca31e84bc91db8596da2695f22762f674340f3 Mon Sep 17 00:00:00 2001 From: Ashishkhakurel <44515939+Ashishkhakurel@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:24:04 +0545 Subject: [PATCH 720/781] Create C Program to print Alphabet Triangle To print alphabet triangle using c programming language. --- C Program to print Alphabet Triangle | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 C Program to print Alphabet Triangle diff --git a/C Program to print Alphabet Triangle b/C Program to print Alphabet Triangle new file mode 100644 index 00000000..6f01273b --- /dev/null +++ b/C Program to print Alphabet Triangle @@ -0,0 +1,20 @@ +#include +#include +int main(){ + int ch=65; + int i,j,k,m; + system("cls"); + for(i=1;i<=5;i++) + { + for(j=5;j>=i;j--) + printf(" "); + for(k=1;k<=i;k++) + printf("%c",ch++); + ch--; + for(m=1;m Date: Sun, 18 Oct 2020 21:10:32 +0530 Subject: [PATCH 721/781] Create rogram to convert binary to decimal number Optimized code using java --- rogram to convert binary to decimal number | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 rogram to convert binary to decimal number diff --git a/rogram to convert binary to decimal number b/rogram to convert binary to decimal number new file mode 100644 index 00000000..f9030cb5 --- /dev/null +++ b/rogram to convert binary to decimal number @@ -0,0 +1,37 @@ +// Java program to convert +// binary to decimal + +// Function to convert +// binary to decimal +class GFG { + static int binaryToDecimal(int n) + { + int num = n; + int dec_value = 0; + + // Initializing base + // value to 1, i.e 2^0 + int base = 1; + + int temp = num; + while (temp > 0) { + int last_digit = temp % 10; + temp = temp / 10; + + dec_value += last_digit * base; + + base = base * 2; + } + + return dec_value; + } + + // Driver Code + public static void main(String[] args) + { + int num = 10101001; + System.out.println(binaryToDecimal(num)); + } +} + +// This code is contributed by mits. From 73c6a7833e222f64b5ee45363f67e3225a14f3aa Mon Sep 17 00:00:00 2001 From: namita27 <60788694+namita27@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:11:27 +0530 Subject: [PATCH 722/781] Create Length of a string Finding the length of a string --- Length of a string | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Length of a string diff --git a/Length of a string b/Length of a string new file mode 100644 index 00000000..2e51a1de --- /dev/null +++ b/Length of a string @@ -0,0 +1,12 @@ +import java.util.*; +import java.lang.*; + +class deciToBin { + + public static void main (String[] args) { + Scanner sc=new Scanner(System.in); + String str=sc.nextLine(); + System.out.println(str.length()); + + } +} From 6bcb2863665dda8b63fb64999cb3121fab8c457d Mon Sep 17 00:00:00 2001 From: aniket170 <73054191+aniket170@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:16:18 +0530 Subject: [PATCH 723/781] Create bubbleSort.py --- bubbleSort.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 bubbleSort.py diff --git a/bubbleSort.py b/bubbleSort.py new file mode 100644 index 00000000..609564c6 --- /dev/null +++ b/bubbleSort.py @@ -0,0 +1,26 @@ +# Python program for implementation of Bubble Sort + +def bubbleSort(arr): + n = len(arr) + + # Traverse through all array elements + for i in range(n-1): + # range(n) also work but outer loop will repeat one time more than needed. + + # Last i elements are already in place + for j in range(0, n-i-1): + + # traverse the array from 0 to n-i-1 + # Swap if the element found is greater + # than the next element + if arr[j] > arr[j+1] : + arr[j], arr[j+1] = arr[j+1], arr[j] + +# Driver code to test above +arr = [64, 34, 25, 12, 22, 11, 90] + +bubbleSort(arr) + +print ("Sorted array is:") +for i in range(len(arr)): + print ("%d" %arr[i]), From 9c7862d8c14581e851c48aff7eda14d8b1f1a777 Mon Sep 17 00:00:00 2001 From: Harish Chavan Date: Sun, 18 Oct 2020 21:30:09 +0530 Subject: [PATCH 724/781] Created Constraint Satisfaction Problem Added code in Python for Constraint Satisfaction Problem - Graph colouring, which is used is AI basics. --- ...t Satisfaction Problem - Graph coloring.py | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Constraint Satisfaction Problem - Graph coloring.py diff --git a/Constraint Satisfaction Problem - Graph coloring.py b/Constraint Satisfaction Problem - Graph coloring.py new file mode 100644 index 00000000..e1eb0eac --- /dev/null +++ b/Constraint Satisfaction Problem - Graph coloring.py @@ -0,0 +1,116 @@ +class Vertex: + def __init__(self, name): + self.name = name + self.neighbors = [] + self.heuristic = 0 + self.visited = 0 + self.color = ['red', 'blue', 'green'] + + def add_neighbor(self, vertex): + if vertex not in self.neighbors: + self.neighbors.append(vertex) + self.neighbors.sort() + self.heuristic = len(self.neighbors) + +class Graph: + vertices = {} + + def add_vertex(self, vertex): + if isinstance(vertex, Vertex) and vertex.name not in self.vertices: + self.vertices[vertex.name] = vertex + return True + return False + + def add_edge(self, u, v): + if u in self.vertices and v in self.vertices: + for key, value in self.vertices.items(): + if key == u: + value.add_neighbor(v) + if key == v: + value.add_neighbor(u) + return True + return False + + def sorter(self): + res = [[self.vertices[key].heuristic, key] for key in self.vertices] + res.sort(reverse=True) + return res + + def decolorer(self, n_li, decolor): + for neighbor in n_li: + if self.vertices[neighbor].visited == 0: + try: + self.vertices[neighbor].color.remove(decolor) + except: + continue + + def csp(self): + li = self.sorter() + queue = [self.vertices[key[1]] for key in li] + count = 0 + result = [] + while count != len(queue): + queue[count].visited = 1 + queue[count].color = queue[count].color.pop(0) + + self.decolorer(queue[count].neighbors, queue[count].color) + result.append([queue[count].name, queue[count].color]) + count += 1 + print('result :', result, '\n') + + def print_graph(self): + print('Graph nodes and their neighbors:') + li = self.sorter() + for key in li: + print(key[1] + ' ( ' + str(self.vertices[key[1]].heuristic) + ' )' ': ' + str(self.vertices[key[1]].neighbors)) + +if __name__=="__main__": + #Example 1 + graph = Graph() + + #Following are elements of V + a = Vertex('A') + b = Vertex('B') + c = Vertex('C') + d = Vertex('D') + e = Vertex('E') + f = Vertex('F') + g = Vertex('G') + + graph.add_vertex(a) + graph.add_vertex(b) + graph.add_vertex(c) + graph.add_vertex(d) + graph.add_vertex(e) + graph.add_vertex(f) + graph.add_vertex(g) + + edges = ['AB', 'AC', 'CD', 'CE', 'DE', 'BE', 'BF', 'FG', 'EG'] + for edge in edges: + graph.add_edge(edge[:1], edge[1:]) + + graph.print_graph() + print('\n') + graph.csp() + +""" + #Example 2 + graph2 = Graph() + p = Vertex('P') + q = Vertex('Q') + r = Vertex('R') + s = Vertex('S') + + graph2.add_vertex(p) + graph2.add_vertex(q) + graph2.add_vertex(r) + graph2.add_vertex(s) + + edges = ['PQ', 'PR', 'PS', 'RS', 'QS'] + for edge in edges: + graph2.add_edge(edge[:1], edge[1:]) + + graph2.print_graph() + print('\n') + graph2.csp() +""" \ No newline at end of file From 21413553640d34bd69beb369011a80b43c16b788 Mon Sep 17 00:00:00 2001 From: Satish Kollu <48837350+satishkollu@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:53:30 +0530 Subject: [PATCH 725/781] Arithmetic operations python Added a program to calculate all arithmetic operations python! --- Arithmetic calc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Arithmetic calc diff --git a/Arithmetic calc b/Arithmetic calc new file mode 100644 index 00000000..5962d09b --- /dev/null +++ b/Arithmetic calc @@ -0,0 +1,16 @@ +num1 = int(input('Enter First number: ')) +num2 = int(input('Enter Second number ')) +add = num1 + num2 +dif = num1 - num2 +mul = num1 * num2 +div = num1 / num2 +floor_div = num1 // num2 +power = num1 ** num2 +modulus = num1 % num2 +print('Sum of ',num1 ,'and' ,num2 ,'is :',add) +print('Difference of ',num1 ,'and' ,num2 ,'is :',dif) +print('Product of' ,num1 ,'and' ,num2 ,'is :',mul) +print('Division of ',num1 ,'and' ,num2 ,'is :',div) +print('Floor Division of ',num1 ,'and' ,num2 ,'is :',floor_div) +print('Exponent of ',num1 ,'and' ,num2 ,'is :',power) +print('Modulus of ',num1 ,'and' ,num2 ,'is :',modulus) From b818e2f7aef9b86e345751d77023dcf38881093f Mon Sep 17 00:00:00 2001 From: Satish Kollu <48837350+satishkollu@users.noreply.github.com> Date: Sun, 18 Oct 2020 21:59:59 +0530 Subject: [PATCH 726/781] Create count vowels and consonants added a python code that can count the number of vowels and consonants! --- count vowels and consonants | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 count vowels and consonants diff --git a/count vowels and consonants b/count vowels and consonants new file mode 100644 index 00000000..4049aa8c --- /dev/null +++ b/count vowels and consonants @@ -0,0 +1,12 @@ +string = str(input('Enter a String: ')) +vowels = ['a','e','i','o','u'] +characters = [] +count_v = 0 +count_c = 0 +for ch in string.lower(): + if ch.isalpha(): + if ch in vowels: + count_v += 1 + else: + count_c += 1 +print(' Number of Vowels: {} \n Number of Consonants: {}'.format(count_v, count_c)) From 856f80e6bb6b5f48fe846551d36b954046d6e505 Mon Sep 17 00:00:00 2001 From: Geethu1440 <73072816+Geethu1440@users.noreply.github.com> Date: Sun, 18 Oct 2020 22:03:32 +0530 Subject: [PATCH 727/781] Create Program to find largest element in an array Largest element of an array. --- Program to find largest element in an array | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Program to find largest element in an array diff --git a/Program to find largest element in an array b/Program to find largest element in an array new file mode 100644 index 00000000..98a77125 --- /dev/null +++ b/Program to find largest element in an array @@ -0,0 +1,22 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + // storing the largest number to arr[0] + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From 2d6b72d159ef4d54991f55a98ba7d19fce42479e Mon Sep 17 00:00:00 2001 From: Geethu1440 <73072816+Geethu1440@users.noreply.github.com> Date: Sun, 18 Oct 2020 22:12:52 +0530 Subject: [PATCH 728/781] Create Program to find largest element in an array Largest element in an array. --- Program to find largest element in an array | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Program to find largest element in an array diff --git a/Program to find largest element in an array b/Program to find largest element in an array new file mode 100644 index 00000000..98a77125 --- /dev/null +++ b/Program to find largest element in an array @@ -0,0 +1,22 @@ +#include +int main() { + int i, n; + float arr[100]; + printf("Enter the number of elements (1 to 100): "); + scanf("%d", &n); + + for (i = 0; i < n; ++i) { + printf("Enter number%d: ", i + 1); + scanf("%f", &arr[i]); + } + + // storing the largest number to arr[0] + for (i = 1; i < n; ++i) { + if (arr[0] < arr[i]) + arr[0] = arr[i]; + } + + printf("Largest element = %.2f", arr[0]); + + return 0; +} From 0968e0a5b71b42f5c0ec237d9590b008fe464ce6 Mon Sep 17 00:00:00 2001 From: Geethu1440 <73072816+Geethu1440@users.noreply.github.com> Date: Sun, 18 Oct 2020 22:18:06 +0530 Subject: [PATCH 729/781] Create Program to find smallest element in an array Smallest element in an array. --- Program to find smallest element in an array | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Program to find smallest element in an array diff --git a/Program to find smallest element in an array b/Program to find smallest element in an array new file mode 100644 index 00000000..9bf488b4 --- /dev/null +++ b/Program to find smallest element in an array @@ -0,0 +1,29 @@ +include +int main() +{ + int a[10], Size, i, Smallest, Position; + + printf("\nPlease Enter the size of an array \n"); + scanf("%d",&Size); + + printf("\nPlease Enter %d elements of an array: \n", Size); + for(i=0; i a[i]) + { + Smallest = a[i]; + Position = i; + } + } + + printf("\nSmallest element in an Array = %d", Smallest); + printf("\nIndex position of the Smallest element = %d", Position); + + return 0; +} From 82ef7dc4a6e69ca346f0604bd08146eddc6e0ec3 Mon Sep 17 00:00:00 2001 From: Geethu1440 <73072816+Geethu1440@users.noreply.github.com> Date: Sun, 18 Oct 2020 22:21:16 +0530 Subject: [PATCH 730/781] Create Program to find sum of all elements in an array Sum of all elements in an array --- ...am to find sum of all elements in an array | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Program to find sum of all elements in an array diff --git a/Program to find sum of all elements in an array b/Program to find sum of all elements in an array new file mode 100644 index 00000000..60e55679 --- /dev/null +++ b/Program to find sum of all elements in an array @@ -0,0 +1,26 @@ +#include + + +int main() +{ + int a[1000],i,n,sum=0; + + printf("Enter size of the array : "); + scanf("%d",&n); + + printf("Enter elements in array : "); + for(i=0; i Date: Sun, 18 Oct 2020 22:45:08 +0530 Subject: [PATCH 731/781] Create Segment trees the most optimal way of representing data. --- Segment trees | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Segment trees diff --git a/Segment trees b/Segment trees new file mode 100644 index 00000000..62628e33 --- /dev/null +++ b/Segment trees @@ -0,0 +1,40 @@ +#include +using namespace std; +const int N = 2e6; +map my[N]; +void update(int st, int lo, int hi, int pos, int val){ + my[st][val]++; + if(lo == hi){ + return; + } + int l = 2*st, r = l+1, mid = (lo+hi)/2; + if(pos>mid) update(r, mid+1, hi, pos, val); + else update(l, lo, mid, pos, val); +} +long long query(int st, int lo, int hi, int x, int y, int val){ + if(lo == x and hi == y){ + return my[st][val]; + } + int l = 2*st, r = l+1, mid = (lo+hi)/2; + if(x>mid) return query(r, mid+1, hi, x, y, val); + else if(y<=mid) return query(l, lo, mid, x, y, val); + return query(l ,lo , mid, x, mid, val) + query(r, mid+1, hi, mid+1, y, val); +} + +int main() { + int n, i, q, k, l, t, r; + cin >> n >> q; + while(q--){ + cin >> t >> l >> r; + if(t == 1){ + //add l to a[r] + update(1, 0, n-1, r-1, l); + } + else{ + //count of k from a[l] to a[r]. + cin >> k; + cout << query(1, 0, n-1, l-1, r-1, k) << endl; + } + } + return 0; +} From 4a303dd5dd50a7ea5b7890a1fb3e2b36d7dc074f Mon Sep 17 00:00:00 2001 From: Akhil Parikh Date: Sun, 18 Oct 2020 22:46:32 +0530 Subject: [PATCH 732/781] Create modulus of 5 --- Modulus of 5 | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Modulus of 5 diff --git a/Modulus of 5 b/Modulus of 5 new file mode 100644 index 00000000..fb8dd366 --- /dev/null +++ b/Modulus of 5 @@ -0,0 +1,49 @@ +#include + +using namespace std; + + + +#include +using namespace std; +typedef long long int ll; +ll e = 1e9+7; +ll check(ll x) +{ + ll sum=0; + while(x!=0) + { + sum=sum+ x%10; + x=x/10; + } + + if(sum%5==0) + { + return 1; + } + else + { + return 0; + } + +} +int main() { + ll n,k; + cin>>n; + cin>>k; + ll i = n+1; + ll count=1;ll answer ; + while(count<=k) + { + ll ram=check(i); + if(ram==1) + { + count++; + answer = i ; + } + + + i++; + } + cout< Date: Sun, 18 Oct 2020 22:46:40 +0530 Subject: [PATCH 733/781] Create persistent Segment trees the optimal data structure of retrieving element. --- persistent Segment trees | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 persistent Segment trees diff --git a/persistent Segment trees b/persistent Segment trees new file mode 100644 index 00000000..9a7a9867 --- /dev/null +++ b/persistent Segment trees @@ -0,0 +1,49 @@ +// query l to r range for the no of integers between x and y +#include +using namespace std; +int T = 1; +const int N = 1e6; +const int MX = N; +struct node{ + int l, r, cnt; +}t[100*MX]; +int root[N], a[N]; +int build(int lo, int hi){ + int id = T++; + if(lo == hi) return id; + int mid = (lo+hi)/2; + t[id].l = build(lo, mid); + t[id].r = build(mid+1, hi); + return id; +} +int update(int rt, int lo, int hi, int val){ + int id = T++; + t[id] = t[rt]; t[id].cnt++; + if(lo == hi) return id; + int mid = (lo+hi)/2; + if(val <= mid) t[id].l = update(t[rt].l, lo, mid, val); + else t[id].r = update(t[rt].r, mid+1, hi, val); + return id; +} +int query(int rt, int lo, int hi, int x, int y){ + if(x==lo and y==hi) return t[rt].cnt; + int mid = (lo+hi)/2; + if(y <= mid) return query(t[rt].l, lo, mid, x, y); + else if (x > mid) return query(t[rt].r, mid+1, hi, x, y); + return query(t[rt].l, lo, mid, x, mid) + query(t[rt].r, mid+1, hi, mid+1, y); +} +int main() { + int i, n, q; + cin >> n >> q; + for(i = 0; i < n; i++) cin >> a[i+1]; + root[0] = build(0, MX); + for(i = 1; i <= n; i++){ + root[i] = update(root[i-1], 0, MX, a[i]); + } + while(q--){ + int l, r, x, y; + cin >> l >> r >> x >> y; + cout << query(root[r], 0, MX, x, y) - query(root[l-1], 0, MX, x, y) << endl; + } + return 0; +} From 31f246373d67a7017685e943280ed5d5ec5aafec Mon Sep 17 00:00:00 2001 From: Darshan Jogad <64198730+dmjogad@users.noreply.github.com> Date: Sun, 18 Oct 2020 22:49:10 +0530 Subject: [PATCH 734/781] Create Leap year Python program to check leap year --- Leap year | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Leap year diff --git a/Leap year b/Leap year new file mode 100644 index 00000000..1af9e169 --- /dev/null +++ b/Leap year @@ -0,0 +1,11 @@ +year = int(input("Enter year: ")) +if (year % 4) == 0: + if (year % 100) == 0: + if (year % 400) == 0: + print("{0} is a leap year".format(year)) + else: + print("{0} is not a leap year".format(year)) + else: + print("{0} is a leap year".format(year)) +else: + print("{0} is not a leap year".format(year)) From f9b318d006819609e52c89162de68899ab6edc75 Mon Sep 17 00:00:00 2001 From: Satish Kollu <48837350+satishkollu@users.noreply.github.com> Date: Sun, 18 Oct 2020 22:50:20 +0530 Subject: [PATCH 735/781] Create binary_search_algo added the Binary Seach program one of the best algorithms to search elements. --- binary_search_algo | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 binary_search_algo diff --git a/binary_search_algo b/binary_search_algo new file mode 100644 index 00000000..8afb3afc --- /dev/null +++ b/binary_search_algo @@ -0,0 +1,27 @@ +#include +using namespace std; +int binarysearch(int arr[], int num, int start, int end) +{ while(start<=end){ + int middle = (start+end)/2; + if(arr[middle] == num) + return middle; + if(arr[middle]>num) + end=middle-1; + else + start=middle+1; + + } + return -1; +} + +int main() +{ + int arr[]={1,2,6,7,8,10}; + int num; + cin>>num; + int n = sizeof(arr)/ sizeof(arr[0]); + int ans=binarysearch(arr,num,0,n-1); + cout< Date: Sun, 18 Oct 2020 22:55:23 +0530 Subject: [PATCH 736/781] Create LinkedHashSet Class In java --- LinkedHashSet Class In java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 LinkedHashSet Class In java diff --git a/LinkedHashSet Class In java b/LinkedHashSet Class In java new file mode 100644 index 00000000..88d42598 --- /dev/null +++ b/LinkedHashSet Class In java @@ -0,0 +1,28 @@ +import java.util.LinkedHashSet; +public class LinkedHashSetExample { + public static void main(String args[]) { + // LinkedHashSet of String Type + LinkedHashSet lhset = new LinkedHashSet(); + + // Adding elements to the LinkedHashSet + lhset.add("Z"); + lhset.add("PQ"); + lhset.add("N"); + lhset.add("O"); + lhset.add("KK"); + lhset.add("FGH"); + System.out.println(lhset); + + // LinkedHashSet of Integer Type + LinkedHashSet lhset2 = new LinkedHashSet(); + + // Adding elements + lhset2.add(99); + lhset2.add(7); + lhset2.add(0); + lhset2.add(67); + lhset2.add(89); + lhset2.add(66); + System.out.println(lhset2); + } +} From ff23694cb00d4f72c9342bbf2fb003e062af7273 Mon Sep 17 00:00:00 2001 From: Harish Chavan Date: Sun, 18 Oct 2020 23:10:46 +0530 Subject: [PATCH 737/781] Best first search algorithm Added code in Python for the Best first search algorithm, which gives the best solution but not always optimal. --- Best First Search.py | 119 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 Best First Search.py diff --git a/Best First Search.py b/Best First Search.py new file mode 100644 index 00000000..c0b16014 --- /dev/null +++ b/Best First Search.py @@ -0,0 +1,119 @@ +class Vertex: + def __init__(self, name, heuristic): + self.name = name + self.hr = heuristic + self.neighbors = [] + self.visited = 0 + + def add_neighbor(self, v): + if v not in self.neighbors: + self.neighbors.append(v) + self.neighbors.sort() + +class Graph: + vertices = {} + + def add_vertex(self, vertex): + if isinstance(vertex, Vertex) and vertex.name not in self.vertices: + self.vertices[vertex.name] = vertex + return True + return False + + def add_edge(self, u, v): + if u in self.vertices and v in self.vertices: + for key, value in self.vertices.items(): + if key == u: + value.add_neighbor(v) + if key == v: + value.add_neighbor(u) + return True + return False + + def priority(self, queue): + rank = [] + for i in queue: + for j in self.vertices: + if i.name == j and i.visited == 0: + rank.append(i.hr) + rank.sort() + queue = [] + for i in rank: + for j in self.vertices: + if i == self.vertices[j].hr: + queue.append(self.vertices[j]) + return queue + + def BestFirstSearch(self, start, end): + ol = [] + cl = [] + + ol.append(start) + while ol != []: + temp = ol.pop(0) + temp.visited = 1 + if temp.name == end.name: + cl.append(end.name) + break + cl.append(temp.name) + + queue = [] + queue += [self.vertices[i] for i in temp.neighbors] + ol += queue + ol = self.priority(ol) + return cl + +if __name__=='__main__': + graph = Graph() + """ + #Example 1: + + a = Vertex('A', 10) + b = Vertex('B', 2) + c = Vertex('C', 1) + d = Vertex('D', 5) + e = Vertex('E', 6) + f = Vertex('F', 0) + g = Vertex('G', 7) + + graph.add_vertex(a) + graph.add_vertex(b) + graph.add_vertex(c) + graph.add_vertex(d) + graph.add_vertex(e) + graph.add_vertex(f) + graph.add_vertex(g) + + edges = ['AB', 'AC', 'AD', 'BE', 'CF', 'DG', 'EF', 'GF'] + for edge in edges: + graph.add_edge(edge[:1], edge[1:]) + """ + + #Example 2: + + a = Vertex('A', 80) + b = Vertex('B', 50) + c = Vertex('C', 40) + d = Vertex('D', 20) + e = Vertex('E', 30) + f = Vertex('F', 0) + + graph.add_vertex(a) + graph.add_vertex(b) + graph.add_vertex(c) + graph.add_vertex(d) + graph.add_vertex(e) + graph.add_vertex(f) + + edges = ['AB', 'AC', 'AE', 'BF', 'CE', 'BD', 'DF', 'EF'] + for edge in edges: + graph.add_edge(edge[:1], edge[1:]) + + path = graph.BestFirstSearch(a, f) + + fstr = '' + for node in range(len(path)): + if node == len(path) - 1: + fstr += path[node] + break + fstr += path[node] + ' --> ' + print(fstr) \ No newline at end of file From fa49da4ed8feeeef41089ca7696b90cc644c2cba Mon Sep 17 00:00:00 2001 From: Amit Kumar Mitra <50025230+amit14mitra@users.noreply.github.com> Date: Sun, 18 Oct 2020 23:19:07 +0530 Subject: [PATCH 738/781] Added a anagram program using Java --- Anagram Program using java. | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Anagram Program using java. diff --git a/Anagram Program using java. b/Anagram Program using java. new file mode 100644 index 00000000..d5a55c4c --- /dev/null +++ b/Anagram Program using java. @@ -0,0 +1,31 @@ +import java.util.Scanner; + +public class Solution { + + static boolean isAnagram(String a, String b) { + if(a.length() != b.length()) + return false; + int c[] = new int[26], d[] = new int[26] ; + a = a.toLowerCase(); + b = b.toLowerCase(); + for(int i=0; i Date: Sun, 18 Oct 2020 23:25:02 +0530 Subject: [PATCH 739/781] Create Fibonacci Series In C++ --- Fibonacci Series In C++ | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Fibonacci Series In C++ diff --git a/Fibonacci Series In C++ b/Fibonacci Series In C++ new file mode 100644 index 00000000..3950198c --- /dev/null +++ b/Fibonacci Series In C++ @@ -0,0 +1,21 @@ +//Fibonacci Series using Recursion +#include +using namespace std; + +int fib(int n) +{ + if (n <= 1) + return n; + return fib(n-1) + fib(n-2); +} + +int main () +{ + int n = 9; + cout << fib(n); + getchar(); + return 0; +} + +// This code is contributed +// by Akanksha Rai From 1727254e66a49dd53b08c36c4229f22a98272391 Mon Sep 17 00:00:00 2001 From: Namit Varshney <44611770+NamitVarshney@users.noreply.github.com> Date: Mon, 19 Oct 2020 00:30:43 +0530 Subject: [PATCH 740/781] Create Replace all 0(s) with 5(s) in user accepted number This is a python code for a program where a user enters a number and the job of the code is to convert all 0(s) to 5(s) in that number and print that number. --- Replace all 0(s) with 5(s) in user accepted number | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Replace all 0(s) with 5(s) in user accepted number diff --git a/Replace all 0(s) with 5(s) in user accepted number b/Replace all 0(s) with 5(s) in user accepted number new file mode 100644 index 00000000..f88bba57 --- /dev/null +++ b/Replace all 0(s) with 5(s) in user accepted number @@ -0,0 +1,8 @@ +number = input('Enter a number: ') +lis = [int(digit) for digit in number] +for i in lis: + if i == 0: + i = 5 + print(i, end="") + else: + print(i, end="") From a24df765e19c5fdb2cc5e32da5b25b4d86a126e5 Mon Sep 17 00:00:00 2001 From: Rohan Sharma Sitoula <48614315+lunatic-rohan@users.noreply.github.com> Date: Mon, 19 Oct 2020 00:55:30 +0545 Subject: [PATCH 741/781] Calcii.cs A simple calculator made using C# that performs all the arithmetic operations. --- Calciii.cs | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 Calciii.cs diff --git a/Calciii.cs b/Calciii.cs new file mode 100644 index 00000000..728563dc --- /dev/null +++ b/Calciii.cs @@ -0,0 +1,94 @@ +//Simple Calculator using c# that performs all the arithmetic operations +using System; + +namespace Calculator + +{ + + class Program + + { + + static void Main(string[] args) + + { + + // Declare variables and then initialize to zero. + + int num1 = 0; int num2 = 0; + + // Display title as the C# console calculator app. + + Console.WriteLine("Console Calculator in C#\r"); + + Console.WriteLine("------------------------\n"); + + // Ask the user to type the first number. + + Console.WriteLine("Type a number, and then press Enter"); + + num1 = Convert.ToInt32(Console.ReadLine()); + + // Ask the user to type the second number. + + Console.WriteLine("Type another number, and then press Enter"); + + num2 = Convert.ToInt32(Console.ReadLine()); + + // Ask the user to choose an option. + + Console.WriteLine("Choose an option from the following list:"); + + Console.WriteLine("\ta - Add"); + + Console.WriteLine("\ts - Subtract"); + + Console.WriteLine("\tm - Multiply"); + + Console.WriteLine("\td - Divide"); + + Console.Write("Your option? "); + + // Use a switch statement to do the math. + + switch (Console.ReadLine()) + + { + + case "a": + + Console.WriteLine($"Your result: {num1} + {num2} = " + (num1 + num2)); + + break; + + case "s": + + Console.WriteLine($"Your result: {num1} - {num2} = " + (num1 - num2)); + + break; + + case "m": + + Console.WriteLine($"Your result: {num1} * {num2} = " + (num1 * num2)); + + break; + + case "d": + + Console.WriteLine($"Your result: {num1} / {num2} = " + (num1 / num2)); + + break; + + } + + // Wait for the user to respond before closing. + + Console.Write("Press any key to close the Calculator console app..."); + + Console.ReadKey(); + + } + + } + +} From 466f6fda4650226d1e0beedc7906e591cc970967 Mon Sep 17 00:00:00 2001 From: Namit Varshney <44611770+NamitVarshney@users.noreply.github.com> Date: Mon, 19 Oct 2020 00:41:09 +0530 Subject: [PATCH 742/781] Create Wave Print in 2D-Array This is a C++ Code for which a 2D array is used to print in an alternate (wave-like) pattern without using any STL. --- Wave Print in 2D-Array | 61 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Wave Print in 2D-Array diff --git a/Wave Print in 2D-Array b/Wave Print in 2D-Array new file mode 100644 index 00000000..d72cd6ab --- /dev/null +++ b/Wave Print in 2D-Array @@ -0,0 +1,61 @@ +/* +1 4 7 10 1 6 7 12 +2 5 8 11 => 2 5 8 11 +3 6 9 12 3 4 9 10 +*/ + + +#include +using namespace std; + +int main() +{ + int arr[20][20], row, col; + int i, j; + cout<<"Enter the size of 2D-ARRAY row-wise: \n"; + cin>>row; + cout<<"Enter the size of 2D-ARRAY column-wise: \n"; + cin>>col; + + cout<<"Enter the values for 2D-ARRAY: \n"; + for(i = 0; i < row; i++) + { + for(j = 0; j < col; j++) + { + cout<<"arr["<>arr[i][j]; + } + } + for(j = 0; j < col; j++) + { + for(i = 0; i < row; i++) + { + cout<= 0; i--) + { + cout< Date: Mon, 19 Oct 2020 00:50:17 +0530 Subject: [PATCH 743/781] Create Spiral Print of a 2D Array In this Code I'm printing a 2D Array in Spiral fashion, i.e Printing Odd rows normally and then Even rows in opposite order (i.e from last column to first column) and continuing till the last row. --- Spiral Print of a 2D Array | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Spiral Print of a 2D Array diff --git a/Spiral Print of a 2D Array b/Spiral Print of a 2D Array new file mode 100644 index 00000000..99be1cc7 --- /dev/null +++ b/Spiral Print of a 2D Array @@ -0,0 +1,72 @@ +/*Traverse the 2d array in spiral. OUTPUT + + ----->1 2 3 4----> 1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10 + <----5 6 7 8 <----- => + ----->9 10 11 12----> + <----13 14 15 16<----- + +*/ + +#include +using namespace std; + + +void spiral_print(int arr[20][20], int row, int col) +{ + int i; + int start_row = 0; + int start_col = 0; + int end_row = row - 1; + int end_col = col - 1; + + while(start_row <= end_row && start_col <= end_col) + { + + // First Row + for (int i = start_col; i <= end_col; i++) + cout << arr[start_row][i]<<" "; + start_row++; + + // + for (int i = start_row; i <= end_row; i++) + cout< start_row) + { + for(i = end_col; i >= start_col; i--) + cout< start_col) + { + for(i = end_row; i >= start_row; i--) + cout << arr[i][start_col]<<" "; + start_col++; + } + } +} +int main() +{ +int arr[20][20], row, col; + int i, j; + cout<<"Enter the size of 2D-ARRAY row-wise: \n"; + cin>>row; + cout<<"Enter the size of 2D-ARRAY column-wise: \n"; + cin>>col; + + cout<<"Enter the values for 2D-ARRAY: \n"; + for(i = 0; i < row; i++) + { + for(j = 0; j < col; j++) + { + cout<<"arr["<>arr[i][j]; + } + } + + spiral_print(arr, row, col); +} From 7c6f25e786fe523e12dc758b25b322df44ed5a8d Mon Sep 17 00:00:00 2001 From: Namit Varshney <44611770+NamitVarshney@users.noreply.github.com> Date: Mon, 19 Oct 2020 00:54:11 +0530 Subject: [PATCH 744/781] Create Finding nth root of a number using C++. A tricky but not tough, this is the code implementation of nth root of a number using C++. --- Finding nth root of a number using C++. | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Finding nth root of a number using C++. diff --git a/Finding nth root of a number using C++. b/Finding nth root of a number using C++. new file mode 100644 index 00000000..8e2a3f6e --- /dev/null +++ b/Finding nth root of a number using C++. @@ -0,0 +1,33 @@ +/* + +Nth root means that, finding a nth root of a number, like 4th root of 625 is 5, 3rd root of 125 is 5, etc + + +*/ +#include +#include +using namespace std; + +int main() +{ + int i, pre, root, trex; + float num, ans = 0.0, inc = 1.0; + cout << "Enter the number to get it's nth root: "; + cin >>num; + cout << "Enter the 'n' value of root: "; + cin >>root; + cout << "Enter the precision for answer: "; + cin >> pre; + + for(i = 1; i <= pre; i++) + { + while((pow(ans, root)) <= num) + { + ans = ans + inc; + } + ans = ans - inc; + inc = inc/10; + } + cout <<"The "< Date: Mon, 19 Oct 2020 01:13:52 +0530 Subject: [PATCH 745/781] Create Program to check triangle is equilateral, isosceles ot scalene Program to check triangle is equilateral, isosceles ot scalene --- ...angle is equilateral, isosceles ot scalene | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Program to check triangle is equilateral, isosceles ot scalene diff --git a/Program to check triangle is equilateral, isosceles ot scalene b/Program to check triangle is equilateral, isosceles ot scalene new file mode 100644 index 00000000..b6f7226a --- /dev/null +++ b/Program to check triangle is equilateral, isosceles ot scalene @@ -0,0 +1,23 @@ + +# Function to check if the triangle +# is equilateral or isosceles or scalene +def checkTriangle(x, y, z): + + # _Check for equilateral triangle + if x == y == z: + print("Equilateral Triangle") + + # Check for isoceles triangle + elif x == y or y == z or z == x: + print("Isoceles Triangle") + + # Otherwise scalene triangle + else: + print("Scalene Triangle") + + +x = 8 +y = 7 +z = 9 + +checkTriangle(x, y, z) From de36481ebe04854f243075de256a8763a1ba1ca0 Mon Sep 17 00:00:00 2001 From: sujoypal51 <70856336+sujoypal51@users.noreply.github.com> Date: Mon, 19 Oct 2020 01:17:18 +0530 Subject: [PATCH 746/781] Create Program to print ASCII value of given character with python Program to print ASCII value of given character with python --- ...m to print ASCII value of given character with python | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Program to print ASCII value of given character with python diff --git a/Program to print ASCII value of given character with python b/Program to print ASCII value of given character with python new file mode 100644 index 00000000..20166dff --- /dev/null +++ b/Program to print ASCII value of given character with python @@ -0,0 +1,9 @@ +# Python program to print +# ASCII Value of Character + +# In c we can assign different +# characters of which we want ASCII value + +c = 'g' +# print the ASCII value of assigned character in c +print("The ASCII value of '" + c + "' is", ord(c)) From 064bfed7b1c0a236ca6bec83419e9dd703ee4f9c Mon Sep 17 00:00:00 2001 From: sujoypal51 <70856336+sujoypal51@users.noreply.github.com> Date: Mon, 19 Oct 2020 01:19:52 +0530 Subject: [PATCH 747/781] Create Program to convert binary to octal number with python Program to convert binary to octal number with python --- ...convert binary to octal number with python | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 Program to convert binary to octal number with python diff --git a/Program to convert binary to octal number with python b/Program to convert binary to octal number with python new file mode 100644 index 00000000..89b6528f --- /dev/null +++ b/Program to convert binary to octal number with python @@ -0,0 +1,71 @@ +# Python3 implementation to convert a binary number +# to octal number + +# function to create map between binary +# number and its equivalent octal +def createMap(bin_oct_map): + bin_oct_map["000"] = '0' + bin_oct_map["001"] = '1' + bin_oct_map["010"] = '2' + bin_oct_map["011"] = '3' + bin_oct_map["100"] = '4' + bin_oct_map["101"] = '5' + bin_oct_map["110"] = '6' + bin_oct_map["111"] = '7' + +# Function to find octal equivalent of binary +def convertBinToOct(bin): + l = len(bin) + + # length of string before '.' + t = -1 + if '.' in bin: + t = bin.index('.') + len_left = t + else: + len_left = l + + # add min 0's in the beginning to make + # left substring length divisible by 3 + for i in range(1, (3 - len_left % 3) % 3 + 1): + bin = '0' + bin + + # if decimal point exists + if (t != -1): + + # length of string after '.' + len_right = l - len_left - 1 + + # add min 0's in the end to make right + # substring length divisible by 3 + for i in range(1, (3 - len_right % 3) % 3 + 1): + bin = bin + '0' + + # create dictionary between binary and its + # equivalent octal code + bin_oct_map = {} + createMap(bin_oct_map) + i = 0 + octal = "" + + while (True) : + + # one by one extract from left, substring + # of size 3 and add its octal code + octal += bin_oct_map[bin[i:i + 3]] + i += 3 + if (i == len(bin)): + break + + # if '.' is encountered add it to result + if (bin[i] == '.'): + octal += '.' + i += 1 + + # required octal number + return octal + +# Driver Code +bin = "1111001010010100001.010110110011011" +print("Octal number = ", + convertBinToOct(bin)) From 3d0b39ad452ed6935bdd44779abca46d4d1acd97 Mon Sep 17 00:00:00 2001 From: Allan Montilla Date: Sun, 18 Oct 2020 19:59:34 -0500 Subject: [PATCH 748/781] find_lenght_of_a_string_length_in_javascript.js Create a program to find lenght of a string length in javascript.js --- ...lenght of a string length in javascript.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Create a program to find lenght of a string length in javascript.js diff --git a/Create a program to find lenght of a string length in javascript.js b/Create a program to find lenght of a string length in javascript.js new file mode 100644 index 00000000..3f8055cd --- /dev/null +++ b/Create a program to find lenght of a string length in javascript.js @@ -0,0 +1,22 @@ + + + + + + Program to find string length + + +

Program to find string length

+String: + + + + From 44a519e1b8caeb03dc91330df90120ce0772f02b Mon Sep 17 00:00:00 2001 From: Abhishek Kumar <59703066+0031abbhishek@users.noreply.github.com> Date: Mon, 19 Oct 2020 08:40:05 +0530 Subject: [PATCH 749/781] Create Length of String Here i have directly used built in function it will somehow save some of the lines and time complexity. --- Length of String | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Length of String diff --git a/Length of String b/Length of String new file mode 100644 index 00000000..5003ff61 --- /dev/null +++ b/Length of String @@ -0,0 +1,8 @@ +#include +using namespace std; +int main() +{ +string s="HELLO WORLD"; +int len=s.length(); +cout< Date: Mon, 19 Oct 2020 09:34:03 +0530 Subject: [PATCH 750/781] Update Binary Search Tree updated optimized binary search tree code in python --- Binary Search Tree | 153 ++++++++++----------------------------------- 1 file changed, 32 insertions(+), 121 deletions(-) diff --git a/Binary Search Tree b/Binary Search Tree index 46c9a37b..2bfdfc5c 100644 --- a/Binary Search Tree +++ b/Binary Search Tree @@ -1,128 +1,39 @@ -#include +# Python3 Program for recursive binary search. -using namespace std; -class treenode{ -public: - int value; - treenode* left; - treenode* right; - - - treenode() - { - value=0; - left=NULL; - right=NULL; - } - treenode(int v) - { - value =v; - left = NULL; - right =NULL; - } -}; +# Returns index of x in arr if present, else -1 +def binarySearch (arr, l, r, x): -class bst{ -public: - treenode* root; - bst() - { - root =NULL; - } - - bool isEmpty(){ - if(root == NULL) - return true; - else - return false; - } - - void insert(treenode* new_node) - { - if(root == NULL) - root = new_node; - else{ - treenode* temp =root; - while(temp!=NULL) - { - if(new_node->value == temp->value) - return; - else if((new_node->value value)&& (temp->left==NULL)) - { - temp->left = new_node; - break; - } - else if((new_node->value > temp->value) && (temp->right ==NULL)) - { - temp->right =new_node; - break; - } - else{ - temp =temp->right; - } - } - } - } - - void disp(treenode* root){ - - if(root ==NULL) - return; - cout<value<left); - disp(root->right); - } -}; + # Check base case + if r >= l: + mid = l + (r - l) // 2 + # If element is present at the middle itself + if arr[mid] == x: + return mid + + # If element is smaller than mid, then it + # can only be present in left subarray + elif arr[mid] > x: + return binarySearch(arr, l, mid-1, x) + # Else the element can only be present + # in right subarray + else: + return binarySearch(arr, mid + 1, r, x) + else: + # Element is not present in the array + return -1 -int main(){ -bst obj; - - int option,val; - do{ - cout<<"Selet operation: (press 0 t exit)"<>option; - - treenode *new_node = new treenode(); - switch(option){ - - case 0: - break; - case 1: - cout<<"insert"<>val; - new_node->value=val; - obj.insert(new_node); - cout< Date: Mon, 19 Oct 2020 09:40:07 +0530 Subject: [PATCH 751/781] Update Program to add two numbers in pyhton decreased number of lines. --- Program to add two numbers in pyhton | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Program to add two numbers in pyhton b/Program to add two numbers in pyhton index 01e1e135..401a4da5 100644 --- a/Program to add two numbers in pyhton +++ b/Program to add two numbers in pyhton @@ -1,6 +1,4 @@ x = input("Type a number: ") y = input("Type another number: ") - sum = int(x) + int(y) - -print("The sum is: ", sum) +print("The sum is: ",sum) From 7f73192e1854a9ed3e099fca1f073ab9d5db65fe Mon Sep 17 00:00:00 2001 From: "Charlie : The Hacker" <42512633+CharlieTheHack1@users.noreply.github.com> Date: Mon, 19 Oct 2020 09:49:15 +0530 Subject: [PATCH 752/781] Create Program to print Fibonnaci Series new --- Program to print Fibonnaci Series new | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Program to print Fibonnaci Series new diff --git a/Program to print Fibonnaci Series new b/Program to print Fibonnaci Series new new file mode 100644 index 00000000..a6d632f2 --- /dev/null +++ b/Program to print Fibonnaci Series new @@ -0,0 +1,39 @@ +# Program to display the Fibonacci sequence up to n-th term + +nterms = int(input("How many terms? ")) + +# first two terms + +n1, n2 = 0, 1 + +count = 0 + +# check if the number of terms is valid + +if nterms <= 0: + + print("Please enter a positive integer") + +elif nterms == 1: + + print("Fibonacci sequence upto",nterms,":") + + print(n1) + +else: + + print("Fibonacci sequence:") + + while count < nterms: + + print(n1) + + nth = n1 + n2 + + # update values + + n1 = n2 + + n2 = nth + + count += 1 From bd69e0e8aa18d35bf0ea6ace995c1c1333f13d51 Mon Sep 17 00:00:00 2001 From: anXcode <73054255+anXcode@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:23:18 +0530 Subject: [PATCH 753/781] Create ProgramToCountVowelsInAStringByAnmol.cpp Added the optimized code of the Program to count vowels in a string by Iterative method --- ProgramToCountVowelsInAStringByAnmol.cpp | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ProgramToCountVowelsInAStringByAnmol.cpp diff --git a/ProgramToCountVowelsInAStringByAnmol.cpp b/ProgramToCountVowelsInAStringByAnmol.cpp new file mode 100644 index 00000000..aa755821 --- /dev/null +++ b/ProgramToCountVowelsInAStringByAnmol.cpp @@ -0,0 +1,32 @@ +// C++ program to count vowels in a string +#include +using namespace std; + +// Function to check the Vowel +bool isVowel(char ch) +{ + ch = toupper(ch); + return (ch=='A' || ch=='E' || ch=='I' || + ch=='O' || ch=='U'); +} + +// Returns count of vowels in str +int countVowels(string str) +{ + int count = 0; + for (int i=0; i Date: Mon, 19 Oct 2020 10:25:24 +0530 Subject: [PATCH 754/781] Rename ProgramToCountVowelsInAStringByAnmol.cpp to ProgramToCountVowelsInAStringByItretive.cpp --- ...ringByAnmol.cpp => ProgramToCountVowelsInAStringByItretive.cpp | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ProgramToCountVowelsInAStringByAnmol.cpp => ProgramToCountVowelsInAStringByItretive.cpp (100%) diff --git a/ProgramToCountVowelsInAStringByAnmol.cpp b/ProgramToCountVowelsInAStringByItretive.cpp similarity index 100% rename from ProgramToCountVowelsInAStringByAnmol.cpp rename to ProgramToCountVowelsInAStringByItretive.cpp From cb22b51cfb04243030cceaa4202090a034645227 Mon Sep 17 00:00:00 2001 From: SurbhiPal972 <73024546+SurbhiPal972@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:29:55 +0530 Subject: [PATCH 755/781] Create A string is palindrome or not Optimized code to check whether a string is palindrome or not. --- A string is palindrome or not | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 A string is palindrome or not diff --git a/A string is palindrome or not b/A string is palindrome or not new file mode 100644 index 00000000..5dac8be4 --- /dev/null +++ b/A string is palindrome or not @@ -0,0 +1,28 @@ +#include +#include + +int main(){ + char string1[20]; + int i, length; + int flag = 0; + + printf("Enter a string:"); + scanf("%s", string1); + + length = strlen(string1); + + for(i=0;i < length ;i++){ + if(string1[i] != string1[length-i-1]){ + flag = 1; + break; + } +} + + if (flag) { + printf("%s is not a palindrome", string1); + } + else { + printf("%s is a palindrome", string1); + } + return 0; +} From 4d586117bcae6ece4c6ab648f5dfd1b71ee3aee0 Mon Sep 17 00:00:00 2001 From: anXcode <73054255+anXcode@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:30:36 +0530 Subject: [PATCH 756/781] Create ProgramToCountVowelsInAStringRecursive.cpp Added the optimized code Program to count vowels in a string by Recursive approach --- ProgramToCountVowelsInAStringRecursive.cpp | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ProgramToCountVowelsInAStringRecursive.cpp diff --git a/ProgramToCountVowelsInAStringRecursive.cpp b/ProgramToCountVowelsInAStringRecursive.cpp new file mode 100644 index 00000000..520b164b --- /dev/null +++ b/ProgramToCountVowelsInAStringRecursive.cpp @@ -0,0 +1,31 @@ +// Recursive C++ program to count the total number of vowels using recursion +#include +using namespace std; + +// Function to check the Vowel +bool isVowel(char ch) +{ + ch = toupper(ch); + return (ch=='A' || ch=='E' || ch=='I' || + ch=='O' || ch=='U'); +} + +// to count total number of vowel from 0 to n +int countVovels(string str, int n) +{ + if (n == 1) + return isVowel(str[n-1]); + + return countVovels(str, n-1) + isVowel(str[n-1]); +} + +// Main Calling Function +int main() +{ + // string object + string str = "abc de"; + + // Total numbers of Vowel + cout << countVovels(str, str.length()) << endl; + return 0; +} From 3369e266b239c34dc652b772e40adeceab576f9b Mon Sep 17 00:00:00 2001 From: anXcode <73054255+anXcode@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:34:30 +0530 Subject: [PATCH 757/781] Create ProgramToCountVowelsInAStringByIterative.java Added the optimized code for Program to count vowels in a string by Iterative Approach in java --- ProgramToCountVowelsInAStringByIterative.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ProgramToCountVowelsInAStringByIterative.java diff --git a/ProgramToCountVowelsInAStringByIterative.java b/ProgramToCountVowelsInAStringByIterative.java new file mode 100644 index 00000000..f69686a3 --- /dev/null +++ b/ProgramToCountVowelsInAStringByIterative.java @@ -0,0 +1,31 @@ +// Java program to count vowels in a string +public class anXcode { + + // Function to check the Vowel + static boolean isVowel(char ch) + { + ch = Character.toUpperCase(ch); + return (ch=='A' || ch=='E' || ch=='I' || + ch=='O' || ch=='U'); + } + + // Returns count of vowels in str + static int countVowels(String str) + { + int count = 0; + for (int i = 0; i < str.length(); i++) + if (isVowel(str.charAt(i))) // Check for vowel + ++count; + return count; + } + + // Driver code + public static void main(String args[]) + { + //string object + String str = "abc de"; + + // Total numbers of Vowel + System.out.println(countVowels(str)); + } +} From 51fdf1287805585ea7d4e96bfc36747c749e4071 Mon Sep 17 00:00:00 2001 From: anXcode <73054255+anXcode@users.noreply.github.com> Date: Mon, 19 Oct 2020 10:36:15 +0530 Subject: [PATCH 758/781] Create ProgramToCountVowelsInAStringByRecursive.java added the optimized code for Program to count vowels in a string by Recursive Approach --- ProgramToCountVowelsInAStringByRecursive.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ProgramToCountVowelsInAStringByRecursive.java diff --git a/ProgramToCountVowelsInAStringByRecursive.java b/ProgramToCountVowelsInAStringByRecursive.java new file mode 100644 index 00000000..0f052360 --- /dev/null +++ b/ProgramToCountVowelsInAStringByRecursive.java @@ -0,0 +1,32 @@ +// Recursive Java program to count the total number of vowels using recursion +public class anXcode { + + // Function to check the Vowel + static int isVowel(char ch) + { + ch = Character.toUpperCase(ch); + if(ch=='A' || ch=='E' || ch=='I' || + ch=='O' || ch=='U') + return 1; + else return 0; + } + + // to count total number of vowel from 0 to n + static int countVowels(String str, int n) + { + if (n == 1) + return isVowel(str.charAt(n - 1)); + + return countVowels(str, n-1) + isVowel(str.charAt(n - 1)); + } + + // Main Calling Function + public static void main(String args[]) + { + //string object + String str = "abc de"; + + // Total numbers of Vowel + System.out.println(countVowels(str,str.length())); + } +} From 41060abb5f830dcbdf3e7e6deff546ae9747ff3e Mon Sep 17 00:00:00 2001 From: kchaithanya125 Date: Mon, 19 Oct 2020 11:15:09 +0530 Subject: [PATCH 759/781] Create binary search in c --- binary search in c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 binary search in c diff --git a/binary search in c b/binary search in c new file mode 100644 index 00000000..9378bd3b --- /dev/null +++ b/binary search in c @@ -0,0 +1,37 @@ +#include +int main() +{ + int c, first, last, middle, n, search, array[100]; + + printf("Enter number of elements\n"); + scanf("%d", &n); + + printf("Enter %d integers\n", n); + + for (c = 0; c < n; c++) + scanf("%d", &array[c]); + + printf("Enter value to find\n"); + scanf("%d", &search); + + first = 0; + last = n - 1; + middle = (first+last)/2; + + while (first <= last) { + if (array[middle] < search) + first = middle + 1; + else if (array[middle] == search) { + printf("%d found at location %d.\n", search, middle+1); + break; + } + else + last = middle - 1; + + middle = (first + last)/2; + } + if (first > last) + printf("Not found! %d isn't present in the list.\n", search); + + return 0; +} From 77ed3c098ea4cd19cfada94f3a16bc8745f8a9fa Mon Sep 17 00:00:00 2001 From: kchaithanya125 Date: Mon, 19 Oct 2020 11:16:20 +0530 Subject: [PATCH 760/781] Create C program to get input from a user using scanf --- C program to get input from a user using scanf | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 C program to get input from a user using scanf diff --git a/C program to get input from a user using scanf b/C program to get input from a user using scanf new file mode 100644 index 00000000..1138fd3a --- /dev/null +++ b/C program to get input from a user using scanf @@ -0,0 +1,12 @@ +#include +int main() +{ + int x; + + printf("Input an integer\n"); + scanf("%d", &x); // %d is used for an integer + + printf("The integer is: %d\n", x); + + return 0; +} From 034199378c20e18800ca6889d35d81a09d070cea Mon Sep 17 00:00:00 2001 From: kchaithanya125 Date: Mon, 19 Oct 2020 11:17:22 +0530 Subject: [PATCH 761/781] Create using if else control instructions --- using if else control instructions | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 using if else control instructions diff --git a/using if else control instructions b/using if else control instructions new file mode 100644 index 00000000..cb1c16fb --- /dev/null +++ b/using if else control instructions @@ -0,0 +1,15 @@ +#include +int main() +{ + int n; + + printf("Enter a number\n"); + scanf("%d", &n); + + if (n > 0) + printf("Greater than zero.\n"); + else + printf("Less than or equal to zero.\n"); + + return 0; +} From 3f4a9521a69839fa35268ef2a58a5c68a5904076 Mon Sep 17 00:00:00 2001 From: kchaithanya125 Date: Mon, 19 Oct 2020 11:18:48 +0530 Subject: [PATCH 762/781] Create C program to check if an integer is prime or not --- ...ram to check if an integer is prime or not | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 C program to check if an integer is prime or not diff --git a/C program to check if an integer is prime or not b/C program to check if an integer is prime or not new file mode 100644 index 00000000..7a1e602e --- /dev/null +++ b/C program to check if an integer is prime or not @@ -0,0 +1,25 @@ +#include + +int main() +{ + int n, c; + + printf("Enter a number\n"); + scanf("%d", &n); + + if (n == 2) + printf("Prime number.\n"); + else + { + for (c = 2; c <= n - 1; c++) + { + if (n % c == 0) + break; + } + if (c != n) + printf("Not prime.\n"); + else + printf("Prime number.\n"); + } + return 0; +} From dc7e53af79ae9f89442e5f4b9f31545ab522b2b6 Mon Sep 17 00:00:00 2001 From: kchaithanya125 Date: Mon, 19 Oct 2020 11:19:37 +0530 Subject: [PATCH 763/781] Create command line arguments in c --- command line arguments in c | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 command line arguments in c diff --git a/command line arguments in c b/command line arguments in c new file mode 100644 index 00000000..1abf1267 --- /dev/null +++ b/command line arguments in c @@ -0,0 +1,12 @@ +#include +int main(int argc, char *argv[]) +{ + int c; + + printf("Number of command line arguments passed: %d\n", argc); + + for (c = 0; c < argc; c++) + printf("%d argument is %s\n", c + 1, argv[c]); + + return 0; +} From de488625c457ef8de830e870bf2cd751d4b48260 Mon Sep 17 00:00:00 2001 From: GodofDaath <63976377+GodofDaath@users.noreply.github.com> Date: Mon, 19 Oct 2020 11:26:43 +0530 Subject: [PATCH 764/781] Create Array program in c --- Array program in c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 Array program in c diff --git a/Array program in c b/Array program in c new file mode 100644 index 00000000..4e02a823 --- /dev/null +++ b/Array program in c @@ -0,0 +1,20 @@ +#include +int main() +{ + int array[100], n, c; + + printf("Enter number of elements in array\n"); + scanf("%d", &n); + + printf("Enter %d elements\n", n); + + for (c = 0; c < n; c++) + scanf("%d", &array[c]); + + printf("The array elements are:\n"); + + for (c = 0; c < n; c++) + printf("%d\n", array[c]); + + return 0; +} From 49ff0429b87cf310656c3e6ba30aa28ecce64ca3 Mon Sep 17 00:00:00 2001 From: GodofDaath <63976377+GodofDaath@users.noreply.github.com> Date: Mon, 19 Oct 2020 11:27:28 +0530 Subject: [PATCH 765/781] Create function program inc --- function program inc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 function program inc diff --git a/function program inc b/function program inc new file mode 100644 index 00000000..ad9287dd --- /dev/null +++ b/function program inc @@ -0,0 +1,19 @@ +#include +void my_function(); // Declaring a function + +int main() +{ + printf("Main function.\n"); + + my_function(); // Calling the function + + printf("Back in function main.\n"); + + return 0; +} + +// Defining the function +void my_function() +{ + printf("Welcome to my function. Feel at home.\n"); +} From e96b14b7126d08a6f4f9e2f8a222d29eadaf8ad3 Mon Sep 17 00:00:00 2001 From: GodofDaath <63976377+GodofDaath@users.noreply.github.com> Date: Mon, 19 Oct 2020 11:28:17 +0530 Subject: [PATCH 766/781] Create Using comments in a program in c --- Using comments in a program in c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Using comments in a program in c diff --git a/Using comments in a program in c b/Using comments in a program in c new file mode 100644 index 00000000..2675d09b --- /dev/null +++ b/Using comments in a program in c @@ -0,0 +1,18 @@ +#include + +int main() +{ + // Single line comment in a C program + + printf("Writing comments is very useful.\n"); + + /* + * Multi-line comment syntax + * Comments help us to understand a program later easily. + * Will you write comments while writing programs? + */ + + printf("Good luck C programmer.\n"); + + return 0; +} From 8520bf9f9639b0ead93ddd3f27e8c15a9a385b42 Mon Sep 17 00:00:00 2001 From: GodofDaath <63976377+GodofDaath@users.noreply.github.com> Date: Mon, 19 Oct 2020 11:29:21 +0530 Subject: [PATCH 767/781] Create using structures in C programming --- using structures in C programming | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 using structures in C programming diff --git a/using structures in C programming b/using structures in C programming new file mode 100644 index 00000000..0abfb534 --- /dev/null +++ b/using structures in C programming @@ -0,0 +1,20 @@ +#include +#include +struct game +{ + char game_name[50]; + int number_of_players; +}; // Note the semicolon + +int main() +{ + struct game g; + + strcpy(g.game_name, "Cricket"); + g.number_of_players = 11; + + printf("Name of game: %s\n", g.game_name); + printf("Number of players: %d\n", g.number_of_players); + + return 0; +} From bb34fdccde838e1876d94350dfc0069bdfb20421 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 14:07:05 +0530 Subject: [PATCH 768/781] elements sum in array code for sum of elements in array in c. --- elements sum in array | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 elements sum in array diff --git a/elements sum in array b/elements sum in array new file mode 100644 index 00000000..b0efbb78 --- /dev/null +++ b/elements sum in array @@ -0,0 +1,23 @@ +#include + +// function to return sum of elements +// in an array of size n +int sum(int arr[], int n) +{ + int sum = 0; // initialize sum + + // Iterate through all elements + // and add them to sum + for (int i = 0; i < n; i++) + sum += arr[i]; + + return sum; +} + +int main() +{ + int arr[] = {12, 3, 4, 15}; + int n = sizeof(arr) / sizeof(arr[0]); + printf("Sum of given array is %d", sum(arr, n)); + return 0; +} From 7d6b65c8e29d19c34480f3b0cb7e402c6e35edb4 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 20:22:39 +0530 Subject: [PATCH 769/781] factorial of no factorial of nos in c. --- factorial of numbers | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 factorial of numbers diff --git a/factorial of numbers b/factorial of numbers new file mode 100644 index 00000000..07b09ea2 --- /dev/null +++ b/factorial of numbers @@ -0,0 +1,19 @@ +#include +int main() { + int n, i; + unsigned long long fact = 1; + printf("Enter an integer: "); + scanf("%d", &n); + + // shows error if the user enters a negative integer + if (n < 0) + printf("Error! Factorial of a negative number doesn't exist."); + else { + for (i = 1; i <= n; ++i) { + fact *= i; + } + printf("Factorial of %d = %llu", n, fact); + } + + return 0; +} From 28237b6b2a2e32587c2deaac36b04a47174b2aa7 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 20:28:35 +0530 Subject: [PATCH 770/781] power of number power of number in c. --- create power of numbers | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 create power of numbers diff --git a/create power of numbers b/create power of numbers new file mode 100644 index 00000000..e7d59525 --- /dev/null +++ b/create power of numbers @@ -0,0 +1,16 @@ +#include +int main() { + int base, exp; + long long result = 1; + printf("Enter a base number: "); + scanf("%d", &base); + printf("Enter an exponent: "); + scanf("%d", &exp); + + while (exp != 0) { + result *= base; + --exp; + } + printf("Answer = %lld", result); + return 0; +} From f2428b3b30e1075ebe6d77fa24de5e03c77e4a63 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 20:35:59 +0530 Subject: [PATCH 771/781] length of the string length of the string in c --- find the length of the string | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 find the length of the string diff --git a/find the length of the string b/find the length of the string new file mode 100644 index 00000000..a20fd7c3 --- /dev/null +++ b/find the length of the string @@ -0,0 +1,10 @@ +#include +int main() { + char s[] = "Programming is fun"; + int i; + + for (i = 0; s[i] != '\0'; ++i); + + printf("Length of the string: %d", i); + return 0; +} From 11c1087d7862add63ad392d2f887d83a65ed8522 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 20:49:21 +0530 Subject: [PATCH 772/781] array reverse array reverse in c --- array reverse | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 array reverse diff --git a/array reverse b/array reverse new file mode 100644 index 00000000..d53801a3 --- /dev/null +++ b/array reverse @@ -0,0 +1,38 @@ +// Iterative C program to reverse an array +#include + +/* Function to reverse arr[] from start to end*/ +void rvereseArray(int arr[], int start, int end) +{ + int temp; + while (start < end) + { + temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } +} + +/* Utility that prints out an array on a line */ +void printArray(int arr[], int size) +{ + int i; + for (i=0; i < size; i++) + printf("%d ", arr[i]); + + printf("\n"); +} + +/* Driver function to test above functions */ +int main() +{ + int arr[] = {1, 2, 3, 4, 5, 6}; + int n = sizeof(arr) / sizeof(arr[0]); + printArray(arr, n); + rvereseArray(arr, 0, n-1); + printf("Reversed array is \n"); + printArray(arr, n); + return 0; +} From 3f1b06d294054068120233e215fd6a00c79570e3 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 20:57:12 +0530 Subject: [PATCH 773/781] binary to decimal converter binary to decimal converter in c --- binary to decimal converter | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 binary to decimal converter diff --git a/binary to decimal converter b/binary to decimal converter new file mode 100644 index 00000000..aa3e14fd --- /dev/null +++ b/binary to decimal converter @@ -0,0 +1,20 @@ +#include +int convert(long long n); +int main() { + long long n; + printf("Enter a binary number: "); + scanf("%lld", &n); + printf("%lld in binary = %d in decimal", n, convert(n)); + return 0; +} + +int convert(long long n) { + int dec = 0, i = 0, rem; + while (n != 0) { + rem = n % 10; + n /= 10; + dec += rem * pow(2, i); + ++i; + } + return dec; +} From a01b50ea141c4bd1075ec9e9e8c01ada1b2b34d5 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 21:07:43 +0530 Subject: [PATCH 774/781] multiplication of matrices multiplication of matrices in c --- multiplication of matrices | 84 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 multiplication of matrices diff --git a/multiplication of matrices b/multiplication of matrices new file mode 100644 index 00000000..0dba24e7 --- /dev/null +++ b/multiplication of matrices @@ -0,0 +1,84 @@ +#include + +// function to get matrix elements entered by the user +void getMatrixElements(int matrix[][10], int row, int column) { + + printf("\nEnter elements: \n"); + + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("Enter a%d%d: ", i + 1, j + 1); + scanf("%d", &matrix[i][j]); + } + } +} + +// function to multiply two matrices +void multiplyMatrices(int first[][10], + int second[][10], + int result[][10], + int r1, int c1, int r2, int c2) { + + // Initializing elements of matrix mult to 0. + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + result[i][j] = 0; + } + } + + // Multiplying first and second matrices and storing it in result + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + for (int k = 0; k < c1; ++k) { + result[i][j] += first[i][k] * second[k][j]; + } + } + } +} + +// function to display the matrix +void display(int result[][10], int row, int column) { + + printf("\nOutput Matrix:\n"); + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("%d ", result[i][j]); + if (j == column - 1) + printf("\n"); + } + } +} + +int main() { + int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2; + printf("Enter rows and column for the first matrix: "); + scanf("%d %d", &r1, &c1); + printf("Enter rows and column for the second matrix: "); + scanf("%d %d", &r2, &c2); + + // Taking input until + // 1st matrix columns is not equal to 2nd matrix row + while (c1 != r2) { + printf("Error! Enter rows and columns again.\n"); + printf("Enter rows and columns for the first matrix: "); + scanf("%d%d", &r1, &c1); + printf("Enter rows and columns for the second matrix: "); + scanf("%d%d", &r2, &c2); + } + + // get elements of the first matrix + getMatrixElements(first, r1, c1); + + // get elements of the second matrix + getMatrixElements(second, r2, c2); + + // multiply two matrices. + multiplyMatrices(first, second, result, r1, c1, r2, c2); + + // display the result + display(result, r1, c2); + + return 0; +} + + From c293e192b2e0801457f5b56cb6727503d820ec53 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 21:17:29 +0530 Subject: [PATCH 775/781] matrix multiplication 2D matrix multiplication in c. --- matrix multiplication 2D | 108 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 matrix multiplication 2D diff --git a/matrix multiplication 2D b/matrix multiplication 2D new file mode 100644 index 00000000..311eb90a --- /dev/null +++ b/matrix multiplication 2D @@ -0,0 +1,108 @@ +#include + +// function to get matrix elements entered by the user +void getMatrixElements(int matrix[][10], int row, int column) { + + printf("\nEnter elements: \n"); + + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("Enter a%d%d: ", i + 1, j + 1); + scanf("%d", &matrix[i][j]); + } + } +} + +// function to multiply two matrices +void multiplyMatrices(int first[][10], + int second[][10], + int result[][10], + int r1, int c1, int r2, int c2) { + + // Initializing elements of matrix mult to 0. + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + result[i][j] = 0; + } + } + + // Multiplying first and second matrices and storing it in result + for (int i = 0; i < r1; ++i) { + for (int j = 0; j < c2; ++j) { + for (int k = 0; k < c1; ++k) { + result[i][j] += first[i][k] * second[k][j]; + } + } + } +} + +// function to display the matrix +void display(int result[][10], int row, int column) { + + printf("\nOutput Matrix:\n"); + for (int i = 0; i < row; ++i) { + for (int j = 0; j < column; ++j) { + printf("%d ", result[i][j]); + if (j == column - 1) + printf("\n"); + } + } +} + +int main() { + int first[10][10], second[10][10], result[10][10], r1, c1, r2, c2; + printf("Enter rows and column for the first matrix: "); + scanf("%d %d", &r1, &c1); + printf("Enter rows and column for the second matrix: "); + scanf("%d %d", &r2, &c2); + + // Taking input until + // 1st matrix columns is not equal to 2nd matrix row + while (c1 != r2) { + printf("Error! Enter rows and columns again.\n"); + printf("Enter rows and columns for the first matrix: "); + scanf("%d%d", &r1, &c1); + printf("Enter rows and columns for the second matrix: "); + scanf("%d%d", &r2, &c2); + } + + // get elements of the first matrix + getMatrixElements(first, r1, c1); + + // get elements of the second matrix + getMatrixElements(second, r2, c2); + + // multiply two matrices. + multiplyMatrices(first, second, result, r1, c1, r2, c2); + + // display the result + display(result, r1, c2); + + return 0; +} +Output + +Enter rows and column for the first matrix: 2 +3 +Enter rows and column for the second matrix: 3 +2 + +Enter elements: +Enter a11: 2 +Enter a12: -3 +Enter a13: 4 +Enter a21: 53 +Enter a22: 3 +Enter a23: 5 + +Enter elements: +Enter a11: 3 +Enter a12: 3 +Enter a21: 5 +Enter a22: 0 +Enter a31: -3 +Enter a32: 4 + +Output Matrix: +-21 22 +159 179 From 4ba8c28d13944125f8c5c9d43f0a0a21f8170438 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 21:22:34 +0530 Subject: [PATCH 776/781] Update ProgramToConvertBinaryToDecimalNumber.cpp --- .../ProgramToConvertBinaryToDecimalNumber.cpp | 54 +++++++------------ 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp index d3691328..60a4b6b8 100644 --- a/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp +++ b/Program to convert binary to decimal number/ProgramToConvertBinaryToDecimalNumber.cpp @@ -1,35 +1,19 @@ -// C++ program to convert binary to decimal -#include -using namespace std; - -// Function to convert binary to decimal -int binaryToDecimal(int n) -{ - int num = n; - int dec_value = 0; - - // Initializing base value to 1, i.e 2^0 - int base = 1; - - int temp = num; - while (temp) { - int last_digit = temp % 10; - temp = temp / 10; - - dec_value += last_digit * base; - - base = base * 2; - } - - return dec_value; -} - -// Driver program to test above function -int main() -{ - int num; - cout<<"Enter binary no. : "; - cin>>num; - - cout << binaryToDecimal(num) << endl; -} +#include +#include +int main(){ +int a[10],n,i; +system ("cls"); +printf("Enter the number to convert: "); +scanf("%d",&n); +for(i=0;n>0;i++) +{ +a[i]=n%2; +n=n/2; +} +printf("\nBinary of Given Number is="); +for(i=i-1;i>=0;i--) +{ +printf("%d",a[i]); +} +return 0; +} From af343ae351edc84287f6ad581d09642e08ba8d84 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 21:44:42 +0530 Subject: [PATCH 777/781] binary to octal binary to octal in c --- binary to octal | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 binary to octal diff --git a/binary to octal b/binary to octal new file mode 100644 index 00000000..96cf36b9 --- /dev/null +++ b/binary to octal @@ -0,0 +1,30 @@ +#include +#include +int convert(long long bin); +int main() { + long long bin; + printf("Enter a binary number: "); + scanf("%lld", &bin); + printf("%lld in binary = %d in octal", bin, convert(bin)); + return 0; +} + +int convert(long long bin) { + int oct = 0, dec = 0, i = 0; + + // converting binary to decimal + while (bin != 0) { + dec += (bin % 10) * pow(2, i); + ++i; + bin /= 10; + } + i = 1; + + // converting to decimal to octal + while (dec != 0) { + oct += (dec % 8) * i; + dec /= 8; + i *= 10; + } + return oct; +} From 2a4571aeda7177d74eb503aa02a672d09a0e3048 Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 22:13:26 +0530 Subject: [PATCH 778/781] fibonacci series to find fabonacci series --- fibonacci series in c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 fibonacci series in c diff --git a/fibonacci series in c b/fibonacci series in c new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/fibonacci series in c @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 91d22bc2a8cf72a06671ed32b7b0cb59edd7b61e Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 22:18:13 +0530 Subject: [PATCH 779/781] Create series in c to find fabonacci series --- series in c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 series in c diff --git a/series in c b/series in c new file mode 100644 index 00000000..d3375464 --- /dev/null +++ b/series in c @@ -0,0 +1,16 @@ +#include +int main() { + int i, n, t1 = 0, t2 = 1, nextTerm; + printf("Enter the number of terms: "); + scanf("%d", &n); + printf("Fibonacci Series: "); + + for (i = 1; i <= n; ++i) { + printf("%d, ", t1); + nextTerm = t1 + t2; + t1 = t2; + t2 = nextTerm; + } + + return 0; +} From 9af7842e8c3acbb0ebdfc7331c4aababea1dea2a Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Mon, 19 Oct 2020 22:26:02 +0530 Subject: [PATCH 780/781] simple webpage --- css/style.css | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 css/style.css diff --git a/css/style.css b/css/style.css new file mode 100644 index 00000000..ceb57611 --- /dev/null +++ b/css/style.css @@ -0,0 +1,50 @@ +* +{ + margin: 0px; + padding: 0px; + font-family: century Gothic; + } + + header { + background-image: url(../2.jpg); + height: 100vh; + background-size: cover; + background-position: center; +} + +ul{ + float: right; + list-style-type: none; + margin-top: 25px; +} + +ul li{ + display: inline-block; +} + +ul li a{ + text-decoration: none; + color: #000; + padding: 5px 20px; + border: 1px solid #000; + transition: 0.6s ease; + } + ul li a:hover{ + background-color: #fff; + color: #000; + } + +.title{ + position: absolute; + top: 50%; + left: 50%; + transform: translate(-50%,-50%); +} +.title h1{ + color: #000; + font-size: 70px; +} + +ul li ul li{ + display: none; +} \ No newline at end of file From 9a34856d5980fba3105edcf77f091839f642306f Mon Sep 17 00:00:00 2001 From: Shiwangi1015 <63739564+shiwangi123456@users.noreply.github.com> Date: Tue, 20 Oct 2020 00:26:58 +0530 Subject: [PATCH 781/781] Create Multiplication of matrix Multiplication of matrix in c --- Multiplication of matrix | 49 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Multiplication of matrix diff --git a/Multiplication of matrix b/Multiplication of matrix new file mode 100644 index 00000000..736f5400 --- /dev/null +++ b/Multiplication of matrix @@ -0,0 +1,49 @@ +#include +#include +int main(){ +int a[10][10],b[10][10],mul[10][10],r,c,i,j,k; +system("cls"); +printf("enter the number of row="); +scanf("%d",&r); +printf("enter the number of column="); +scanf("%d",&c); +printf("enter the first matrix element=\n"); +for(i=0;i