The Wayback Machine - https://web.archive.org/web/20241119175754/https://www.geeksforgeeks.org/c-programming-examples/
Open In App

C Programs

Last Updated : 11 Oct, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

To learn anything effectively, practicing and solving problems is essential. To help you master C programming, we have compiled over 100 C programming examples across various categories, including basic C programs, Fibonacci series, strings, arrays, base conversions, pattern printing, pointers, and more. These C Examples cover a range of questions, from fundamental concepts to advanced topics, and are frequently asked in C-based programming interviews.

C Programs

C Program Topics:

Prerequisite: Before you start with these C programs, take a look at our C tutorial to get a good understanding of the basics. Bascally, C programming is a versatile language that powers many foundational systems. For those looking to strengthen their skills in C and master data structures, the C Programming Course Online with Data Structures offers a variety of example programs and deep dives into practical applications.

C Program – Basic

  1. C Hello World Program
  2. C Program to Print Your Own Name 
  3. C Program to Print an Integer Entered By the User
  4. C Program to Add Two Numbers
  5. C Program to Check Whether a Number is Prime or Not
  6. C Program to Multiply two Floating-Point Numbers 
  7. C Program to Print the ASCII Value of a Character
  8. C Program to Swap Two Numbers
  9. C Program to Calculate Fahrenheit to Celsius
  10. C Program to Find the Size of int, float, double, and char
  11. C Program to Add Two Complex Numbers 
  12. C Program to Print Prime Numbers From 1 to N 
  13. C Program to Find Simple Interest
  14. C Program to Find Compound Interest
  15. C Program for Area And Perimeter Of Rectangle 

C Program – Control Flow

  1. C Program to Check Whether a Number is Positive, Negative, or Zero
  2. C Program to Check Whether Number is Even or Odd
  3. C Program to Check Whether a Character is Vowel or Consonant 
  4. C Program to Find Largest Number Among Three Numbers
  5. C Program to Calculate Sum of Natural Numbers 
  6. C Program to Print Alphabets From A to Z Using Loop
  7. C Program to Check Leap Year
  8. C Program to Find Factorial of a Number
  9. C Program to Make a Simple Calculator 
  10. C Program to Generate Multiplication Table 
  11. C Program to Print Fibonacci Series
  12. C Program to Find LCM of Two Numbers
  13. C Program to Check Armstrong Number
  14. C Program to Display Armstrong Numbers Between 1 to 1000 
  15. C Program to Display Armstrong Number Between Two Intervals 
  16. C Program to Reverse a Number
  17. C Program to Check Whether a Number is a Palindrome or Not 
  18. C Program to Check Whether a Number is Prime or Not
  19. C Program to Display Prime Numbers Between Intervals
  20. C Program to Check whether the input number is a Neon Number
  21. C Program to Find All Factors of a Natural Number
  22. C program to  Sum of Fibonacci Numbers at Even Indexes up to N Terms 

C Program – Pattern Printing

  1. C Program to Print Simple Pyramid Pattern 
  2. C Program to Print Given Triangle 
  3. C Program to Print 1800 Rotation of Simple Pyramid
  4. C Program to Print Inverted Pyramid 
  5. C Program to Print Number Pattern
  6. C Program to Print Character Pattern  
  7. C Program to Print Continuous Character Pattern
  8. C Program to Print Hollow Star Pyramid
  9. C Program to Print Inverted Hollow Star pyramid 
  10. C Program to Print Hollow Star Pyramid in a Diamond Shape
  11. C Program to Print Full Diamond Shape Pyramid
  12. C Program to Print Pascal’s Pattern Triangle Pyramid 
  13. C Program to Print Floyd’s Pattern Triangle Pyramid 
  14. C Program to Print Reverse Floyd pattern Triangle Pyramid 

C Program – Functions

  1. C Program to Check Prime Number By Creating a Function 
  2. C Program to Display Prime Numbers Between Two Intervals Using Functions 
  3. C Program to Find All Roots of a Quadratic Equation
  4. C Program to Check Whether a Number can be Express as Sum of Two Prime Numbers
  5. C Program to Find the Sum of Natural Numbers using Recursion 
  6. C Program to Calculate the Factorial of a Number Using Recursion 
  7. C Program to Find G.C.D Using Recursion
  8. C Program to Reverse a Stack using Recursion
  9. C Program to Calculate Power Using Recursion

C Program – Arrays

  1. C Program to Print a 2D Array
  2. C Program to Find the Largest Element in an Array
  3. C Program to Find the Maximum and Minimum in an Array
  4. C Program to Search an Element in an Array (Binary search)
  5. C Program to Calculate the Average of All the Elements Present in an Array 
  6. C Program to Sort an Array using Bubble Sort
  7. C Program to Sort an Array using Merge Sort
  8. C Program to Sort an Array Using Selection Sort 
  9. C Program to Sort an Array Using Insertion Sort
  10. C Program to Sort the Elements of an Array in Descending Order
  11. C Program to Sort the Elements of an Array in Ascending Order 
  12. C Program to Remove Duplicate Elements From a Sorted Array
  13. C Program to Merge Two Arrays 
  14. C Program to Remove All Occurrences of an Element in an Array 
  15. C Program to Find Common Array Elements  
  16. C Program to Copy All the Elements of One Array to Another Array
  17. C Program For Array Rotation 
  18. C Program to Sort the 2D Array Across Rows
  19. C Program to Check Whether Two Matrices Are Equal or Not 
  20. C Program to Find the Transpose
  21. C Program to Find the Determinant of a Matrix
  22. C Program to Find the Normal and Trace 
  23. C Program to Add Two Matrices
  24. C Program to Multiply Two Matrices
  25. C Program to Print Boundary Elements of a Matrix 
  26. C Program to Rotate Matrix Elements 
  27. C Program to Compute the Sum of Diagonals of a Matrix 
  28. C Program to Interchange Elements of First and Last in a Matrix Across Rows 
  29. C Program to Interchange Elements of First and Last in a Matrix Across Columns 

C Program – Strings

  1. C Program to Add or Concatenate Two Strings
  2. C Program to Add 2 Binary Strings
  3. C Program to Get a Non-Repeating Character From the Given String
  4. C Program to check if the string is palindrome or not
  5. C Program to Reverse an Array or String
  6. C program to Reverse a String Using Recursion
  7. C Program to Find the Length of a String
  8. C Program to Sort a String
  9. C Program to Check For Pangram String
  10. C Program to Print the First Letter of Each Word 
  11. C Program to Determine the Unicode Code Point at a Given Index 
  12. C Program to Remove Leading Zeros 
  13. C Program to Compare Two Strings
  14. C Program to Compare Two Strings Lexicographically 
  15. C Program to Insert a String into Another String
  16. C Program to Split a String into a Number of Sub-Strings 

C Program – Conversions

  1. C Program For Boolean to String Conversion 
  2. C Program For Float to String Conversion
  3. C Program For Double to String Conversion 
  4. C Program For String to Long Conversion
  5. C Program For Long to String Conversion
  6. C Program For Int to Char Conversion 
  7. C Program For Char to Int Conversion 
  8. C Program For Octal to Decimal Conversion 
  9. C Program For Decimal to Octal Conversion
  10. C Program For Hexadecimal to Decimal Conversion 
  11. C Program For Decimal to Hexadecimal Conversion 
  12. C Program For Decimal to Binary Conversion 
  13. C Program For Binary to Decimal Conversion

C Program – Pointers

  1. How to Return a Pointer from a Function in C
  2. How to Declare a Two-Dimensional Array of Pointers in C?
  3. C Program to Find the Largest Element in an Array using Pointers
  4. C Program to Swap Two Numbers
  5. C Program to Sort an Array using Pointers
  6. C Program to Sort a 2D Array of Strings
  7. C Program to Check if a String is a Palindrome using Pointers
  8. C Program to Create a Copy of a Singly Linked List using Recursion

C Program – Structures and Unions

  1. C Program to Store Information of Students Using Structure
  2. C Program to Store Student Records as Structures and Sort them by Name
  3. C Program to Add N Distances Given in inch-feet System using Structures
  4. C Program to Add Two Complex Numbers by Passing Structure to a Function
  5. C Program to Store Student Records as Structures and Sort them by Age or ID
  6. Read/Write Structure to a File in C 
  7. Flexible Array Members in a Structure in C

C Program – File IO

  1. C Program to Create a Temporary File
  2. C Program to Read/Write Structure to a File
  3. C Program to Rename a file
  4. C Program to Make a File Read-Only
  5. C program to Compare Two Files and Report Mismatches
  6. C Program to Copy One File into Another File 
  7. C Program to Print all the Patterns that Match Given Pattern From a File
  8. C Program to Append the Content of One Text File to Another
  9. C Program to Read Content From One File and Write it Into Another File
  10. C Program to Read and Print all Files From a Zip File 

C Program – Date and Time

  1. C Program to Format time in AM-PM format 
  2. C program to Print Digital Clock with the Current Time
  3. C Program to Display Dates of Calendar Year in Different Formats
  4. C Program to Display Current Date and Time
  5. C Program to Maximize Time by Replacing ‘_’ in a Given 24-Hour Format Time
  6. C Program to Convert the Local Time to GMT
  7. C Program to Convert Hours into Minutes and Seconds

C Program – More C Programs

  1. C Program to Show Runtime exceptions 
  2. C Program to Show Types of errors 
  3. C Program to Show Unreachable Code Error 
  4. C Program to Find Quotient and Remainder 
  5. C Program to Find the Initials of a Name 
  6. C Program to Draw a Circle in Graphics
  7. Printing Source Code of a C Program Itself

FAQs on C Program

What is C programming?

C is a structured, high-level, and general-purpose programming language, developed in the early 1970s by Dennis Ritchie at Bell Labs. C language is considered as the mother language of all modern programming languages, widely used for developing system software, embedded software, and application software.

How do I write a “Hello, World!” program in C?

To write a “Hello, World!” program in C, you can use the following code:

#include <stdio.h>

int main() {
  printf(“Hello, World!\n”);
  return 0;
}
This code uses the printf function to display the “Hello, World!” message on the screen.

Why should you learn C Programming?

There are many reasons why you should learn C programming:

  • Versatility
  • Efficiency
  • Portability
  • Widely used
  • Foundation for other languages
  • Employment opportunities and more.


Previous Article
Next Article

Similar Reads

Common Memory/Pointer Related bug in C Programs
Dereferencing an unknown memory location : C programmers mostly use scanf() function to take input, but sometimes a small mistake can bring a bug or even crash whole program. The syntax for scanf() is scanf("%d", &a);. It might be possible to miss a & and write &a as a so now scanf("%d", a); is dereferencing to an unknown location. Now
6 min read
Output of C programs | Set 63
Prerequisite : Structure padding, integer promotion and sequence points. Q1. Consider the following code: C/C++ Code #include<stdio.h> struct geeks{ int i; char c; } obj; int main() { printf("%ld", sizeof(obj)); } What would be the output of the above code? A. 4 B. 5 C. 8 D. Can't be determined Output: Can't be determined Explanatio
4 min read
Facts and Question related to Style of writing programs in C/C++
Here are some questions related to Style of writing C programs: Question-1: Why i++ executes faster than i + 1 ? Answer-1: The expression i++ requires a single machine instruction such as INR to carry out the increment operation whereas, i + 1 requires more instructions to carry out this operation. Question-2: Is writing if(! strcmp(s1, s2) ) a goo
2 min read
Output of C programs | Set 66 (Accessing Memory Locations)
Q1. Is the output of this code True or False? #include <stdio.h> int main(void) { int b = 20; int* y = &b; char n = 'A'; char* z = &n; y[0] = z[0]; printf((*y == *z) ? "True" : "False"); } A. True B. False C. Program would crash D. Compilation error Answer: A. True Explanation: The binary form of 20 is 10100 which
7 min read
CLI programs in C for playing media and shut down the system
Command Line Interface: CLI is a text-based user interface (UI) used to view and manage computer files.Command-line interfaces are also called command-line user interfaces, the console uses interfaces and characters uses interfaces.In programming, the user gives input during the execution of a program i.e., in the running phase. But there are a lot
6 min read
Programs to print Interesting Patterns
Program to print the following pattern: Examples : Input : 5 Output: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * This program is divided into four parts. C/C++ Code // C++ program to print // the given pattern #include<iostream> using namespace std; void pattern(int n
15+ min read
Output of C programs | Set 30 (Switch Case)
Prerequisite - Switch Case in C/C++ Interesting Problems of Switch statement in C/C++ Program 1 #include <stdio.h> int main() { int num = 2; switch (num + 2) { case 1: printf("Case 1: "); case 2: printf("Case 2: "); case 3: printf("Case 3: "); default: printf("Default: "); } return 0; } Output: Default:
2 min read
C/C++ Tricky Programs
We may come across various tricky programs in our day-to-day life. Maybe in technical interviews, coding tests, or C/C++ classrooms. Here is a list of such programs:- Print text within double quotes (" "). This may seem easy, but beginners may get puzzled while printing text within double quotes. C/C++ Code #include <stdio.h> int main() { pri
6 min read
C File Handling Programs
C Program to list all files and sub-directories in a directory C Program to count number of lines in a file C Program to print contents of file C Program to copy contents of one file to another file C Program to merge contents of two files into a third file C program to delete a file
1 min read
Pattern Programs in C
Printing patterns using C programs has always been an interesting problem domain. We can print different patterns like star patterns, pyramid patterns, Floyd's triangle, Pascal's triangle, etc. in C language. These problems generally require the knowledge of loops and if-else statements. In this article, we will discuss the following example progra
15+ min read
Memory Layout of C Programs
A typical memory representation of a C program consists of the following sections. Text segment (i.e. instructions)Initialized data segment Uninitialized data segment (bss)Heap Stack A typical memory layout of a running process 1. Text Segment: A text segment, also known as a code segment or simply as text, is one of the sections of a program's mem
6 min read
C Programming Language Tutorial
In this C Tutorial, you’ll learn all C programming basic to advanced concepts like variables, arrays, pointers, strings, loops, etc. This C Programming Tutorial is designed for both beginners as well as experienced professionals, who’re looking to learn and enhance their knowledge of the C programming language. What is C?C is a general-purpose, pro
8 min read
Difference Between Call by Value and Call by Reference in C
Functions can be invoked in two ways: Call by Value or Call by Reference. These two ways are generally differentiated by the type of values passed to them as parameters. The parameters passed to the function are called actual parameters whereas the parameters received by the function are called formal parameters. Call By Value in CIn call by value
5 min read
C Programs
To learn anything effectively, practicing and solving problems is essential. To help you master C programming, we have compiled over 100 C programming examples across various categories, including basic C programs, Fibonacci series, strings, arrays, base conversions, pattern printing, pointers, and more. These C Examples cover a range of questions,
9 min read
C Functions
A function in C is a set of statements that when called perform some specific tasks. It is the basic building block of a C program that provides modularity and code reusability. The programming statements of a function are enclosed within { } braces, having certain meanings and performing certain operations. They are also called subroutines or proc
10 min read
Switch Statement in C
Switch case statement evaluates a given expression and based on the evaluated value(matching a certain condition), it executes the statements associated with it. Basically, it is used to perform different actions based on different conditions(cases). Switch case statements follow a selection-control mechanism and allow a value to change control of
8 min read
C Programming Interview Questions (2024)
At Bell Labs, Dennis Ritchie developed the C programming language between 1971 and 1973. C is a mid-level structured-oriented programming and general-purpose programming. It is one of the oldest and most popular programming languages. There are many applications in which C programming language is used, including language compilers, operating system
15+ min read
Dynamic Memory Allocation in C using malloc(), calloc(), free() and realloc()
Since C is a structured language, it has some fixed rules for programming. One of them includes changing the size of an array. An array is a collection of items stored at contiguous memory locations. As can be seen, the length (size) of the array above is 9. But what if there is a requirement to change this length (size)? For example, If there is a
9 min read
Basics of File Handling in C
File handling in C is the process in which we create, open, read, write, and close operations on a file. C language provides different functions such as fopen(), fwrite(), fread(), fseek(), fprintf(), etc. to perform input, output, and many different C file operations in our program. Why do we need File Handling in C?So far the operations using the
15 min read
Strings in C
A String in C programming is a sequence of characters terminated with a null character '\0'. The C String is stored as an array of characters. The difference between a character array and a C string is that the string in C is terminated with a unique character '\0'. C String Declaration SyntaxDeclaring a string in C is as simple as declaring a one-
8 min read
Decision Making in C (if , if..else, Nested if, if-else-if )
The conditional statements (also known as decision control structures) such as if, if else, switch, etc. are used for decision-making purposes in C programs. They are also known as Decision-Making Statements and are used to evaluate one or more conditions and make the decision whether to execute a set of statements or not. These decision-making sta
11 min read
Operators in C
In C language, operators are symbols that represent operations to be performed on one or more operands. They are the basic components of the C programming. In this article, we will learn about all the built-in operators in C with examples. What is a C Operator?An operator in C can be defined as the symbol that helps us to perform some specific math
14 min read
C Pointers
Pointers are one of the core components of the C programming language. A pointer can be used to store the memory address of other variables, functions, or even other pointers. The use of pointers allows low-level memory access, dynamic memory allocation, and many other functionality in C. In this article, we will discuss C pointers in detail, their
14 min read
std::sort() in C++ STL
std::sort() is an STL function that is used to sort the given range in desired order. It provides a simple and efficient way to sort the data in C++ but it only works on data structure which have random access to its elements such as vectors and arrays. It is defined inside <algorithm> header file. Syntaxstd::sort (first, last, comp);Paramete
4 min read
Data Types in C
Each variable in C has an associated data type. It specifies the type of data that the variable can store like integer, character, floating, double, etc. Each data type requires different amounts of memory and has some specific operations which can be performed over it. The data types in C can be classified as follows: Types Description Data Types
7 min read
C Arrays
Array in C is one of the most used data structures in C programming. It is a simple and fast way of storing multiple values under a single name. In this article, we will study the different aspects of array in C language such as array declaration, definition, initialization, types of arrays, array syntax, advantages and disadvantages, and many more
15+ min read
C Structures
The structure in C is a user-defined data type that can be used to group items of possibly different types into a single type. The struct keyword is used to define the structure in the C programming language. The items in the structure are called its member and they can be of any valid data type. Additionally, the values of a structure are stored i
10 min read
Bitwise Operators in C
In C, the following 6 operators are bitwise operators (also known as bit operators as they work at the bit-level). They are used to perform bitwise operations in C. The & (bitwise AND) in C takes two numbers as operands and does AND on every bit of two numbers. The result of AND is 1 only if both bits are 1. The | (bitwise OR) in C takes two nu
7 min read
C Language Introduction
C is a procedural programming language initially developed by Dennis Ritchie in the year 1972 at Bell Laboratories of AT&T Labs. It was mainly developed as a system programming language to write the UNIX operating system. The main features of the C language include: General Purpose and PortableLow-level Memory AccessFast SpeedClean SyntaxThese
6 min read
Exception Handling in C++
In C++, exceptions are runtime anomalies or abnormal conditions that a program encounters during its execution. The process of handling these exceptions is called exception handling. Using the exception handling mechanism, the control from one part of the program where the exception occurred can be transferred to another part of the code. So basica
11 min read
Article Tags :
three90RightbarBannerImg