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.   List of Source Code Code to print triangles using *, digits and characters Code to print inverted triangles using * and digits Code to print full pyramids…
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 source of the program using __FILE__ macro. Though this problem seems complex but, the concept behind this program is very simple; display the content from the same 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 enter ‘newline’ character is encountered. Example: Program to read text from a file #include <stdio.h> #include <stdlib.h> // For exit() function int main() { char c[1000]; FILE *fptr; if…
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 user in a file. #include <stdio.h> #include <stdlib.h> /* For exit() function */ int main() { char sentence[1000]; FILE *fptr; fptr = fopen(“program.txt”, “w”);…
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 dynamic memory using malloc(). This program asks user to store the value of noOfRecords¬†and allocates the memory for the noOfRecords¬†structure variable dynamically using malloc() function. Example: Demonstrate the Dynamic Memory Allocation for…
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 user defined – differenceBetweenTimePeriod function. Example: Calculate Difference Between Two Time Periods #include <stdio.h> struct TIME { int seconds; int minutes; int hours; }; void differenceBetweenTimePeriod(struct TIME t1, struct TIME t2, struct…
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 #include <stdio.h> typedef struct complex { float real; float imag; } complex; complex add(complex n1,complex n2); int main() { complex n1,…
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 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 inch-feet system #include <stdio.h> struct Distance {…
Read more

C Program to Store Information of a Student Using Structure

C Program to Store Information of a Student Using Structure This program stores the information (name, roll and marks) of a student and displays it on the screen using structures. In this program, a structure, student is created. This structure has three members: name (string), roll (integer) and marks (float). Then, a structure variable s…
Read more