Programming Examples and Source Code

Source code section features a diverse collection of programming examples and source code snippets in C and C++. The examples includes practical implementations, tutorials, and demonstrations aimed at helping programmers enhance to enhance their programming skills.

The best way to learn any programming language is by practicing examples. This source code section features a diverse collection of programming examples and source code snippets written C, C++ and other programming languages.

The examples includes practical implementations, tutorials, and demonstrations aimed at helping programmers enhance to enhance their programming skills.

C Programming Source Code

  • Porter’s Algorithm in C
    Originally written in 1979 at Computer Laboratory, Cambridge (England), it was reprinted in 1997 in the book “Readings in Information Retrieval”. Initially it was written in BCPL language. Here is the list of implementations in other programming languages including C, Java and Pearl implementations done by author himself.
  • Counting Words, Lines and Characters in a Text File in C
    This is a small C language program that can read a text file. The program is given file name as command parameter and it reads the file line by line. The program will prints out number of characters and words in each line.
  • C Program of Library Management System
    This is a C program to implement Library Management System by which a librarian can operate a simple library. It uses Linked List, Stack and Pointers to implement different features of the library system. The program also uses struct data structure to add records in the library.
  • C Program to Calculate Factorial of a Number
    This C program is designed to compute the factorial of a user-entered integer. The program employs a for loop to calculate the factorial and then displays the result. The user can continue inputting positive integers to obtain their factorials until a non-integer input is provided which terminates the program.
  • C Program: Number Shuffling Game
    This C program is a simple console-based implementation of a number-shuffling game. The game presents a grid of numbers, and the objective is to rearrange them in ascending order. The player can move the numbers by pressing the corresponding number keys, and the game tracks the number of moves taken to complete the puzzle.
  • C Program – Tic-Tac-Toe Game – Command Line
    This is a console version of Tic Tac Toe computer game written in c programming language. The game runs in text mode of command prompt and users can play the game in text mode. The game has many options to choose from, like playing with computer, friend. While playing with computer use can select either novice mode or advance mode.

C++ Programming Source Code

JavaScript Source Code

  • Difference Between [] and {}: Arrays vs. Objects in JavaScript
    In JavaScript, we use braces {} for creating an empty object and brackets [] for creating an empty array. I find the Developer console in Mozilla Firefox or Google Chrome more convenient to print out any object and study the details.
  • JavaScript Program to Show Current Time In Various Formats
    This is a small script that can display the current time in “Military Time” format or “12 Hour Time” format with the push of a button. It shows two radio buttons to change the time format and a text box to display the time.
  • JavaScript Program to Show Date and Timestamp
    This is a simple JavaScript Program to show Date and Time Stamp on a webpage. In this script  we define a JavaScript function named getFormattedDateTime. This function uses the Date object to get the current date and time. It then formats them into a human-readable string.

PHP Code Snippets

  • How to Send Email using PHP
    A detailed guide on PHP mail sending options with examples of using the built-in mail function(), PHPMailer, Symfony, and third-party mail service providers such as Amazon SES, SendGrid and GetResponse.
  • Search the LDAP Directory in PHP
    This PHP code connects to an LDAP server, performs a search for entries with the last name and then sorts and prints them alphabetically. The sorting is done by a custom function called compareEntry, which compares entries based on last names and first names. It uses the LDAP functions to communicate with the server and showcases basic error handling.
  • Calculating the Greatest Common Denominator (GCD) in PHP
    This PHP code defines a function called gcd that calculates the greatest common denominator (GCD) of a list of integers by using a brute-force approach and later efficient and widely-used method called Euclidean Algorithm.

Java Source Code

  • Java Program to Demonstrate the Use of Linked List
    This is a very simple implementation of linked list in java programming language. Very nice and well commented java source code for beginners.
  • Simple Image Viewer in Java with Swing
    This Java program is a simple image viewer application designed for novice Java programmers. The program utilizes the Swing library to create a graphical user interface (GUI) with a JFrame, JPanel, and JButton components. The main functionality of the Java program is to select an image file through a JFileChooser dialog, load the selected image and display it within the JPanel.
  • Find Words Frequency in a Text File using Java
    The program demonstrates sorting techniques by sorting a list of words based on their frequency count. Novice programmers can learn about basic file handling, data structures, generics, and sorting algorithms through this program, gaining foundational knowledge applicable to a wide range of Java applications.

Scroll to Top