C Programming

Create a digital clock using Python-Turtle

Create a digital clock using Python-Turtle

Prerequisites: Turtle in programming Python. Turtle is a special feature of Python. Using Turtle, we can easily draw on a drawing board. First, we import the turtle module. Then create a window, next we create a turtle object and using the turtle methods we can draw on the drawing board. In this blog we'll be creating a digital clock using turtle and python. Installation:  To install this module type the below command in the terminal. pip install turtle Note: To create a clock we will use the ‘time’ and ‘DateTime’ module of Python also, To install time use the following command:…
Read More
How to start programming? Step By Step Guide

How to start programming? Step By Step Guide

Programming is the key to getting success in a tech carrier, when I talk about programming I mean efficient programming. It means the coding which is time and space-efficient. How can we make programs which is time and space-efficient by learning data structure and Algorithms? So that’s why data structure and algorithms are so much required for preparing for interviews. Now there is a huge list of websites that are there for preparing these algorithms and these algorithms and data structures are mostly used during interviews as when we are working in Industry we mostly focus on API development and using the…
Read More
What are the good websites to learn data structures and algorithms?

What are the good websites to learn data structures and algorithms?

Well! Programming is fun once you get it and the great part is a decent developer gets an enormous check from Top Tech Giants Like (Google, Amazon, Walmart, Microsoft, Facebook, and Apple). Data Structure and algorithms are needed for breaking interviews in these first-rate organizations. Regardless of whether you are a fledgling or middle in Algorithm abilities for the most part learning complete data structure, required 2-3 months. Likewise, getting ready code without help from anyone else is the fundamental model for the arrangement cycle. The following are a few decent assets for learning Data structure and Algorithms: 1. Geeksforgeeks: Geeksforgeeks has an expanse of issues.…
Read More
Search an element in a sorted and rotated array

Search an element in a sorted and rotated array

An element in a sorted array can be found in O(log n) time via binary search. But suppose we rotate an ascending order sorted array at some pivot unknown to you beforehand. So for instance, 1 2 3 4 5 might become 3 4 5 1 2. Devise a way to find an element in the rotated array in O(log n) time. Example:   Input : arr[] = {5, 6, 7, 8, 9, 10, 1, 2, 3}; key = 3 Output : Found at index 8 Input : arr[] = {5, 6, 7, 8, 9, 10, 1, 2, 3}; key = 30…
Read More
Program to cyclically rotate an array by one

Program to cyclically rotate an array by one

Given an array, cyclically rotate the array clockwise by one.  Examples: Input: arr[] = {1, 2, 3, 4, 5} Output: arr[] = {5, 1, 2, 3, 4} Following are steps for Array Rotation.  Store last element in a variable say x. Shift all elements one position ahead. Replace first element of array with x. #include <stdio.h> void rotate(int arr[], int n) { int x = arr[n-1], i; for (i = n-1; i > 0; i--) arr[i] = arr[i-1]; arr[0] = x; } int main() { int arr[] = {1, 2, 3, 4, 5}, i; int n = sizeof(arr)/sizeof(arr[0]); printf("Given array is\n"); for…
Read More
C Program for Fibonacci numbers

C Program for Fibonacci numbers

The Fibonacci numbers are the numbers in the following integer sequence.0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, …….. In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation  Fn = Fn-1 + Fn-2 with seed values  F0 = 0 and F1 = 1. Given a number n, print n-th Number.  Examples:  Input : n = 2 Output : 1 Input : n = 9 Output : 34 Following are different methods to get the nth Fibonacci number.  Method 1 (Use recursion)  A simple method that is a direct recursive…
Read More
Program to find the pair with a given sum in an array

Program to find the pair with a given sum in an array

We are given an array that is sorted and then rotated around an unknown point. Find if the array has a pair with a given sum ‘x’. It may be assumed that all elements in the array are distinct. Examples :  Input: arr[] = {11, 15, 6, 8, 9, 10}, x = 26 Output: true There is a pair (11, 15) with sum 26 Input: arr[] = {11, 15, 26, 38, 9, 10}, x = 35 Output: true There is a pair (26, 9) with sum 35 Input: arr[] = {11, 15, 26, 38, 9, 10}, x = 52 Output:…
Read More
Block Swap algorithm for array rotation

Block Swap algorithm for array rotation

Write a function rotate(ar[], d, n) that rotates arr[] of size n by d elements using block swap algorithm Algorithm : Initialize A = arr[0..d-1] and B = arr[d..n-1]1) Do following until size of A is equal to size of B a) If A is shorter, divide B into Bl and Br such that Br is of samelength as A. Swap A and Br to change ABlBr into BrBlA. Now Ais at its final place, so recur on pieces of B. b) If A is longer, divide A into Al and Ar such that Al is of samelength as B…
Read More
C Program to implement Binary Search

C Program to implement Binary Search

We are given a sorted array of size n. We have to write program to find an element x in arr[]. In the previous post we have implemented linear search. Now we are going to implement another approach to search it. This approach is called Binary Search. Binary Search - Search an element in sorted array by repeatedly dividing the search interval in half. Begin with an interval covering the whole array. If the value of the search key is less than the item in the middle of the interval, narrow the interval to the lower half. Otherwise, narrow it…
Read More