diff --git a/.github/ISSUE_TEMPLATE/contribution.md b/.github/ISSUE_TEMPLATE/contribution.md index 377f463e..b68f4055 100644 --- a/.github/ISSUE_TEMPLATE/contribution.md +++ b/.github/ISSUE_TEMPLATE/contribution.md @@ -34,6 +34,7 @@ eg-git push origin -u swaaz - The given link should be copied and pasted in web browser or go to your repo in web browser - Create a pull request +- tag @swaaz under review section ## If you are contributing for the first time,then : [click here](https://gitme.js.org/) 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/program 47.c b/C/program-47/program 47.c new file mode 100644 index 00000000..0a87a07c --- /dev/null +++ b/C/program-47/program 47.c @@ -0,0 +1,33 @@ +#include +#include +#include + +int main() +{ + /* Length of the password */ + int length; + int num; + int temp; + printf("Enter the length of the password: "); + scanf("%d", &length); + printf("\nEnter the number of passwords you want: "); + scanf("%d", &num); + /* Seed number for rand() */ + srand((unsigned int) time(0) + getpid()); + + while(num--) + { + temp = length; + printf("\n"); + while(temp--) { + putchar(rand() % 56 + 65); + srand(rand()); + } + + temp = length; + } + + printf("\n"); + + return EXIT_SUCCESS; +} diff --git a/C/program-47/program.c b/C/program-47/program.c new file mode 100644 index 00000000..04e8a3c6 --- /dev/null +++ b/C/program-47/program.c @@ -0,0 +1,23 @@ +#include +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/Readme.md b/C/program-53/Readme.md new file mode 100644 index 00000000..8809d9d9 --- /dev/null +++ b/C/program-53/Readme.md @@ -0,0 +1 @@ +Program to find the position of an element in an array \ 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/readme.md b/C/program-55/readme.md new file mode 100644 index 00000000..42d8c087 --- /dev/null +++ b/C/program-55/readme.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/C/program-57/program.c b/C/program-57/program.c new file mode 100644 index 00000000..cac40c26 --- /dev/null +++ b/C/program-57/program.c @@ -0,0 +1,26 @@ +#include + +int main () { + float score; + printf("Enter your total score (0-100): "); + scanf("%f",&score); + if(score < 0 || score > 100) { + printf("Enter score 0 - 100 \n"); + } else if(score >= 80) { + printf("Score = %.2f , You Grade : A\n",score); + } else if(score >= 75) { + printf("Score = %.2f , You Grade : B+\n",score); + } else if(score >= 70) { + printf("Score = %.2f , You Grade : B\n",score); + } else if(score >= 65) { + printf("Score = %.2f , You Grade : C+\n",score); + } else if(score >= 60) { + printf("Score = %.2f , You Grade : C\n",score); + } else if(score >= 55) { + printf("Score = %.2f , You Grade : D+\n",score); + } else if(score >= 50) { + printf("Score = %.2f , You Grade : D\n",score); + } else { + printf("Score = %.2f , You Grade : F\n",score); + } +} \ No newline at end of file diff --git a/C/program-57/readme.md b/C/program-57/readme.md new file mode 100644 index 00000000..6d1d4966 --- /dev/null +++ b/C/program-57/readme.md @@ -0,0 +1,4 @@ +Program 57 + + +Write a program in C to calculate the grade diff --git a/C/program-58/Program.c b/C/program-58/Program.c new file mode 100644 index 00000000..709d4d23 --- /dev/null +++ b/C/program-58/Program.c @@ -0,0 +1,24 @@ + #include +void main() + +{ + //float n[10]; + int i,sum,a,b,x; + printf("enter the size of elements\n"); + scanf("%d", &x); + float n[x]; + printf("enter the values\n"); + for (i=0;i +#include + +typedef struct student +{ + + char name[25]; + char usn[15]; + float cgpa; +} S; +S s[70]; + + +void search(char name[],int n) +{ + + int i,j; + // printf("%s\n",name); + for(i=0;i 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_digitsmax) + max=arr[i]; + } + System.out.println("Minimum="+min+"\nMaximum="+max); + } +} \ No newline at end of file diff --git a/Java/program-2/README.md b/Java/program-2/README.md new file mode 100644 index 00000000..7ed914ac --- /dev/null +++ b/Java/program-2/README.md @@ -0,0 +1,9 @@ +Program 2 + +Given a String,check if it is a palindrome or not. + +Variable description +s= Input String +start= Starting index of String s +end= Last index of String s +flag= Variable to mark if the String is not a Palindrome \ No newline at end of file diff --git a/Java/program-2/program.java b/Java/program-2/program.java new file mode 100644 index 00000000..a9d9adda --- /dev/null +++ b/Java/program-2/program.java @@ -0,0 +1,26 @@ +import java.io.*; +import java.util.*; +class prg{ + public static void main(String args[]) + { + Scanner sc=new Scanner(System.in); + String s=sc.next(); + int start=0; + int end=s.length()-1; + int flag=0; + while(start +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/program-4.html b/Javascript/program-4/program-4.html new file mode 100644 index 00000000..52145b20 --- /dev/null +++ b/Javascript/program-4/program-4.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/Javascript/program-5/program-5.html b/Javascript/program-5/program-5.html new file mode 100644 index 00000000..69b109fe --- /dev/null +++ b/Javascript/program-5/program-5.html @@ -0,0 +1,47 @@ + + +MATHEMATICAL OPERATIONS OF TWO NUMBERS + + +
+ENTER NUMBER1:
+ENTER NUMBER2:
+ + + + +Reset: +Result: +
+ + + diff --git a/Javascript/program-5/read.md b/Javascript/program-5/read.md new file mode 100644 index 00000000..24771b46 --- /dev/null +++ b/Javascript/program-5/read.md @@ -0,0 +1,4 @@ +# Program-5 +## This is a javascript program for mathematical operations + + diff --git a/Javascript/program-6/program-6.html b/Javascript/program-6/program-6.html new file mode 100644 index 00000000..55d8806f --- /dev/null +++ b/Javascript/program-6/program-6.html @@ -0,0 +1,17 @@ + + + CHARACTER PROCESSING METHODS + + + + + diff --git a/Javascript/program-6/read.md b/Javascript/program-6/read.md new file mode 100644 index 00000000..61cc055a --- /dev/null +++ b/Javascript/program-6/read.md @@ -0,0 +1,3 @@ +# Program-4 +## This is a javascript program for character processing + diff --git a/Python/program-4/Program 4.py b/Python/program-4/Program 4.py new file mode 100644 index 00000000..77c405f9 --- /dev/null +++ b/Python/program-4/Program 4.py @@ -0,0 +1,9 @@ +# Store input numbers +num1 = input('Enter first number: ') +num2 = input('Enter second number: ') + +# Add two numbers +sum = float(num1) + float(num2) + +# Display the sum +print('The sum of {0} and {1} is {2}'.format(num1, num2, sum)) 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) diff --git a/index.html b/index.html index f6c920ff..142e7e1b 100644 --- a/index.html +++ b/index.html @@ -1,20 +1,16 @@ - - Basic Programs - - - - - - - - -
-

Basic Programs

-

Basic programs in C and Python

- -
- - - \ No newline at end of file + + Basic Programs + + + + + + +
+

Basic Programs

+

Basic programs in C and Python

+
+ + diff --git a/readme.md b/readme.md index b41b556d..25413caa 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ # Basic programs -## This repo contains basics programs in c programming language and python. +## This repo contains basics programs in all languages. ## Contribution If you want to contribute to this repo then [click here](https://github.com/swaaz/basicprograms/blob/swaaz/.github/ISSUE_TEMPLATE/contribution.md) diff --git a/src/1.jpg b/src/1.jpg deleted file mode 100644 index a7aa7071..00000000 Binary files a/src/1.jpg and /dev/null differ diff --git a/src/css/index.css b/src/css/index.css new file mode 100644 index 00000000..e69de29b diff --git a/1.jpg b/src/images/1.jpg similarity index 100% rename from 1.jpg rename to src/images/1.jpg diff --git a/src/js/index.js b/src/js/index.js new file mode 100644 index 00000000..e69de29b