C Programming Example

C Example for Beginners: C Program to Display its own Source Code as Output

(C programming Example for Beginners) 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, the concept behind this program is straightforward; display the content from the same file you are writing the source code. In …

C Example for Beginners: C Program to Write a Sentence to a File

(C programming Example for Beginners) C Program to Write a Sentence to a File In this example, you will learn to write a sentence in a file using fprintf() statement. This program stores a sentence entered by the user in a file. #include <stdio.h> #include <stdlib.h> int main(){ char sentence[1000]; // creating file pointer to …

C Example for Beginners: C Program to Store Information of Students Using Structure

(C programming Example for Beginners) C Program to Store Information of Students Using Structure In this example, you will learn to store the information of 5 students by using an array of structures. Store Information in Structure and Display it #include <stdio.h> struct student { char firstName[50]; int roll; float marks; } s[10]; int main(){ …

C Example for Beginners: C Program to Add Two Complex Numbers by Passing Structure to a Function

(C programming Example for Beginners) C Program to Add Two Complex Numbers by Passing Structure to a Function In this example, you will learn to take two complex numbers as structures and add them by creating a user-defined function. Add Two Complex Numbers #include <stdio.h> typedef struct complex { float real; float imag; } complex; …

C Example for Beginners: C Program to Store Information of a Student Using Structure

(C programming Example for Beginners) C Program to Store Information of a Student Using Structure In this example, you will learn to store the information of a student in a structure and display them on the screen. Store Information and Display it Using Structure #include <stdio.h> struct student { char name[50]; int roll; float marks; …

C Example for Beginners: C Program to Concatenate Two Strings

(C programming Example for Beginners) C Program to Concatenate Two Strings In this example, you will learn to concatenate two strings manually without using the strcat() function. As you know, the best way to concatenate two strings in C programming is by using the strcat() function. However, in this example, we will concatenate two strings manually. Concatenate …

C Example for Beginners: C Program to Remove all Characters in a String Except Alphabets

(C programming Example for Beginners) C Program to Remove all Characters in a String Except Alphabets In this example, you will learn to remove all the characters from a string entered by the user except the alphabets. Remove Characters in String Except Alphabets #include <stdio.h> int main(){ char line[150]; printf(“Enter a string: “); fgets(line, sizeof(line), …

C Example for Beginners: C Program to Find the Frequency of Characters in a String

(C programming Example for Beginners) C Program to Find the Frequency of Characters in a String In this example, you will learn to find the frequency of a character in a string. Find the Frequency of a Character #include <stdio.h> int main(){ char str[1000], ch; int count = 0; printf(“Enter a string: “); fgets(str, sizeof(str), …

C Example for Beginners: C Program to Find Largest Number Using Dynamic Memory Allocation

(C programming Example for Beginners) C Program to Find Largest Number Using Dynamic Memory Allocation In this example, you will learn to find the largest number entered by the user in a dynamically allocated memory. Find the Largest Element in a Dynamically Allocated Memory #include <stdio.h> #include <stdlib.h> int main(){ int num; float *data; printf(“Enter …