Category: Programming

Traversing a Binary Tree in C

There are generally 3 traversal strategies for Binary Trees – INORDER, PREORDER and POSTORDER. For eg:, the inorder, preorder and postorder traversal of an expression tree...

C program for Hailstones series

Hailstones is a sequence of numbers that could be generated from any positive number by performing a specific operation on it until it reaches 1....

for loops in C

The ‘for’  loop is another important looping structure which could replace ‘while’  and ‘do .. while’ loops. It has a special feature that the initialization,...

C program to implement Russian Peasant

Here is a C program that I wrote years back to implement Russian Peasant method of an interesting multiplication technique – main(){ int a, b,...

While Loop in C

Like do-while loop, While loop is the most commonly used looping construct to repeat a process or calculation for a set or collection of inputs...

Do – While Loops in C

Looping constructs is an important programming language technique to repeat a process or calculation for a set or collection of inputs or storage based on...

C Program to check for leap year

Here is a C program to check for leap year – main () { int year; printf("Please enter any year as 4 digits>> "); scanf("%d",...

Making decision in C program

Decision making is an important aspect of programming language that enables the programmer to arrive at a conclusion based on certain data processing, comparisons and conditional...

Declaring variables in C language

C programming language allows to define and classify data so we can use it appropriately in various parts of the program in the correct form...

C Programming Language

C language developed at Bell lab by Dennis Ritchie on UNIX environment. UNIX was later rewritten in C. An earlier version of C is BCPL...

Recursive C program for Binary search

Below is an example Recursive C program to perform Binary – int binsearch(int low, int high, in a, X){ int mid; if(low > high){ return(-1);...

Bubble sort in C

Simple bubble sort in C – for (i=0; i<n-1; i++){ for(j=i+1; j<n; j++){ if(x[j] < x[i]){ temp = x[j]; x[j] = x[i]; x[i] = temp;...

File Operation in C

Below is a simple C program to perform file operation – include <stdlib.h> main() { FILE * file_source char * file_name = (char*) malloc (sizeof...

Traversing a Binary Tree in Preorder

A binary tree can be traversed in two basic ways – preorder and postorder. Explained below is the process or preorder traverse of a binary...

Binary Tree

Binary Tree is a basic data structure that is used behind the scenes of all major technologies whether it’s a Database system or operating system,...

Simple HTTP log analyzer

Here is a simple light weight HTTP analyzer written in PHP. I wrote this to brush up my skills writing schedulers for a typical LAMP...

Stack Vs Heap

Stack and Heap refers to 2 distinct memory areas utilized by an executing program based on the data type of data that it deals at...

What is the purpose of static modifier?

Static modifier is commonly used in all programming languages. There are two distinct reasons for using the static modifier whether its C, Java, C#, PHP or...

Arrays Vs Lists – Which one to use?

Both Arrays and Lists helps us to store list of elements. But which one to choose is an important design decision that is directly related...

C# File, Directory Manipulation

C# provide two versions of File, Directory manipulation options – 1) Static methods based and 2) Instance methods based. Static method based operations are provided...

MVC Architecture

MVC architecture has been in place since past 4 decades or so when GUI (Graphical Use Interfaces) started to be used widely. The idea is simple...

C# Program to find Age

Below is a C# program to find Age from a Date of Birth. Enjoy! public class Person    {        public string Name { get; set; }        public Person(DateTime birthdate)        {            BirthDate = birthdate;        }        public DateTime BirthDate { get; private set; }        public int Age{                        get { ...

Usage of params modifier in C#

Lets see how to use params modifier in C#. The perfect example is Calculator implementation. ‘params’ access modifier when used on a method argument, allows...

Constructor overloading in C#

Constructors need to be overloaded depending on what extend of data/properties need to be initialized in order to set the object to a particular state....

Using LINQ in C#

LINQ or Language Integrated Query gives the capability to query objects and C# allows two distinctive ways to achieve this – You can either use LINQ...

Using DateTime in C#

Below is very simple usage of DateTime – class DateTimePr     {         static void Main(string args)         {             var datetime = new DateTime();             var now = DateTime.Now;             var today = DateTime.Today;             Console.WriteLine(now);             Console.WriteLine(today);             Console.WriteLine(now.Hour);             Console.WriteLine(now.ToLongDateString());             Console.WriteLine(now.ToString());         }     }...

Reading a file in C#

Below is a simple program in C# that reads a file and outputs the longest word in it. Enjoy! using System; using System.IO; using System.Collections.Generic; namespace <yourNS> {     class FilesNDirs...

Finding Lowest number from a List in C#

Below is a simple program to find the lowest number from a list of numbers – using System; using System.Collections.Generic; namespace GroundCSApp {     class GetSmallest     {         public static void Main(string argvs)         {             var numlist = new List<int> { 1, 2, 3, 4, 5, 6 };...

Simple C# Programs

Here is some basic, simple, handy C# programs for you to enjoy and refresh your memory – using GroundCSApp; using System; using System.Collections.Generic; using System.Linq; namespace GroundCSApp {     public enum ShippingMethod     {...

Code Reuse via Composition in C#

Composition is a common object oriented concept that enables us to implement loose coupling as well as code-reuse. Lot of times we recommend our developers...

Constructor Inheritance in C#

Like any other Object Oriented Programming language, C# does not allow parent constructor to be automatically inherited. It need to explicitly defined in the derived...

Dynamic Typing in C#

Well, C# provides this option to prove that it is flexible. If you are too fond of dynamic typing, use scripting languages such as PHP!...

C# Generics

C# Generics are really useful when we want to reuse a class for different types and with constraints on what those types would be without...

C# Indexers

C# Indexers is a simple implementation of key/value pairs using Dictionary type. Below is a sample implementation of a telephone directory –TelephoneDirectory class using System.Collections.Generic; namespace Indexers...

C# Inheritance

We generally apply the concept of inheritance to implement a IS-A relationship. For example to implement a relationship that says an Apple is a Fruit...

C# Abstract Classes Vs Interfaces

We use abstract classes when the base class can’t have concrete implementation and that we need the derived class to fully implement it. If at...

Simple Stop Watch implementation in C#

Below is a simple stop watch implemented in C#, enjoy!StopWatch using System; namespace StopWatchApp {     public class StopWatch     {         public DateTime StarTime { get; set; }         public DateTime StopTime { get; set; }         public string ClockState { get; set; }         public void StartClock()         {             if(this.ClockState == "started")                 throw new InvalidOperationException("Invalid Operation");             this.StarTime = DateTime.Now;             this.ClockState = "started";         }...

Simple Workflow Engine Implementation in C#

Below is a simple implementation of work flow engine using interfaces and the concept of injecting overloaded class implementations via the dependent class method. The...