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

  • 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 – 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.
  • Display Days of Week using enum Keyword in C
    This C program uses enumerated types to display days of week. The enumerated type is then declared as a different name using typedef keyword i.e. enum days  to typedef enum days days. The function prints for each day of the week, today, yesterday, and tomorrow, both as a string and as a number.
  • Graphical Scientific Calculator with Advance Features
    This is a C implementation of basic and few advance scientific features of calculator. It shows a nice graphical UI of the calculator with 3D buttons and demonstrates click button animation functionality. The functionalities of the calculator includes: Basic Mathematics (Add, Subtract, Multiply and Divide), Advance Mathematics (Square root, Square, Cube), Logarithmic Functions (Log, Natural Log (ln), e, Exponential), Number Conversions (Binary, Decimal, Hexadecimal and Octal), Trigonometric Functions (Sine, Cosine, Tangent, Cotangent, Secant and Cosecant), Angle Measurement (Degree, Radia and Gradian), Other Functions (Memory, Pi and Inv).
  • Multiplication of Two Matrices in C
    This C code multiplies two 2×2 matrices. It prompts the user to input values for both matrices, displays the input matrices, performs matrix multiplication using nested loops, and then prints the resulting matrix. The code adheres to modern C standards, using printf and scanf for I/O and avoiding outdated functions for better readability and compatibility.
  • C Program to Add Sequence of Numbers
    This C program reads a sequence of positive integers as input by the user and print their sum. The program keeps on taking the input from user until user enters number ( 0 ) and program calculates the sum of all input numbers. Finally this C program prints the sum of all the numbers on screen and terminates.

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.
  • Java Swing GUI Example Program
    This Java source code is an example of a Graphical User Interface (GUI) with different GUI elements such as TextBox, Buttons, TextArea, Text Area and Labels. It is implemented using Java Swing API which provides a set of “lightweight” (all-Java language) components. This code example extends the functionality of JFrame class to show a JFrame window and Implements ActionListener on buttons to catch the click event on those buttons.

Scroll to Top