C Programs for Practice: Learn Simple C Programs for Beginners

Simple C Programs for Beginners

In this article, let’s learn some of the basic but essential programs to understand C fundamentals.

1. Write a program to compute the Fibonacci series.

The Fibonacci series (also called Fibonacci numbers) is the sum of the two preceding numbers. The sequence commonly starts from 0 and 1. A Fibonacci series can be given as 0, 1, 1, 2, 3, 5, 8, 13, … Let’s implement the Fibonacci series with the help of the below C program.

When you execute the above program, the output will look like this as shown below:

Enter number of terms you want to print: 8
0  1  1  2  3  5  8  13

2. Write a program to find if the given number is Prime or not.

A number that is divisible only by itself and 1 is called a Prime number. For example, 2, 3, 5, 7, 11, … Let’s implement this with the help of the below C program.

When you execute the above program, the output will look like this as shown below:

Enter any number to check: 41
Given number is prime number.

3. Write a program to convert numbers to words.

This simple C program takes a single-digit number between 0-9 and prints it in words. Let’s implement it in the C program.

When you execute the above program, the output will look like this as shown below:

Enter any number (0 - 9): 5
Five

4. Write a program to find the sum of digits of any entered number.

This simple C program takes any number and calculates the sum of each digit. For example, user entered 1234 then the output will be 1+2+3+4=10. Let’s implement it in the C program.

When you execute the above program, the output will look like this as shown below:

Enter any number: 1234
Sum of digit is: 10

5. Write a program to insert an element in One Dimensional Array (ODA) at a given position.

This simple C program inserts an element in a given array into a specified position and prints it with the newly added item. Let’s implement it in the C program.

When you execute the above program, the output will look like as shown below:

Enter the size of array: 4
Enter element at [1] position: 1
Enter element at [2] position: 3
Enter element at [3] position: 4
Enter element at [4] position: 5

Enter the location and item: 2 2

Array after insertion:
Element at [1] position: 1
Element at [2] position: 2
Element at [3] position: 3
Element at [4] position: 4
Element at [5] position: 5

6. Write a program to arrange string data (student name) in alphabetical order using bubble sort.

This simple C program sorts the string array using the bubble sort method. Let’s implement it in the C program.

When you execute the above program, the output will look like this as shown below:

Enter total number of names: 3
Enter [1] student name: Ram
Enter [2] student name: Shyam
Enter [3] student name: Ramesh

Student name after sorted in alphabetical order:
Ram
Ramesh
Shyam

7. Write a program to multiply two-dimensional array (3×3) matrixes.

Let’s implement the C program to multiply 3 x 3 matrixes.

When you execute the above program, the output will look like this as shown below:

Enter row and column size of matrix A: 3 3
Enter elements of matrix A:
1 2 3
4 5 6
7 8 9

Matrix A:
1 2 3
4 5 6
7 8 9

Enter row and column size of matrix B: 3 3
Enter elements of matrix B:
1 2 3
4 5 6
7 8 9

Matrix B:
1 2 3
4 5 6
7 8 9

Matrix can be multiplied!

Matrix C:
30 36 42
66 81 96
102 126 150

8. Write a program to find the largest element in Two Dimensional Array (TDA).

In this program, we will learn how to find the largest number from a given two dimension array. Let’s implement it in the C program.

When you execute the above program, the output will look like this as shown below:

Enter row of array: 3
Enter column of array: 3

Enter elements of array:
1 2 3
4 5 6
7 8 9

Elements in Matrix:
1 2 3
4 5 6
7 8 9

Largest element in given TDA: 9

9. Write a program to check if a given string is Palindrome or not.

A palindromic number/string is a number/string that remains the same when its digits/characters are reversed. Let’s implement it in the C program.

When you execute the above program, the output will look like this as shown below:

Enter the string to check palindrome: nitin
String is Palindrome!

10. Write a program to find the Factorial of a given number using a recursive function.

The Factorial of a positive integer (number) is the sum of the multiplication of all the integers smaller than that positive integer denoted by “!”. For example, the factorial of 4 is 4 * 3 * 2 * 1 which equals 24. Let’s implement it in a C program with a recursive function.

When you execute the above program, the output will look like this as shown below:

Enter any number: 5
Factorial of 5 is: 120

11. Write a program using the function to find the sum of two numbers with an argument and no return value.

Let’s implement it in a C program to implement a function that does not have any arguments and does not return any value.

When you execute the above program, the output will look like this as shown below:

Enter first number: 5
Enter second number: 6
Sum of two numbers: 11

12. Write a program to demonstrate passing structure to functions using call by value.

Let’s implement it in the C program to implement struct and function using call by value. The fields in the struct are empNo, empName, basicSalary.

When you execute the above program, the output will look like this as shown below:

Enter employee number: 101
Enter employee name: Shyam
Enter employee basic salary: 15000

Employee number: 101
Employee name: Shyam
Employee basic salary: 15000

13. Write a program to demonstrate passing structure to functions using call by reference.

Let’s implement it in the C program to implement struct and function with a call by reference. The fields in struct are empNo, empName, basicSalary.

When you execute the above program, the output will look like this as shown below:

Enter employee number: 102
Enter employee name: Ramesh
Enter employee basic salary: 13000

Employee number: 102
Employee name: Ramesh
Employee basic salary: 13000

14. Write a program to swap the value of two variables by passing pointers.

The pointer in C language is a variable that stores the address of another variable which can be by any data type like int, char, array, function, or any other pointer. Let’s implement it in a C program to swap values by passing pointers to functions.

When you execute the above program, the output will look like this as shown below:

Enter the value of A: 10
Enter the value of B: 20

Value of A & B after swapping.
Value of A: 20
Value of B: 10

15. Write a program to create a sequential file and perform operations: 1. Process records, 2. Display output.

When you execute the above program and open the file COLLEGE1.txt, the output will look like this:

101 Kavita 56 78 45
102 Prachi 65 67 89
103 Pradip 32 44 67
104 Roshni 67 89 87

Related:
Simple C Programs Based on Discrete Mathematics
Simple C Programs Based on the Mathematical Statistics

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top