Posts

Showing posts from April, 2019

Python program for Fibonacci series using Recursion

Image
What is the Fibonacci series The Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ... The next number is found by adding up the two numbers before it. The 2 is found by adding the two numbers before it (1+1) The 3 is found by adding the two numbers before it (1+2), And the 5 is (2+3), and so on! Example: the next number in the sequence above is 21+34 =  55 code for Fibonacci series is terms = int(input("how many terms? : ")) #taking the input from the user #using recursion to print the series def recur_fibo(n,a1,a2): if n <= 1: #return this if terms is less than 1 print(a1) return else: print(str(a1) , end=" , ") return(recur_fibo(n-1,a2,a1 + a2)) #checking for the negative number and single terms if terms <= 0: print("Please enter a positive integer") elif terms == 1: print("Fibonacci Sequence of 1 terms : ") print(0) else: recur_fibo(terms,0,1) to veri

Creating Square, Rectangle, Multiply, slash using * (star) using C

Image
In the process of learning the basic of C language people often create shapes using the *, and these shapes question are also asked in the interview question and selection exam of various companies so it is very good to learn how to make various shapes. Rectangle we can also make multiply etc. Multiply Code for the above images it is in the order of images. #include <iostream> using namespace std; int main() { int size; cout << "Enter Number "; cin >> size; cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ cout << "*"; } cout << endl; } cout << endl; for(int i=0;i<size;i++){ for(int j=0;j<size;j++){ if(i == j) cout << "*"; else cout << " "; } cout << endl; } cout << endl; for(int i=0;i<size;i++)

Selection Sort using C language (with every step)

Image
What is selection sorting The selection algorithm sorts an array by repeatedly finding the smallest element (considering increasing or ascending order) from the unsorted part and putting it at the beginning. The algorithm maintains two subarrays in a given group. 1) Subarray that is already sorted. 2) Remaining subarray that is unsorted. At each iteration of selection, the minimum value (with regard to rising order) is sorted from the unsorted subarray and moved to the sorted subframe. Code #include <stdio.h> void swap(int *xp, int *yp) { int temp = *xp; *xp = *yp; *yp = temp; } void selectionSort(int a[], int n) { int i, j, minIndex; printf("sorting array of length %d...\n",n); // n-1 changed to n for (i = 0; i < n; i++) { // in selection sort we find the smallest element // from array and put it aside, then we // find the next smallest in the remaining array // again, and go on and go on // pri

Calculating Julian Day Number (JDN) using C++

Image
what is Julian Day Number Julian Day is the continuous number of days since the beginning of the Julian period and is mainly used by astronomers and in software to easily calculate past days between two events (eg, food production date and sales by date). Code #include<iostream> #include <limits> using namespace std; void input_data(int &month, int &year, int &day,int &bmonth, int &byear, int &bday); void calculations(int month, int year, int day, int &jdn); void output_results(int &month, int &year, int &day, int &jdn,int d); void calculate_dow(int &jdn , int &dow); void calculate_difference_and_print(int jdn , int bjdn); void pause(); int main() { int bday; int bmonth; int byear; int bjdn; int day; int month; int year; int jdn; int dow; int bdow; input_data(month, year, day,bmonth, byear, bday); // calculate JDN for the present day calculations(month, year, day, jdn); // calculat