learn C programming from examples. The list of c programs includes the various C’s concept such as functions, loops, structures, variables, pointers, string, array, etc.
String
- Reverse a String
- Palindrome string
- String Array
- Sort String array in Alphabetical Order
- Remove Duplicate Characters in a String
- Count Vowels and Consonants
- Remove Vowels from String
- Concatenate Two Strings
Number
- Palindrome Number
- Armstrong Number
- Neon Number
- Magic Number
- Perfect Number
- Strong Number
- Automorphic Number
- Fascinating Number
- Harshad Number
- Swap 2 Numbers without using 3rd Variable
- Minimum Prime Factor
- Display Factors of a Number
Mathematics
- Check Leap Year
- Factorial of a Number
- Prime Numbers From 1 to N
- Find LCM of Two Numbers
- Find LCM of Array of Numbers
- Find GCD of Two Numbers
- Find GCD of Array of Numbers
Number Conversion
Array
- Reverse Array without Using another Array
- Delete Duplicate Elements in an Array
- Find Second Largest in an Array
- Merge Two Sorted Arrays into One
- Insert Element at nth Position
Matrix
- Matrix addition in C
- Matrix addition using the linked list
- Matrix multiplication in C
- Transpose of Matrix
- Check for Identity Matrix
- Minimum in Row and Maximum in Column
- Search Element in 2D array
- Smallest and Largest Element of the Diagonals
Recursion
Structure
Patterns
Command Line Arguments
The best way to learn to program is by practicing on your own. So we recommend you to code on your own after reading our programming examples.
To Practise C programming you will need a text editor and a c/c++ compiler. If you don’t have that, you can download the Dev-C++ IDE to run your c or c++ source code on your machine.
You can also code C language online using an online platform like repl.it which is absolutely free.
Unlike C++, Java, and Python – C is not an object-oriented programming language so for a newbie it is the best language to learn because knowing the logic of how the code works and runs? is more important than learning cool complex features of OOP.
So let’s start with Hello World Program in C.
#include <stdio.h>
int main(void) {
printf("Hello World\n");
return 0;
}
Output: Hello World
If you are not familiar with the basic concepts of c language then don’t worry. Let’s Learn C together.
Basics of C Language
The smallest fundamental unit of the C program is known as Token. For example, if you break down c programs into smaller parts, the smallest to have some meaning or significance is considered as a Token.
Example: if, for, int, main, return, ;, +, -, class, #, myVariable, etc.
The main types of Tokens in C are:
- Keywords: These are the words that are reserved for special purpose in C language e.g default. switch, if, class, char, int, etc.
- Operators: These types of tokens in C are basically use to perform mathematical or logical operations e.g +, -, ||, & etc.
- Identifiers: These are the names given to program elements such as array, variable, function to identify them for use e.g student_id, add, roll_no etc.
- Constants: These are the types of tokens whose values remains fixed through out the program. It can be of two types:
- Numeric Constant: such as const int num = 2.
- Character constant: such as ‘\n’, ‘\b’.
Variables in C
A variable is named storage which can hold single or more values.
Example:
#include <stdio.h>
int main(void) {
int x=4, y=5;
printf("%d\n",(x+y));
return 0;
}
The above program output 9. x and y are variables that are used to store 4 and 5 respectively.
Now variables in C can be of two types:
A local variable is a variable whose value is confined to a particular scope or function and a global variable can be accessed or modified throughout the program.