Programming Articles

Page 960 of 2547

C Program for Round Robin scheduling

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 10K+ Views

Round Robin is a CPU scheduling algorithm designed for time-sharing systems. It operates like FCFS scheduling but with a crucial difference − each process gets a fixed time slice called a time quantum. When a process's time quantum expires, it is preempted and moved to the back of the ready queue, allowing other processes to execute. What is Round Robin Scheduling? Round Robin treats the ready queue as a circular queue where each process gets a small unit of time (10-100 milliseconds typically). The main advantages include fair CPU allocation and good response time for interactive systems. The ...

Read More

Priority Queue using Linked List in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 5K+ Views

A priority queue is a special type of queue where elements are served based on their priority rather than the order of insertion. In C, we can implement a priority queue using a linked list where each node contains data, priority, and a pointer to the next node. In a priority queue, elements with higher priority (lower numerical value) are processed first. If two elements have the same priority, they follow FIFO order. Syntax typedef struct node { int data; int priority; struct node* ...

Read More

C Program for FCFS Scheduling

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 56K+ Views

We are given with the n number of processes i.e. P1, P2, P3, ..., Pn and their corresponding burst times. The task is to find the average waiting time and average turnaround time using FCFS CPU Scheduling algorithm. What is Waiting Time and Turnaround Time? Turnaround Time is the time interval between the submission of a process and its completion. Turnaround Time = completion of a process − submission of a process Waiting Time is the difference between turnaround time and burst time Waiting Time = turnaround time − burst time What is FCFS Scheduling? ...

Read More

C Program for focal length of a lens

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 481 Views

In optics, the focal length is a fundamental property of lenses that determines their converging or diverging power. Given the image distance and object distance from a lens, we can calculate the focal length using the lens equation. What is Focal Length? Focal length of an optical system is the distance between the center of lens or curved mirror and its focus. It represents the distance over which initially collimated rays are brought to a focus. ...

Read More

Code valid in both C and C++ but produce different output

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 195 Views

Here we will see programs that return different results when compiled with C or C++ compilers. These differences arise due to fundamental variations in how C and C++ handle certain language features. Character Literal Size Differences In C, character literals like 'a' are treated as int type, while in C++ they are treated as char type. This affects the result of the sizeof() operator − Example 1: C Code #include int main() { printf("Character: %c, Size: %d bytes", 'a', sizeof('a')); return 0; } ...

Read More

What are the differences between bitwise and logical AND operators in C/C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 8K+ Views

In C, the bitwise AND (&) and logical AND (&&) operators serve different purposes and work with different data types. Understanding their differences is crucial for correct C programming. Syntax // Bitwise AND result = operand1 & operand2; // Logical AND result = condition1 && condition2; Bitwise AND Operator (&) The bitwise AND (&) operator performs a bit-by-bit AND operation between two integers. It works on integer types and returns the same data type. Each corresponding bit is AND-ed according to these rules − 1 & 1 = 1 ...

Read More

C Program Coin Change

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 4K+ Views

In this problem, we are given a value n, and we want to make change of n rupees using a given set of coin denominations. We need to return the total number of ways to make the sum using these coins. Syntax int coinChange(int coins[], int numCoins, int amount); Example Input/Output Input: N = 6, coins = {1, 2, 4} Output: 6 Explanation: The total combinations that make the sum of 6 are: {1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 2}, {1, 1, 2, 2}, {1, 1, 4}, {2, 2, ...

Read More

C / C++ Program for Dijkstra\'s shortest path algorithm

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 27K+ Views

Dijkstra's algorithm is a greedy algorithm used to find the shortest path from a source vertex to all other vertices in a weighted graph. It works by maintaining a set of vertices whose shortest distance from the source has been determined and gradually expanding this set until all vertices are included. Syntax void dijkstra(int graph[V][V], int source); Algorithm Steps Step 1: Create a set to store vertices included in shortest path tree Step 2: Initialize all distances as INFINITE and source distance as 0 Step 3: Loop until all vertices are processed: ...

Read More

Binary to Gray code using recursion in C program

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 2K+ Views

A Binary number is a number that has only two bits 0 and 1. Gray code is a special type of binary number that has a property that two successive numbers of the code cannot differ by more than one bit. This property of gray code makes it useful in K-maps, error correction, communication, etc. This makes the conversion of binary to gray code necessary. So, let's see an algorithm to convert binary to gray code using recursion. Syntax int binaryToGray(int binary); Algorithm Step 1: For input n: Step ...

Read More

Binary Search for Rational Numbers without using floating point arithmetic in C program

sudhir sharma
sudhir sharma
Updated on 15-Mar-2026 318 Views

In this problem, we are given a sorted array of rational numbers and we have to search the given element using binary search algorithm without using floating point arithmetic. A Rational number is a number represented in the form p/q where both p and q are integers. For example, 2/3, 1/5. Binary search is a searching technique that works by finding the middle of the array and comparing elements to determine which half contains the target. For finding the element using binary search from a sorted array of rational numbers, where floating point arithmetic is not allowed, ...

Read More
Showing 9591–9600 of 25,466 articles
« Prev 1 958 959 960 961 962 2547 Next »
Advertisements