Posts

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...

Bubble Sort in C language

Image
Bubble sort is the simplest Sorting algorithm available. It works by repeatedly swapping the adjacent or neighbor element if they are in the wrong order. Working Actually in first pass bubble sort sets the largest element to its position, in the second pass algorithm sets the second largest element this continues till the list or array is not finally sorted. Here is the example image. To work with the algorithm you first have to understand what is swapping and how it is done. What is Swapping ?? Swapping is the technique to interchange the content of the two variables, using another variable called temporary variable. For the program in C #include <stdio.h> void bubbleSort(int s[],int size){ int c,swap,d; for (c = 0 ; c < size - 1; c++) { for (d = 0 ; d < size - c - 1; d++) { if (s[d] > s[d+1]) /* For decreasing order use < */ { swap = s[d]; s[d] = s[d+1]; s[d+1] = swap...

Distributed Systems AKTU (UPTU) lab program

Image
Distributed system DS is the subject mandatory subject in the seventh semester of the final year of Computer Science in Dr. APJ Abdul Kalam Technical University. Lab practical Questions. Assignment 1 Assignment 2 Assignment 3 Assignment 4 For the completed Answer of these assignments are in the link given below. Answers Thanks for being here. Subscribe to this blog for more post like this.

Learning C language part 2 Basics of C

Image
Welcome to the second part of this Series of C language. In this series, we will start with the basic of C language. Previous post Environment Setup Text Editor Install any of the text editor available in the market, suggestion consist of the Sublime Text Editor, notepad++ etc. I have been using Sublime Text Editor. Compiler Install the compiler if you have not previously then check out this post. Installing C/C++ (GCC) compiler On Windows Basics of C Before starting anything lets take a look at the minimum code required to run a C program. Now we are going to do the Most famous ritual of the programming, Program of Hello World. #include <stdio.h> int main(int argc, char const *argv[]) { printf("Hello World!\n"); return 0; } save this program as the hello.c this will give output as like Comments in C comment is of two types in C. first // this is single line comment in c Second, /* this is multiline comment in c language */ Semicolons in C A semicolon terminates the ...