diff --git a/C++/Program -1/Program.cpp b/C++/Program -1/Program.cpp new file mode 100644 index 00000000..9144cf64 --- /dev/null +++ b/C++/Program -1/Program.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; +#include +int main() { + cout<<"Enter the number of elements "<>n;//Input the size of array + int arr[n]; + int min=INT_MAX; + int max=INT_MIN; + cout<<"Enter the elements"<>arr[i]; + if(arr[i]max)//if current element is greater than max + max=arr[i];//max is updated + } + cout<<"Minimum element is:"< +n = size of array/ number of element +x = Element to be counted in array +count = veriable to count the X-number in array diff --git a/C++/Program-2/number_of_occurrence.cpp b/C++/Program-2/number_of_occurrence.cpp new file mode 100644 index 00000000..d481a7bc --- /dev/null +++ b/C++/Program-2/number_of_occurrence.cpp @@ -0,0 +1,42 @@ +#include + +using namespace std; + +class Solution{ +public: + +/* + if x is present in arr[] then returns the count + of occurrences of x, otherwise returns 0. +*/ + +int count(int arr[], int n, int x) { + + int count = 0; + for(int i=0;i> n ; + cout<<"Enter a number to be counted: "; + cin>>x; + int arr[n]; + for (int i = 0; i < n; i++) { + cin >> arr[i]; + } + Solution ob; + auto ans = ob.count(arr, n, x); + cout<< "number "< +n = number of elements/size +k = Kth element for swaping diff --git a/C++/Program-3/swap_kth_Element.cpp b/C++/Program-3/swap_kth_Element.cpp new file mode 100644 index 00000000..d0573268 --- /dev/null +++ b/C++/Program-3/swap_kth_Element.cpp @@ -0,0 +1,45 @@ +#include + +using namespace std ; + +void takeInput(int a[], int n){ + for(int i=1;i<=n;i++){ + cin>>a[i]; + } +} + +void swap_k(int a[], int n, int k){ + + int i , count = n ; + for(i=1 ; i<=n , count >= 1 ; i++ , count--){ + + if(k == i || k == count){ + swap(a[k],a[count]); + } + + } + + for(i=1;i<=n;i++){ + cout<>n ; + + int k; + cout<<"Enter Kth element to swap:"; + cin>>k ; + + int a[1000]; + takeInput(a,n); + + swap_k(a,n,k); + cout<<"\n"; + + return 0; +} diff --git a/C/Program-49/README.md b/C/Program-49/README.md new file mode 100644 index 00000000..7766aa7c --- /dev/null +++ b/C/Program-49/README.md @@ -0,0 +1,8 @@ +Program 49 + +Write a program to find the sum of the digits of the given number. + +Variable description-- +num=Number +sum= Holds the sum +dig=Holds the single digit of the number diff --git a/C/Program-49/program.c b/C/Program-49/program.c new file mode 100644 index 00000000..cc5d2743 --- /dev/null +++ b/C/Program-49/program.c @@ -0,0 +1,18 @@ +#include + +int main() { + + int n; + printf("Enter the number"); + int num; + scanf("%d",&num);//Enter the number + int sum=0,dig=0; + while(num>0) + { + dig=num%10; + sum+=dig; + num/=10; + } + printf("The sum of digits of a number is: %d",sum); + return 0; +} diff --git a/C/Program-52/README.md b/C/Program-52/README.md new file mode 100644 index 00000000..e521142d --- /dev/null +++ b/C/Program-52/README.md @@ -0,0 +1,4 @@ +Program 52 + +Write a program to find whether the given element is present in the array or not. + diff --git a/C/Program-52/program.c b/C/Program-52/program.c new file mode 100644 index 00000000..0d916d88 --- /dev/null +++ b/C/Program-52/program.c @@ -0,0 +1,39 @@ +#include + +int main() { + int n;//number of elements of array; + printf("Enter the number of elements"); + scanf("%d",&n); + int arr[n]; + printf("\nEnter the elements"); + for(int i=0;i -void main() +#include +int main() { int a,b; int *x,*y; @@ -9,6 +10,6 @@ x=&a; y=&b; //s=; printf("%d\t%d",*x+*y,abs(*x-*y)); - +return 0; } diff --git a/C/program-37/a.out b/C/program-37/a.out deleted file mode 100755 index 2dff926d..00000000 Binary files a/C/program-37/a.out and /dev/null differ diff --git a/C/program-37/program.c b/C/program-37/program.c index 0f2f59a1..6be02495 100644 --- a/C/program-37/program.c +++ b/C/program-37/program.c @@ -11,15 +11,13 @@ int f; if(n==0 || n==1) { - - return ; + return 1; } else { f=fib(n-2)+fib(n-1); } - - + return f; } int main() diff --git a/C/program-38/a.out b/C/program-38/a.out deleted file mode 100755 index 0bb435f1..00000000 Binary files a/C/program-38/a.out and /dev/null differ diff --git a/C/program-38/program.c b/C/program-38/program.c index 02f4e88d..1a771155 100644 --- a/C/program-38/program.c +++ b/C/program-38/program.c @@ -11,15 +11,13 @@ int f; if( n==1) { - - return ; + return 1; } else { f=n*fact(n-1); } - - + return f; } int main() diff --git a/C/program-39/a.out b/C/program-39/a.out deleted file mode 100755 index 4ebdcb8d..00000000 Binary files a/C/program-39/a.out and /dev/null differ diff --git a/C/program-39/program.c b/C/program-39/program.c index 1d0f60f9..8bbcd1a1 100644 --- a/C/program-39/program.c +++ b/C/program-39/program.c @@ -7,7 +7,6 @@ Program to find the GCD of a number using recursion int gcd(int a,int b) { -int f; if( b!=0) { @@ -16,7 +15,7 @@ int f; } else { - return; + return a; } diff --git a/C/program-40/program.c b/C/program-40/program.c index f48a3382..d0d11ff5 100644 --- a/C/program-40/program.c +++ b/C/program-40/program.c @@ -8,7 +8,8 @@ int ack(int m,int n) else if(m!=0 && n==0) return ack(m-1,1); else if (m!=0 && n!=0) - return ack(m-1,ack(m,n-1)); + return ack(m-1,ack(m,n-1)); + return 0; } int main() diff --git a/C/program-42/program42.c b/C/program-42/program.c similarity index 94% rename from C/program-42/program42.c rename to C/program-42/program.c index 5a6154b0..3dd7b554 100644 --- a/C/program-42/program42.c +++ b/C/program-42/program.c @@ -1,7 +1,7 @@ /*C Program to print Floyd’s triangle*/ // Without using a temporary variable and with only one loop #include -void floyd(n){ +void floyd(int n){ int i,j=1; for (i=1;i<=(n*(n+1))/2;i++){ printf("%d ",i); diff --git a/C/Program-43/program.c b/C/program-43/program.c similarity index 100% rename from C/Program-43/program.c rename to C/program-43/program.c diff --git a/C/program-44/program.c b/C/program-44/program.c index 24dbbcb7..4b686c63 100644 --- a/C/program-44/program.c +++ b/C/program-44/program.c @@ -5,7 +5,7 @@ // Alphabet Z Pattern void alphabet_Z_Pattern(int N) { - int index, side_index, size; + int index, side_index; // Declaring the values of Right, // Left and Diagonal values diff --git a/C/program-47/Readme.md b/C/program-47/Readme.md new file mode 100644 index 00000000..dccb21a0 --- /dev/null +++ b/C/program-47/Readme.md @@ -0,0 +1,13 @@ +Program 47 + +Write a program to find the maximum and minimum element in an array. + +Variable description-- + +n=Number of elements in an array + +a=Array of size N + +min= Holds the minimum element + +max=Holds the maximum element diff --git a/C/program-47/kaprekar_number.c b/C/program-47/kaprekar_number.c new file mode 100644 index 00000000..37f77482 --- /dev/null +++ b/C/program-47/kaprekar_number.c @@ -0,0 +1,42 @@ +/* A kaprekar number is a number in base 10 whose square can be split such that the the sum of those numbers +add up to the original number for eg : (45)^2 = 2025 => 20+25=45 */ + + # include + # include + # include + # include + bool iskaprekarnum(int n) + { + if (n == 1) // If the number passed is 1 then it is also considered to be a kaprekar number + return true; + int square_number = n * n; // Finding the square + int count_digits = 0; //This will be the counter variable for the number of digits in the number + while (square_number != 0) + { + count_digits++; + square_number /= 10; + } + square_number = n*n; // Recalculating square as it was changed in the above while loop + for (int r_digits=1; r_digits +int main() +{ + + int a[100],n,min,max; + printf("enter the size of the array"); + scanf("%d",&n); + printf("enter the elements of the array"); + for(int i=0;imax) + max=a[i]; + if(a[i] + +int main() { + int num; + printf("Enter a number \n"); + scanf("%d",&num); + if(num%2==0) + printf("%d is an even number",num); + else + printf("%d is an odd number",num); +} \ No newline at end of file diff --git a/C/program-50/Readme.md b/C/program-50/Readme.md new file mode 100644 index 00000000..06f7c7e1 --- /dev/null +++ b/C/program-50/Readme.md @@ -0,0 +1,13 @@ +Program 50 + +Write a program to check whether a given number is a palindrome or not. + +Variable description-- + +n=Holds the element which is to be checked + +temp=Holds the copy of the element + +rev= Holds the reverse of the number + +rem=Holds the digits of the number diff --git a/C/program-50/program.c b/C/program-50/program.c new file mode 100644 index 00000000..0bd7302c --- /dev/null +++ b/C/program-50/program.c @@ -0,0 +1,19 @@ +#include +int main() +{ + int rem,rev=0,temp,n; + printf("Enter the number"); + scanf("%d",&n); + temp=n; + while(n>0) + { + rem=n%10; + n=n/10; + rev=rem+(rev*10); + } + if(temp==rev) + printf("number is palindrome"); + else + printf("number is not palindrome"); + return 0; +} diff --git a/C/program-51/README.md b/C/program-51/README.md new file mode 100644 index 00000000..18f1c5a3 --- /dev/null +++ b/C/program-51/README.md @@ -0,0 +1,3 @@ +Program 51 + +Write an program to print duplicates in an array. \ No newline at end of file diff --git a/C/program-51/program.c b/C/program-51/program.c new file mode 100644 index 00000000..c255d1a5 --- /dev/null +++ b/C/program-51/program.c @@ -0,0 +1,20 @@ +#include + +int main() { + int arr[100],freq[100]; + int n,i; + printf("Enter the number of elements in array \n"); + scanf("%d",&n); + printf("Enter elements in the array \n"); + for(i=0;i1) + printf("%d ",i); + } + printf("\n"); +} \ No newline at end of file diff --git a/C/program-53/program.c b/C/program-53/program.c new file mode 100644 index 00000000..9fb90c19 --- /dev/null +++ b/C/program-53/program.c @@ -0,0 +1,22 @@ +#include +int main() +{ + int a[100],n,el,i; + printf("Enter the size of the array"); + scanf("%d",&n); + printf("Enter the elements of the array"); + for(int i=0;i +int main() +{ + char a[100],b[100]; + int f[26]={0}; + int s[26]={0}; + int k; + int len1,len2; + printf("Enter the two strings\n"); + fgets(a,100,stdin); + fgets(b,100,stdin); + for(int i=0;a[i]!='\0';++i) + f[a[i]-'a']+=1; + for(int i=0;b[i]!='\0';++i) + s[b[i]-'a']+=1; + len1 = sizeof(a)/sizeof(a[0]); + len2 = sizeof(b)/sizeof(b[0]); + if(len1 == len2) + { + for(k=0;k<26;++k) + if(f[k]!=s[k]) + break; + if(k==26) + printf("The strings are anagrams.\n"); + else + printf("The strings aren't anagrams."); + } + else + printf("The strings aren't anagrams."); + return 0; +} diff --git a/C/program-55/program.c b/C/program-55/program.c new file mode 100644 index 00000000..ff134113 --- /dev/null +++ b/C/program-55/program.c @@ -0,0 +1,22 @@ +/* Program that prints a number in binary*/ + +// start writng code from here +#include + +int main (void) +{ + int b; + unsigned int mask = 1<<31; + + printf("Input a 32bits integer number: "); + scanf("%d", &b); + + while (mask != 0){ + printf("%d", b&mask?1:0); + mask >>= 1; + } + + printf("\n"); + + return 0; +} diff --git a/C/program-55/read.md b/C/program-55/read.md new file mode 100644 index 00000000..42d8c087 --- /dev/null +++ b/C/program-55/read.md @@ -0,0 +1,4 @@ +# program-55 +## Program that prints a number in binary + +This program uses bitwise operators to print a 32bits integer in binary representation diff --git a/C/program-56/README.md b/C/program-56/README.md new file mode 100644 index 00000000..cdda9057 --- /dev/null +++ b/C/program-56/README.md @@ -0,0 +1,4 @@ +Program 56 + + +Write a program in C to calculate the number of vowels and consonants in a string. diff --git a/C/program-56/program.c b/C/program-56/program.c new file mode 100644 index 00000000..12d30de1 --- /dev/null +++ b/C/program-56/program.c @@ -0,0 +1,15 @@ +#include + +int main() { + char ch[100]; + int i,count; + printf("Enter the string \n"); + fgets(ch,100,stdin); + for(i=0;ch[i]!='\0';i++) + { + if(ch[i]=='a'||ch[i]=='e'||ch[i]=='i'||ch[i]=='o'||ch[i]=='u'||ch[i]=='A'||ch[i]=='E'||ch[i]=='I'||ch[i]=='O'||ch[i]=='U') + count++; + } + printf("Number of vowels are %d \n",count); + printf("Number of consonants are %d",(i-count)); +} diff --git a/Java/program-1/README.md b/Java/program-1/README.md new file mode 100644 index 00000000..5bf7551a --- /dev/null +++ b/Java/program-1/README.md @@ -0,0 +1,9 @@ +Program 1 + +Write a program to find the maximum and minimum element in an array. + +Variable description-- +N=Number of elements in an array +arr=Array of size N +min= Holds the minimum element +max=Holds the maximum element \ No newline at end of file diff --git a/Java/program-1/program.java b/Java/program-1/program.java new file mode 100644 index 00000000..8abc89cd --- /dev/null +++ b/Java/program-1/program.java @@ -0,0 +1,24 @@ +import java.util.*; +import java.io.*; + +class prg { + public static void main (String[] args) { + Scanner sc=new Scanner(System.in); + System.out.println("Enter the size of array"); + int N=sc.nextInt(); + int arr[]=new int[N]; + System.out.println("Enter the elements in the array"); + for(int i=0;imax) + max=arr[i]; + } + System.out.println("Minimum="+min+"\nMaximum="+max); + } +} \ No newline at end of file diff --git a/Javascript/program-1/program-1.html b/Javascript/program-1/program-1.html new file mode 100644 index 00000000..d47acfbb --- /dev/null +++ b/Javascript/program-1/program-1.html @@ -0,0 +1,21 @@ + + +SUM OF THE TWO NUMBERS + + +
+ENTER NUMBER1:
+ENTER NUMBER2:
+Submit: +Reset: +
+ + diff --git a/Javascript/program-1/read.md b/Javascript/program-1/read.md new file mode 100644 index 00000000..a0b76fea --- /dev/null +++ b/Javascript/program-1/read.md @@ -0,0 +1,2 @@ +# Program-1 +## This is a javascript program for adding two numbers diff --git a/Javascript/program-2/program-2.html b/Javascript/program-2/program-2.html new file mode 100644 index 00000000..531f4181 --- /dev/null +++ b/Javascript/program-2/program-2.html @@ -0,0 +1,16 @@ + + + CHARACTER PROCESSING METHODS + + + + + diff --git a/Javascript/program-2/read.md b/Javascript/program-2/read.md new file mode 100644 index 00000000..39f1e330 --- /dev/null +++ b/Javascript/program-2/read.md @@ -0,0 +1,2 @@ +# Program-2 +## This is a javascript program for string operations diff --git a/Javascript/program-3/armstrong.html b/Javascript/program-3/armstrong.html new file mode 100644 index 00000000..fe1188a2 --- /dev/null +++ b/Javascript/program-3/armstrong.html @@ -0,0 +1,20 @@ + +ARMSTRONG NUMBER + + + + diff --git a/Javascript/program-3/read.md b/Javascript/program-3/read.md new file mode 100644 index 00000000..36e6ee89 --- /dev/null +++ b/Javascript/program-3/read.md @@ -0,0 +1,3 @@ +# Program-3 +## This is a javascript program for armstrong + diff --git a/Javascript/program-4/palindrome.html b/Javascript/program-4/palindrome.html new file mode 100644 index 00000000..52145b20 --- /dev/null +++ b/Javascript/program-4/palindrome.html @@ -0,0 +1,55 @@ + + + + Check Palindrome with JavaScript Program + + + + +
+ + +
+ + \ No newline at end of file diff --git a/Javascript/program-4/read.md b/Javascript/program-4/read.md new file mode 100644 index 00000000..80979ba9 --- /dev/null +++ b/Javascript/program-4/read.md @@ -0,0 +1,3 @@ +# Program-4 +## This is a javascript program for palindrome + diff --git a/Python/Program-3/README.md b/Python/Program-3/README.md new file mode 100644 index 00000000..67521f30 --- /dev/null +++ b/Python/Program-3/README.md @@ -0,0 +1,7 @@ +Program 3 + +Write a program to check whether the string is palindrome or not + +Variable description-- +a=Holds the input string +b=Holds the reverse of the string diff --git a/Python/Program-3/program.py b/Python/Program-3/program.py new file mode 100644 index 00000000..ac4daec0 --- /dev/null +++ b/Python/Program-3/program.py @@ -0,0 +1,8 @@ + + +a=input() +b=a[::-1] #String is reversed and stored in b +if (a==b): # If a and b both are equal string is Palindrome + print("String is Palindrome") +else: + print("String is not Palindrome") diff --git a/Python/program-4/sorting.py b/Python/program-4/sorting.py new file mode 100644 index 00000000..e91b5a5c --- /dev/null +++ b/Python/program-4/sorting.py @@ -0,0 +1,23 @@ +import datetime +start = datetime.datetime.now() +arr = [5, 8, 1, 3, 3, 0, 7, 4,5,8, 9, 10, 84, 34, 22] +arr_size = len(arr) +new_arr = [None]*(arr_size) +n = 0 + +for i in range(arr_size): + n=0 + for j in range(arr_size): + if arr[i] > arr[j]: + n+=1 + while new_arr[n] == arr[i]: + n+=1 + new_arr[n] = arr[i] + +arr = new_arr + +for i in range(arr_size): + print ("%d" %arr[i]), + +finish = datetime.datetime.now() +print (finish-start)