Last Updated on April 28, 2023 by Prepbytes
Many interviews generally include questions about C programs. These programs can be used to handle files, arrays, strings, pointers, linked lists, and other fundamental data types.
About C Programming Language
Dennis Ritchie developed the general-purpose computer language C at Bell Laboratories in 1972. Despite being an ancient language, it is quite popular.
Since the UNIX operating system was created using C, the two are closely related.
List of Basic C Programs.
-
Calculate the Percentage of 5 Subjects
It is simple to calculate the percentage of five subjects, all you need to do is add all of the marks and multiply that total by 100. Then divide that by the total number of marks a student is permitted to receive. You will ultimately receive the results as a percentage of the 5 subjects.Input:
50 20 30 40 80
Output:
Enter marks of five subjects: Total marks = 220.00 Average marks = 44.00 Percentage = 44.00
-
Convert infix to postfix
Any operation may be written as an infix, prefix, or postfix, in this C language tutorial, we’ll see how to do this. Two approaches have been covered: the array-based stack approach and the struct-based stack approach.Input:
((p+(q*r))-s)
Output:
pqr*+s-
-
Odd Even Program
A number is taken into consideration even though it may be split by two equally. The remainder that is not precisely divisible by 2 is known as an odd number. Simply expressed, odd numbers adopt the form n = 2k+1, whereas even numbers take the form n = 2k. Each integer will be made up of either even or odd integers.Input:
10
Output:
Even
Input:
15
Output:
Odd
-
Find area of a circle
Everyone knows the basics of mathematics,
For finding the area of a circle, we can get this by performing someArea = Pie * Radius * Radius
Where the value of pie = 3.14 and the radius will be given by the user.
Input:
10
Output:
The radius of the circle is 10 The area of a given circle is 314.000000
-
Convert Celsius to Fahrenheit
In the realm of programming, we may easily convert between celsius and fahrenheit by carrying out a few simple mathematical operations.
The formula to change from celsius to fahrenheit is shown below.Formula
Fahrenheit Temperature = (1.8 * celsius) + 32;
Input:
40
Output:
104
-
Add two numbers
In the C programming language, the phrase "sum of two integers" refers to adding two integer values and printing the addition of two integer values and the printing of the result. To combine two numbers, all we need to do is utilize the "+" operator. In the link above, we have also explained several techniques.Input:
10 20
Output:
30
Input:
20 20
Output:
40
-
Binary Search program in C
In the C programming language, a sorted array may be searched using a technique called binary search by continually halving the search interval. In order to reduce the time complexity to O, binary search makes use of the fact that the array is sorted (LogN).
This approach always searches the center of an array for the element.
There are two ways to create a binary search program in C:- Iterative Method
- Recursive Method
Input:
[11, 14, 25, 30, 40, 45]
40
Output:Element is present at position 4
-
Priority Scheduling program in C
The algorithms prioritize the processes that must be carried out and schedule them accordingly. A higher-priority process will receive CPU priority first, and this will continue until all of the processes are finished. Due to the process’ greater priority, the Priority Scheduling Algorithm is in charge of transferring it from the ready queue to the work queue.Input:
{{1, 10, 2}, {2, 5, 0}, {3, 8, 1}}
Output:
Order in which processes get executed 1 3 2
Processes Burst time Waiting time Turn around time
1 10 0 10
3 8 10 18
2 5 18 23Average waiting time = 9.33333
Average turn around time = 17 -
Find roots of quadratic equation
A quadratic has the formula y = ax^2 + bx + c, where a, b, and c are all integers and a must be 0. An illustration of a quadratic equation is 3×2 + 3x + 1.
Let’s talk about what a quadratic equation’s roots are and how to get them from the equation.
The discriminant of a quadratic equation is the expression b2 – 4ac. It describes the roots’ character.Input:
a = 2.4 b = 4 c = 506
Output:
root1 = -0.87+1.30i and root2 = -0.87-1.30i
-
Convert binary numbers to decimal number
In order to convert a binary number to a decimal number, we must multiply each digit of the binary number starting at 0 by powers of 2 and then sum the results to obtain the decimal number.Input:
111
Output:7
Input:
0101
Output:
5
-
Ascending order program in C language
Different kinds of reasoning can be used to sort things. For the sake of simplicity, we shall employ a tried-and-true technique. We choose a certain element from an array, compare it to other elements, and then place it appropriately to sort the array.Input:
Arr[50, 20, 100, 25, 36]
Output:
20 25 36 50 100
Input:
Arr[5, 8, 2, 1, 6]
Output:
1 2 5 6 8
-
SJF Scheduling program in C
One of the CPU scheduling strategies is to select the shortest jobs first. It is an algorithm whose burst time-dependent procedure. In other words, a process with a lower burst time executes first. The shortest job next (SJN) is another name for the shortest job first (SJF). For instance, we have four processes, P1, P2, P3, and P4, with burst times of 5, 7, 6, and 2. Process P4 will now be run first since it has a shorter burst period. Processes P1, P3, and P2 will then be carried out in that order.Output:
enter the no of processes: 2 the arrival time for process P1: 10 the burst time for process P1: 5 the arrival time for process P2: 6 the burst time for process P2 : 3 P[10] | -22765 | -32764
average waiting time = -16382.000000
average turnaround time = -11382.500000 -
Menu Driven program for all operations on the doubly linked list in C.
In the menu-driven program in C, the user is given a variety of options, and some functionality is available based on these choices. These programs are used to give users the desired functions and a straightforward yet effective user interface.Output:
1 To see list 2 For insertion at starting 3 For insertion at end 4 For insertion at any position 5 For deletion of first element 6 For deletion of last element 7 For deletion of element at any position 8 To exit Enter Choice : 2 Enter number to be inserted: 4 1 To see list 2 For insertion at starting 3 For insertion at end 4 For insertion at any position 5 For deletion of first element 6 For deletion of last element 7 For deletion of element at any position 8 To exit Enter Choice : 3 Enter number to be inserted: 11 1 To see list 2 For insertion at starting 3 For insertion at end 4 For insertion at any position 5 For deletion of first element 6 For deletion of last element 7 For deletion of element at any position 8 To exit Enter Choice : 3 Enter number to be inserted: 9 1 To see list 2 For insertion at starting 3 For insertion at end 4 For insertion at any position 5 For deletion of first element 6 For deletion of last element 7 For deletion of element at any position 8 To exit Enter Choice: 1 Data = 4 Data = 11 Data = 9
-
FCFS Scheduling program in C
The CPU assigns work using a non-preemptive scheduling mechanism called First Come First Serve. According to the request that was made initially, as the name implies, the tasks are given the highest priority.Output:
Processes Burst time Waiting time Turn around time 1 10 0 10 2 5 10 15 3 8 15 23
Average waiting time = 8.33333
Average turnaround time = 16 -
Swap two Numbers
When two numbers are changed, two variables’ values are also changed. Think about the variables var1 and var2 you have. Var1 is valued at 20, whereas Var2 is valued at 40. As a result, after swapping, var1 and var2 will have values of 40 and 20, respectively.
We have discussed different methods such as:- Swapping Two Numbers Using a Third Variable
- Swapping Two Numbers Using Without Using Third Variable
- Swapping Function in C
- Swap two numbers using pointers in C
- Swap Two Numbers Using Bitwise XOR
Input:
a = 20 b = 40
Output:
a = 40 b = 20
-
Compound Interest Program
To calculate the amount of interest given by:
Amount of interest = P(1+R/100)t
P = Principal amount
R = Rate of interest
T = The Time span
Compound Interest = Amount – PInput:
Principal (amount): 1200 Time: 2 Rate: 5.4
Output:
Compound Interest = 133.099243
-
Radix Sort Program
Each digit is sorted in the Radix sort algorithm from least to greatest significance. In base 10, radix sort would first sort by the digits in the place of one, then by the digits in the place of ten, and so on. Radix sort uses counting sort as a subroutine to order the data in each digit position.Input:
312 42 635 11 8 783 954 777
Output:
8 11 42 312 635 777 783 954
Input:
50 40 30 10 96 100
Output:
10 30 40 50 96 100
-
Bubble sort on Linked List
The bubble sort’s fundamental principle is to compare each member of an array individually until they are sorted in ascending order, a process known as bubble busting. Instead of shifting the entire array when an element has to be moved, the impacted element is just moved.Input:
Linked list before sorting 8 -> 2 -> 4 -> 1 -> 5
Output:
Linked list after sorting 1 -> 2 -> 4 -> 5 -> 8
-
Round-Robin Scheduling
With round-robin scheduling, each job receives an equal amount of CPU time. In its most basic form, jobs are placed in a circular queue, where they are moved to the back of the queue when their allotted CPU time runs out and to the front when a new task is added.Output:
Total number of processes in the system: 4 Enter the Arrival and Burst time of the Process[1] Enter Arrival time: 0 Enter Burst time: 5 Enter the Arrival and Burst time of the Process[2] Enter Arrival time: 1 Enter Burst time: 4 Enter the Arrival and Burst time of the Process[3] Enter Arrival time: 2 Enter Burst time: 2 Enter the Arrival and Burst time of the Process[4] Enter Arrival time: 4 Enter Burst time: 1 Enter the Time Quantum for the process: 2
-
Reverse a Number
Using the modulo division (%) function, find the final digit of the provided integer, and then save the result in the last digit variable, for example, last digit=number%10. Reversed is equal to reversed times 10 plus the final digit, therefore reversed is reversed times 10 plus the last digit. Like numbered/10, multiply the number by 10.Input:
6789
Output:
9876
Conclusion
This blog covers all the basic C Programs. You can just brush up on your basic concepts through this article. We hope this article will help you to enhance your knowledge.
You May Also Like to Read
DFS Program in C
BFS Program in C
Singly Linked List Program in C
Structure of C Program with Example
Selection Sort Program in C
Calculator Program in C Language
C Program For Merge Sort For Linked Lists
Insertion Sort Program in C
How to Implement Selection Sort in C?
C Program for Matrix Addition
C program to Reverse a Linked List
Star Program in C
Doubly Linked List Program in C
Simple Interest Program in C
Bit Stuffing Program in C
Perfect Number Program in C
While Loop Program in C
Graphics Program in C
Hello World Program in C
C Program for Armstrong Number
Matrix Multiplication Program in C
Linear Search Program in C
Switch Case Program in C
C Program to Convert Decimal Numbers to Binary Numbers
Pascal Triangle Program in C
How to write string programs in C
Leap Year Program in C
Program to Find Largest of 3 Numbers
Area of Rectangle Program in C
Area of Triangle Program in C
String Program in C