diff --git a/C++/Program-4/factorial.cpp b/C++/Program-4/factorial.cpp new file mode 100644 index 00000000..27796e1e --- /dev/null +++ b/C++/Program-4/factorial.cpp @@ -0,0 +1,29 @@ +#include +using namespace std; +int main() +{ + int t; + cin>>t; + while(t--){ + int n,size=200,fact[size],j=size-1,carry=0; + cin>>n; + fact[size-1]=1; + while(n>1){ + int x; + for(int k=size-1;k>=j;k--){ + x=fact[k]*n+carry; + fact[k]=x%10; + carry=x/10;} + while(carry>0){ + fact[--j]= carry%10; + carry/=10;} + n--; + } + for(int k=j;k +void 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(); + +} diff --git a/C/program-63/program.c b/C/program-63/program.c new file mode 100644 index 00000000..b89e54f9 --- /dev/null +++ b/C/program-63/program.c @@ -0,0 +1,16 @@ +#include +void main() +{ + int n1,n2,n3,n4,n5; + float t; + + printf("Enter Five Numbers:"); + scanf("%d %d %d %d %d",&n1,&n2,&n3,&n4,&n5); + + t=(n1+n2+n3+n4+n5)/5; + + printf("The Average of %d,%d,%d,%d,%d is %f",n1,n2,n3,n4,n5,t); + + getch(); + +} 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..af56595a --- /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 he 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. | + + + + diff --git a/Python/program-10/program.py b/Python/program-10/program.py new file mode 100644 index 00000000..df6429bd --- /dev/null +++ b/Python/program-10/program.py @@ -0,0 +1,11 @@ +# Python program to shuffle a deck of card + +import itertools, random + +deck = list(itertools.product(range(1,14),['Spade','Heart','Diamond','Club'])) + +random.shuffle(deck) + +print("woohh here you got:") +for i in range(5): + print(deck[i][0], "of", deck[i][1]) diff --git a/Python/program-11/program.py b/Python/program-11/program.py new file mode 100644 index 00000000..84546b60 --- /dev/null +++ b/Python/program-11/program.py @@ -0,0 +1,21 @@ +#fibonacci series +nterms = int(input("How many terms? ")) + +# first two 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 + # update values + n1 = n2 + n2 = nth + count += 1 \ No newline at end of file diff --git a/Python/program-12/program.py b/Python/program-12/program.py new file mode 100644 index 00000000..9ce5c2ef --- /dev/null +++ b/Python/program-12/program.py @@ -0,0 +1,22 @@ +# Program to check if a number is prime or not + +num = 407 + +# To take input from the user +#num = int(input("Enter a number: ")) + +# prime numbers are greater than 1 +if num > 1: + # check for factors + for i in range(2,num): + if (num % i) == 0: + print(num,"is not a prime number") + print(i,"times",num//i,"is",num) + break + else: + print(num,"is a prime number") + +# if input number is less than +# or equal to 1, it is not prime +else: + print(num,"is not a prime number") \ No newline at end of file diff --git a/Python/program-13/program.py b/Python/program-13/program.py new file mode 100644 index 00000000..a6a74aa2 --- /dev/null +++ b/Python/program-13/program.py @@ -0,0 +1,36 @@ +# Returns index of x in arr if present, else -1 +def binary_search(arr, low, high, x): + + # Check base case + if high >= low: + + mid = (high + low) // 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 binary_search(arr, low, mid - 1, x) + + # Else the element can only be present in right subarray + else: + return binary_search(arr, mid + 1, high, x) + + else: + # Element is not present in the array + return -1 + +# Test array +arr = [ 2, 3, 4, 10, 40 ] +x = 10 + +# Function call +result = binary_search(arr, 0, len(arr)-1, x) + +if result != -1: + print("Element is present at index", str(result)) +else: + print("Element is not present in array") \ No newline at end of file diff --git a/Python/program-13/readme.md b/Python/program-13/readme.md new file mode 100644 index 00000000..305d7c49 --- /dev/null +++ b/Python/program-13/readme.md @@ -0,0 +1 @@ +python program for binary search \ No newline at end of file diff --git a/Python/program-14/program.py b/Python/program-14/program.py new file mode 100644 index 00000000..f1530142 --- /dev/null +++ b/Python/program-14/program.py @@ -0,0 +1,16 @@ +# Python3 program to find simple interest +# 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) + print('The rate of interest is',r) + + si = (p * t * r)/100 + + print('The Simple Interest is', si) + return si + +# Driver code +simple_interest(8, 6, 8) \ No newline at end of file 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-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-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-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 new file mode 100644 index 00000000..99238315 --- /dev/null +++ b/Python/program-5/README.md @@ -0,0 +1,10 @@ +Program 5 + +This program gives the following pattern: + + 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/pragram.py b/Python/program-5/pragram.py new file mode 100644 index 00000000..e067d825 --- /dev/null +++ b/Python/program-5/pragram.py @@ -0,0 +1,10 @@ +for i in range(1,6): + for j in range(1,6-i): + print(" ",end=" ") + for k in range(1,i+1): + print(k,end=" ") + if i>1: + for l in range(1,i+1): + print(l,end=" ") + print() + \ No newline at end of file diff --git a/Python/program-6/README.md b/Python/program-6/README.md new file mode 100644 index 00000000..55a615a3 --- /dev/null +++ b/Python/program-6/README.md @@ -0,0 +1,10 @@ +Program 6 + +The code gives the following pattern : + +1 +2 2 +3 3 3 +4 4 4 4 +5 5 5 5 5 + diff --git a/Python/program-6/program.py b/Python/program-6/program.py new file mode 100644 index 00000000..456583e0 --- /dev/null +++ b/Python/program-6/program.py @@ -0,0 +1,4 @@ +for i in range(1,6): + for j in range(1,i+1): + print(i,end=' ') + print() diff --git a/Python/program-7/program.py b/Python/program-7/program.py new file mode 100644 index 00000000..601bfdbb --- /dev/null +++ b/Python/program-7/program.py @@ -0,0 +1,8 @@ +#pattern +for i in range(1,6): + for j in range (1,6-i): + print(" ",end=" ") + for k in range(1,i+1): + print(k,end=" ") + print() + \ No newline at end of file diff --git a/Python/program-7/readme.md b/Python/program-7/readme.md new file mode 100644 index 00000000..4f87ac17 --- /dev/null +++ b/Python/program-7/readme.md @@ -0,0 +1,6 @@ +Program to print the following pattern + 1 + 1 2 + 1 2 3 + 1 2 3 4 +1 2 3 4 5 \ No newline at end of file diff --git a/Python/program-8/program.py b/Python/program-8/program.py new file mode 100644 index 00000000..683d48d8 --- /dev/null +++ b/Python/program-8/program.py @@ -0,0 +1,6 @@ +c=0 +for i in range(0,4): + for j in range(i+1): + print(c,end=" ") + c=c+1 + print() \ No newline at end of file diff --git a/Python/program-8/readme.md b/Python/program-8/readme.md new file mode 100644 index 00000000..a3b103b0 --- /dev/null +++ b/Python/program-8/readme.md @@ -0,0 +1,5 @@ +program to print the given pattern +0 +1 2 +3 4 5 +6 7 8 9 \ No newline at end of file diff --git a/Python/program-9/program.py b/Python/program-9/program.py new file mode 100644 index 00000000..7e0967c6 --- /dev/null +++ b/Python/program-9/program.py @@ -0,0 +1,22 @@ +#Python Program to Find Armstrong Number in an Interval + + +lower = 100 +upper = 2000 + +for num in range(lower, upper + 1): + + # order of number + order = len(str(num)) + + # initialize sum + sum = 0 + + temp = num + while temp > 0: + digit = temp % 10 + sum += digit ** order + temp //= 10 + + if num == sum: + print(num) diff --git a/gif/giphy.gif b/gif/giphy.gif new file mode 100644 index 00000000..c5360b3a Binary files /dev/null and b/gif/giphy.gif differ diff --git a/readme.md b/readme.md index 25413caa..17b64228 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,12 @@ -# Basic programs +

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)