Category: C program

python tutorials and learn python

Created with Sketch.

C Programming Code To Create Pyramid and Pattern

C Programming Code To Create Pyramid and Pattern Examples to print half pyramid, pyramid, inverted pyramid, Pascal’s Triangle, and Floyd’s triangle in C Programming using control statements.     Example code to create pyramids and patterns in C programming language:   Pattern These are just examples and can be modified to create different patterns and…
Read more

C Program to Display its own Source Code as Output

C Program to Display its own Source Code as Output In this example, you’ll learn to display the program’s source using the __FILE__ macro. Though this problem seems complex but, the concept behind this program is straightforward; display the content from the exact file you are writing the source code.   A predefined macro __FILE__…
Read more

C Program to Read a Line From a File and Display it

C Program to Read a Line From a File and Display it This program reads text from a file and stores it in a string until entering the ‘newline’ character is encountered. Example: Program to read text from a file If the file program.txt is not found, this program prints an error message. If the…
Read more

C Program to Write a Sentence to a File

C Program to Write a Sentence to a File In this example, you’ll learn to write a sentence to a file using fprintf() statement. This program stores a sentence entered by the user in a file.   Output Enter sentence: I am awesome and so are files. After the termination of this program, you can…
Read more

C Program to Store Information Using Structures with Dynamically Memory Allocation

C Program to Store Information Using Structures with Dynamically Memory Allocation In this example, you’ll learn to store information using structures by allocation of dynamic memory using malloc(). This program asks the user to store the value of noOfRecords and allocates the memory for the noOfRecords structure variable dynamically using malloc() function.   Example: Demonstrate the Dynamic…
Read more

C Program to Store Information of Students Using Structure

C Program to Store Information of Students Using Structure This program stores the information (name, roll and marks) of 10 students using structures. In this program, a structure, student is created. This structure has three members: name (string), roll (integer) and marks (float). Then, we created a structure array of size 10 to store information…
Read more

C Program to Calculate Difference Between Two Time Periods

C Program to Calculate Difference Between Two Time Periods In this example, you’ll learn to calculate the difference between two time periods using the user-defined – differenceBetweenTimePeriod function. Example: Calculate the Difference Between Two Time Periods Output Enter start time: Enter hours, minutes and seconds respectively: 12 34 55 Enter stop time: Enter hours, minutes…
Read more

C Program to Add Two Complex Numbers by Passing Structure to a Function

C Program to Add Two Complex Numbers by Passing Structure to a Function This program takes two complex numbers as structures and adds them with the use of functions. Example: Add Two Complex Numbers   Output For 1st complex number Enter real and imaginary part respectively: 2.3 4.5 For 2nd complex number Enter real and…
Read more

C Program to Add Two Distances (in inch-feet) System Using Structures

C Program to Add Two Distances (in inch-feet) System Using Structures This program takes two distances (in an inch-feet system), adds them and displays the result on the To understand this example, you should have the knowledge of following C programming topics: Example: Program to add two distances in an inch-feet system Output Enter information…
Read more

C Program to Store Information of a Student Using Structure

C Program to Store Information of a Student Using Structure Introduction In this C programming tutorial, we will create a program to store information about a student using a structure. A structure is a composite data type in C that allows you to group variables of different data types under a single name. We will…
Read more