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 NumberThis 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 LineThis 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 CThis 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 FeaturesThis 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 CThis 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 NumbersThis 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
- C++ Code – Wave File Converter from Text FileThis C++ program is capable of turning a text file describing the notes of a piece of music into an audio file (.wav). The program reads the contents of the input file i.e. input.txt, constructs Song, Voice and Note objects… Read more: C++ Code – Wave File Converter from Text File
- Design patterns“describe a problem which occurs over and over again in our environment, and then describe the core of the solution to that problem, in such a way that you can use this solution a million times over, without ever doing… Read more: Design patterns
- C++ Convert a number from base A to base BThis is a C++ class which has a member function that takes 3 arguments and converts the number from first base to second base. It takes the following arguments. – std::string thestlstring – int base – int base2
- C++ Program to demonstrate SnakeMan gameIt is a snake game same as in Nokia Mobile Phones written n C++ using Turbo C++ compiler. I assure that you would love it. The code is quite simple to understand. I would be happy if you visit it.
- TIC-TAC-TOE Enhanced Version – C++This is an enhanced version of Tic-Tac-Toe (TTT) game by adding one more row and column. Actually I have played this newer version of Tic-Tac-Toe (TTT) game on a video game. So, when I learnt C/C++ programming, it was my wish to program this game myself using C/C++.
- C++ Source Code: Exception HandlingError recovery is a fundamental concern for every program you write, and it’s especially important in C++, in which one of the goals is to create program components for others to use. To create a robust system, each component must… Read more: C++ Source Code: Exception Handling
JavaScript Source Code
- Difference Between [] and {}: Arrays vs. Objects in JavaScriptIn 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 FormatsThis 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 TimestampThis 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 PHPA 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 PHPThis 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 PHPThis 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 ListThis 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 SwingThis 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 ProgramThis 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.


















