You are here

C programming

To quickly learn C language you must start writing programs in it. To do so you need a text editor and a compiler to translate a source program into machine code that can be executed directly on a machine. Dev C++ IDE is a good choice, so if you are not having it installed on your computer then download Dev C++ compiler.

C programs list

Hello world
Print Integer
Addition
Odd or Even
Add, subtract, multiply and divide
Check vowel
Leap year
Add digits
Factorial
HCF and LCM
Decimal to binary conversion
nCr and nPr
Add n numbers
Swapping
Reverse number
Palindrome number
Print Pattern
Diamond
Prime numbers
Find armstrong number
Generate armstrong number
Fibonacci series
Print floyd's triangle
Print pascal triangle
Addition using pointers
Maximum element in array
Minimum element in array
Linear search
Binary search
Reverse array
Insert element in array
Delete element from array
Merge arrays
Bubble sort
Insertion sort
Selection sort
Add matrices
Subtract matrices
Transpose matrix
Multiply two matrices
Print string
String length
Compare strings
Copy string
Concatenate strings
Reverse string
Find palindrome
Delete vowels
C substring
Subsequence
Sort a string
Remove spaces
Change case
Swap strings
Character's frequency
Anagrams
Read file
Copy files
Merge two files
List files in a directory
Delete file
Random numbers
Add complex numbers
Print date
Get IP address
Shutdown computer

Compiling and executing C programs

Now you have the tool to create programs, if you wish to look at some example codes then see C programming examples. How to compile and run your programs? You may be using a different compiler or operating system. We discuss how to use Dev C++, GCC, and Turbo C++ compiler.

Dev C++
1. Create a new file (Ctrl+N).
2. Write the code.
3. Press Ctrl+F9 to compile the program. If there are any compile-time errors then fix them.
4. Press Ctrl+F10 to run the program.

Compiling and running C programs in GCC compiler
1. Save the code in a file say "hello.c" (quotes for clarity)
2. To compile open terminal and type "gcc hello.c"
3. To execute type "./a.out"

You can also specify the output file name as:
gcc hello.c -o hello.out
hello.out is the name of the output file.

Turbo C compiler:
1. Write your code to a file and save it.
2. Compile by pressing Alt + F9.
3. Execute by pressing Ctrl + F9.
4. To view output of the program, press (Alt + F5).

C programming basics

Computer programming means giving instructions to a computer, and to interact with it, we need a language to communicate. There are many languages such as C, C++, Java, Python, and many others, each having their features. Let's discuss first why we need programming? Suppose you have ten numbers to arrange in ascending order, then you can do it easily, but what if the numbers are, say ten thousand. It's a difficult task, takes a long time manually, and the result may also contain errors. To simplify this task, we can write a program that does it. If the algorithm is correct, we get an accurate result in a short amount of time, depending on the processor speed. That's why programming is helpful, and it makes life a lot easier.