diff --git a/C++/Program-6/Readme.md b/C++/Program-6/Readme.md new file mode 100644 index 00000000..00f303b9 --- /dev/null +++ b/C++/Program-6/Readme.md @@ -0,0 +1,10 @@ +Program 6 + +Write a program to find the greatest common divisor of two number. + +Variable description-- + +x=Holds the first number + +y=Holds the second number + diff --git a/C++/Program-6/program.cpp b/C++/Program-6/program.cpp new file mode 100644 index 00000000..23a755c2 --- /dev/null +++ b/C++/Program-6/program.cpp @@ -0,0 +1,16 @@ +#include +using namespace std; +int gcd(int x,int y) +{ + if(y==0) + return x; + return gcd(y,x%y); +} + +int main() { + cout<<"enter the numbers\n"; + int x,y; + cin>>x>>y; + cout<<"The GCD is "< +using namespace std; + +int main() +{ + int rows, n = 1; + + cout << "Enter number of rows: \n"; + cin >> rows; + + for(int i = 0; i < rows; i++) + { + for(int line = 1; line <= rows-i; line++) + cout <<" "; + + for(int j = 0; j <= i; j++) + { + if (j == 0 || i == 0) + n = 1; + else + n = n*(i-j+1)/j; + + cout << n << " "; + } + cout << endl; + } + + return 0; +} \ No newline at end of file diff --git a/C++/Program-7/readme.md b/C++/Program-7/readme.md new file mode 100644 index 00000000..83bd1a5b --- /dev/null +++ b/C++/Program-7/readme.md @@ -0,0 +1 @@ +C++ Program to print Pascal' triangle \ No newline at end of file diff --git a/C/Program-61/program.c b/C/Program-61/program.c new file mode 100644 index 00000000..0e7c906c --- /dev/null +++ b/C/Program-61/program.c @@ -0,0 +1,58 @@ +/* + This Program calulates all the prime between the range of numbers + includes the numbers which is provided. + + For e.g: 2 7 + Prime Numbers are : 2 3 5 7 +*/ + +#include +#include + +char primecheck(int); + +int main() +{ + int i,num1,num2,cases; + char ans; + printf("Enter Number of Test Cases: "); + scanf("%d",&cases); + while (cases--) + { + printf("Enter First Number: "); + scanf("%d",&num1); + printf("Enter Second Number: "); + scanf("%d",&num2); + + printf("Answer: "); + for(i=num1;i<=num2;i++) + { + ans = primecheck(i); + if (ans == 'y') + printf("%d ",i); + } + printf("\n"); + } + return 0; +} + +char primecheck(int num) +{ + int i; + if (num == 0 || num == 1) + return 'n'; + else + { + for(i=(num-1);i>1;i--) + { + if(num%i == 0) + { + return 'n'; + } + else + continue; + } + return 'y'; + } + +} \ No newline at end of file diff --git a/C/README.md b/C/README.md index 936b65b6..f5d269b5 100644 --- a/C/README.md +++ b/C/README.md @@ -62,6 +62,7 @@ | Program-58 | Program to find the sum of elements between indexes | | Program-59 | Program to Search Students details in a list | | Program-60 | Program to print kaprekar number in a given range | +| Program-61 | Program to find the all the prime numbers between the numbers | diff --git a/C/program-61/program.c b/C/program-61/program.c index 0bfbf2dc..ca8f1a80 100644 --- a/C/program-61/program.c +++ b/C/program-61/program.c @@ -1,23 +1,58 @@ -#include -void main() +/* + This Program calulates all the prime between the range of numbers + includes the numbers which is provided. + + For e.g: 2 7 + Prime Numbers are : 2 3 5 7 +*/ + +#include +#include + +char primecheck(int); + +int main() { - double r,area,circum;//Initializing varaibles - - printf("Enter Radius:"); - scanf("%lf",&r);//getting radius. - - if(r<10)//Checks if radius is less than 10 - { - circum = 2*3.14*r;//Circumference of a circle is 2*pi*r. - - printf("The Circumference of the Circle with the given radius is: %lf",circum);//printing Circumference - } - else//If r is NOT less that 10....i.e. r is greater than 10 - { - area = 3.14*r*r;//Area of a circle is pi*r*r. - - printf("The Area of the Circle with the given radius is: %lf",area);//printing The area - } - getch(); - + int i,num1,num2,cases; + char ans; + printf("Enter Number of Test Cases: "); + scanf("%d",&cases); + while (cases--) + { + printf("Enter First Number: "); + scanf("%d",&num1); + printf("Enter Second Number: "); + scanf("%d",&num2); + + printf("Answer: "); + for(i=num1;i<=num2;i++) + { + ans = primecheck(i); + if (ans == 'y') + printf("%d ",i); + } + printf("\n"); + } + return 0; } + +char primecheck(int num) +{ + int i; + if (num == 0 || num == 1) + return 'n'; + else + { + for(i=(num-1);i>1;i--) + { + if(num%i == 0) + { + return 'n'; + } + else + continue; + } + return 'y'; + } + +} \ No newline at end of file diff --git a/Java/program-3/program.java b/Java/program-3/program.java index a108adc6..95be6346 100644 --- a/Java/program-3/program.java +++ b/Java/program-3/program.java @@ -8,10 +8,10 @@ public static void main(String args[]) int v=0; for(int i=0;i + + + +

My First Web Page

+

My First Paragraph.

+ +

+ + + + + \ No newline at end of file diff --git a/Javascript/program-10/read.md b/Javascript/program-10/read.md new file mode 100644 index 00000000..b6ac8af1 --- /dev/null +++ b/Javascript/program-10/read.md @@ -0,0 +1,4 @@ +# Program-10 + +## This is a javascript program for javascript writing into an html element + diff --git a/Javascript/program-6/read.md b/Javascript/program-6/read.md index 61cc055a..41027f16 100644 --- a/Javascript/program-6/read.md +++ b/Javascript/program-6/read.md @@ -1,3 +1,3 @@ -# Program-4 +# Program-6 ## This is a javascript program for character processing diff --git a/Javascript/program-7/program-7.html b/Javascript/program-7/program-7.html new file mode 100644 index 00000000..02f877bc --- /dev/null +++ b/Javascript/program-7/program-7.html @@ -0,0 +1,33 @@ + + +Searching strings with index Of amd LastIndex of + + + + +
+

The String to search is:
abcdefghijklmnopqrstuvwxyzabcdefghijklm

+

Enter substring to search for + +

+

First Occurace located at index + +
Last occurance located at index + +
First occurance from index l2 located at index + +
last occurance from index l2 located at index +

+
+ + diff --git a/Javascript/program-7/read.md b/Javascript/program-7/read.md new file mode 100644 index 00000000..58c8bbb4 --- /dev/null +++ b/Javascript/program-7/read.md @@ -0,0 +1,4 @@ +# Program-7 + +## This is a javascript program for string searching + diff --git a/Javascript/program-8/program-8.html b/Javascript/program-8/program-8.html new file mode 100644 index 00000000..9fc48e1e --- /dev/null +++ b/Javascript/program-8/program-8.html @@ -0,0 +1,21 @@ + + + + + + + + +

When you click "Try it", a function will be called.

+

The function will display a message.

+ + + +

+ + + \ No newline at end of file diff --git a/Javascript/program-8/read.md b/Javascript/program-8/read.md new file mode 100644 index 00000000..b6c0dfd5 --- /dev/null +++ b/Javascript/program-8/read.md @@ -0,0 +1,4 @@ +# Program-8 + +## This is a javascript program for javascript function basic program + diff --git a/Javascript/program-9/program-9.html b/Javascript/program-9/program-9.html new file mode 100644 index 00000000..6c8a1d04 --- /dev/null +++ b/Javascript/program-9/program-9.html @@ -0,0 +1,16 @@ + + + + +

My First Web Page

+

My first paragraph.

+ +

Never call document.write after the document has finished loading. +It will overwrite the whole document.

+ + + + + \ No newline at end of file diff --git a/Javascript/program-9/read.md b/Javascript/program-9/read.md new file mode 100644 index 00000000..cb69f65a --- /dev/null +++ b/Javascript/program-9/read.md @@ -0,0 +1,4 @@ +# Program-9 + +## This is a javascript program for javascript writing into html output + diff --git a/Python/Program-3/README.md b/Python/Program-3/README.md deleted file mode 100644 index 67521f30..00000000 --- a/Python/Program-3/README.md +++ /dev/null @@ -1,7 +0,0 @@ -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/README.md b/Python/README.md new file mode 100644 index 00000000..c1b29aee --- /dev/null +++ b/Python/README.md @@ -0,0 +1,24 @@ +# Python-basicprograms +## This repo contains basics programs in Python programming language. +| Program No.| Question | +| ------- | ------ | +| Program-01 | Program to print Hello World. | +| Program-02 | Program to find the factorial of a number. | +| Program-03 | Program to find if the string is Palindrom or not. | +| Program-04 | Program to find sum of two numbers. | +| Program-05 | Program to print a pattern. | +| Program-06 | Program to print a pattern. | +| Program-07 | Program to print a pattern. | +| Program-08 | Program to print a pattern. | +| Program-09 | Program to check if the number is armstrong or not. | +| Program-10 | Program to shuffle a deck of cards. | +| Program-11 | Program to print fibonacci series. | +| Program-12 | Program to check if a number is prime or not. | +| Program-13 | Program to find a number in an array using binary search. | +| Program-14 | Program to find simple interest for given principal amount, time and rate of interest. | +| Program-15 | Program to sort the array and give the time to sort the array. | +| Program-16 | Program to print a right angled triangle. | +| Program-17 | Program to convert Binary to Decimal. | +| Program-18 | Program to check leap year or not. | +| Program-19 | Program to count number of integers between 1 to 50 divisible by a number. | +| Program-20 | Program to create an array of range specified and print. | \ No newline at end of file diff --git a/Python/program-11/shufflecards.py b/Python/program-10/program.py similarity index 100% rename from Python/program-11/shufflecards.py rename to Python/program-10/program.py diff --git a/Python/program-14/git.py b/Python/program-11/program.py similarity index 100% rename from Python/program-14/git.py rename to Python/program-11/program.py diff --git a/Python/program-15/git1.py b/Python/program-12/program.py similarity index 100% rename from Python/program-15/git1.py rename to Python/program-12/program.py diff --git a/Python/program-16/git2.py b/Python/program-13/program.py similarity index 100% rename from Python/program-16/git2.py rename to Python/program-13/program.py diff --git a/Python/program-16/readme.md b/Python/program-13/readme.md similarity index 100% rename from Python/program-16/readme.md rename to Python/program-13/readme.md diff --git a/Python/program-18/git3.py b/Python/program-14/program.py similarity index 99% rename from Python/program-18/git3.py rename to Python/program-14/program.py index cfbccef5..f1530142 100644 --- a/Python/program-18/git3.py +++ b/Python/program-14/program.py @@ -2,7 +2,6 @@ # for given principal amount, time and # rate of interest. - def simple_interest(p,t,r): print('The principal is', p) print('The time period is', t) diff --git a/Python/program-14/readme.md b/Python/program-14/readme.md deleted file mode 100644 index 53622207..00000000 --- a/Python/program-14/readme.md +++ /dev/null @@ -1 +0,0 @@ -program to print fibonacci series diff --git a/Python/program-4/sorting.py b/Python/program-15/program.py similarity index 100% rename from Python/program-4/sorting.py rename to Python/program-15/program.py diff --git a/Python/program-15/readme.md b/Python/program-15/readme.md deleted file mode 100644 index a089d895..00000000 --- a/Python/program-15/readme.md +++ /dev/null @@ -1 +0,0 @@ -program to check whether a number is prime or not diff --git a/Python/program-4/triangle.py b/Python/program-16/program.py similarity index 96% rename from Python/program-4/triangle.py rename to Python/program-16/program.py index da4902eb..3b38ab45 100644 --- a/Python/program-4/triangle.py +++ b/Python/program-16/program.py @@ -1,4 +1,4 @@ -for i in range(5): - for j in range(i): - print('*', end=' ') +for i in range(5): + for j in range(i): + print('*', end=' ') print() \ No newline at end of file diff --git a/Python/program-17/program.py b/Python/program-17/program.py new file mode 100644 index 00000000..80444473 --- /dev/null +++ b/Python/program-17/program.py @@ -0,0 +1,14 @@ +#Python Program to Convert Decimal to Binary + +def decimalToBinary(num): + """This function converts decimal number + to binary and prints it""" + if num > 1: + decimalToBinary(num // 2) + print(num % 2, end='') + + +# decimal number +number = int(input("Enter any decimal number: ")) + +decimalToBinary(number) diff --git a/Python/program-18/program.py b/Python/program-18/program.py new file mode 100644 index 00000000..c843e104 --- /dev/null +++ b/Python/program-18/program.py @@ -0,0 +1,7 @@ + +year = int( input('Enter Year: ')) + +if (year%4) and (year%100) and (year%400) == 0: + print('Leap year') +else: + print('Not leap year') diff --git a/Python/program-18/readme.md b/Python/program-18/readme.md deleted file mode 100644 index 0c0fcc1d..00000000 --- a/Python/program-18/readme.md +++ /dev/null @@ -1 +0,0 @@ -python program for simple interest \ No newline at end of file diff --git a/Python/program-19/program.py b/Python/program-19/program.py new file mode 100644 index 00000000..b7fbc2ee --- /dev/null +++ b/Python/program-19/program.py @@ -0,0 +1,10 @@ +a = int(input()) +count = 0 +list_1 = [i for i in range(1, 51)] + +for i in list_1: + if i != a: + if i%a == 0: + count+=1 + +print(count,end='') \ No newline at end of file diff --git a/Python/program-2/program.py b/Python/program-2/program.py index 7df869a1..47edb63b 100644 --- a/Python/program-2/program.py +++ b/Python/program-2/program.py @@ -1 +1,14 @@ -print("Hello, World!") +fact=int(input("input any number")) +# input any number +factorial = 1 +#predefined factorial of 0 +if fact < 0: + print("factorial is not possible") +elif fact == 0: + print("factorial of "+str(fact) +" is "+str(factorial)) +else: + fact1=fact + while(fact>2): + fact-=1 + fact1=fact1*(fact) + print("factorial is "+ str(fact1)) \ No newline at end of file diff --git a/Python/program-20/program.py b/Python/program-20/program.py new file mode 100644 index 00000000..c01b73a1 --- /dev/null +++ b/Python/program-20/program.py @@ -0,0 +1,9 @@ +a,b = input().split() + +a = int(a) +b = int(b) + +list_1 = list(x for x in range(a+1,b+1)) + +for i in list_1[a:b]: + print(i) \ No newline at end of file diff --git a/Python/program-4/README.md b/Python/program-4/README.md deleted file mode 100644 index 7137f722..00000000 --- a/Python/program-4/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# triangle.py -# Draws a triangle \ No newline at end of file diff --git a/Python/program-4/Program 4.py b/Python/program-4/program.py similarity index 96% rename from Python/program-4/Program 4.py rename to Python/program-4/program.py index 77c405f9..d31335e3 100644 --- a/Python/program-4/Program 4.py +++ b/Python/program-4/program.py @@ -1,9 +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)) +# 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-5/README.md b/Python/program-5/README.md index 669d2d67..99238315 100644 --- a/Python/program-5/README.md +++ b/Python/program-5/README.md @@ -1,7 +1,10 @@ Program 5 -Write a program to find a factorial of a number. +This program gives the following pattern: -Variable description-- -fact= Holds the input number + 1 + 1 2 1 2 + 1 2 3 1 2 3 + 1 2 3 4 1 2 3 4 +1 2 3 4 5 1 2 3 4 5 diff --git a/Python/program-5/factorial.py b/Python/program-5/factorial.py deleted file mode 100644 index 9db2639b..00000000 --- a/Python/program-5/factorial.py +++ /dev/null @@ -1,14 +0,0 @@ -fact=int(input("input any number")) -# input any number -factorial =1 -#predefined factorial of 0 -if fact<0: - print("factorial is not possible") -elif fact==0: - print("factorial of "+str(fact) +" is "+str(factorial)) -else: - fact1=fact - while(fact>2): - fact-=1 - fact1=fact1*(fact) - print("factorial is "+ str(fact1)) \ No newline at end of file diff --git a/Python/program-5/pattern.py b/Python/program-5/pragram.py similarity index 100% rename from Python/program-5/pattern.py rename to Python/program-5/pragram.py diff --git a/Python/program-6/README.md b/Python/program-6/README.md index 8d8c46c6..55a615a3 100644 --- a/Python/program-6/README.md +++ b/Python/program-6/README.md @@ -1,7 +1,10 @@ Program 6 -Write a program to check whether a number is prime or not +The code gives the following pattern : -Variable description-- -n= holds input value +1 +2 2 +3 3 3 +4 4 4 4 +5 5 5 5 5 diff --git a/Python/program-6/pattern.py b/Python/program-6/pattern.py deleted file mode 100644 index 456583e0..00000000 --- a/Python/program-6/pattern.py +++ /dev/null @@ -1,4 +0,0 @@ -for i in range(1,6): - for j in range(1,i+1): - print(i,end=' ') - print() diff --git a/Python/program-6/program.py b/Python/program-6/program.py index 8b70a1d6..456583e0 100644 --- a/Python/program-6/program.py +++ b/Python/program-6/program.py @@ -1,14 +1,4 @@ -n=int(input("enter any number")) -# n is the number to check whether it is prime or not -if n>1: - # loop from 2 to n/2 - for i in range(2,int(n/2)): - - if(n%i)==0: - #if n is completly divisible by i then it is not a prime number - print("n is not prime") - break - else: - print("n is prime") -else: - print("not prime") +for i in range(1,6): + for j in range(1,i+1): + print(i,end=' ') + print() diff --git a/Python/program-7/pattern3.py b/Python/program-7/program.py similarity index 100% rename from Python/program-7/pattern3.py rename to Python/program-7/program.py diff --git a/Python/program-8/pattern4.py b/Python/program-8/program.py similarity index 100% rename from Python/program-8/pattern4.py rename to Python/program-8/program.py diff --git a/Python/program-10/armstrong.py b/Python/program-9/program.py similarity index 100% rename from Python/program-10/armstrong.py rename to Python/program-9/program.py diff --git a/readme.md b/readme.md index 17b64228..0a5ec0fd 100644 --- a/readme.md +++ b/readme.md @@ -1,12 +1,119 @@ -

Basic Program

- +

Basic Program

-## 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) +## This Repository is an awesome collection of basic programs in different programming languages⚡ +
+ + + + + + + +

+ +## ⚠️Points to note before you start contributing +- Check whether the program you are going to add already exists in the repo or not. Make sure you're not repeting any program. +- Do add readme.md file for explaining the question , input and output for each program. +- Please go through [How to contribute](#contribute) and do accordingly to make a smooth contribution. +

+ +## Folder structure: +``` +. +├── C++ +│ ├── Program-1 +│ │ ├── program.cpp +│ │ ├── readme.md +│ . . +│ . . +│ +├── C +│ ├── Program-1 +│ │ ├── program.c +│ │ ├── readme.md +│ . . +│ . . +│ +├── Java +│ ├── Program-1 +│ │ ├── program.java +│ │ ├── readme.md +│ . . +│ . . +│ +├── Javascript +│ ├── Program-1 +│ │ ├── program.js +│ │ ├── readme.md +│ . . +│ . . +│ +├── Python +│ ├── Program-1 +│ │ ├── program.py +│ │ ├── readme.md +│ . . +│ . . +│ +``` +

+ +# How to contribute + + +- Fork this [repo](https://github.com/swaaz/basicprograms) + +- Clone it using command : +
 $ git clone paste_the_copied_url.
+ +- Open folder "basicprograms" : +
$ cd basicprograms
+ +- Open folder "C/Python" : +
$ cd folder_name
+ eg: cd C + +- Create new branch : +
 $ git branch new_branch_name
+ eg: git branch hactoberfest + +- Checkout to new branch from master branch : +
$ git checkout new_branch_name
+ eg: git checkout hactoberfest + + - Create a new folder +
 $ mkdir program-number 
+ eg: mkdir program-35 + + - Change directory to the new created folder +
 $ cd folder_name 
+ + - Create a file *program.c* + + - Write the code inside program.c file + ### NOTE: Before writng code refer [*sample*](https://github.com/swaaz/basicprograms/blob/swaaz/C/sample.c) file and write the code in the same format as given + + - Add file : +
$ git add -A
+ +- Commit file : +
$ git commit -m "comment"
+ eg: git commit -m "program added" + +- Push the file : +
$ git push origin -u 'branch_name'
+ eg: git push origin -u hactoberfest + +- 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

+ +### Tada you just made a contribution ✨. Pat your back 👏

+ +### If you have never made a PR before 😕, no worries, follow these steps to get going [👉click me](https://gitme.js.org/) +