Found 1339 Articles for C

C Program for Round Robin scheduling

Sunidhi Bansal
Updated on 23-Dec-2019 07:41:30

9K+ Views

We are given with the n processes with their corresponding burst time and time quantum and the task is to find the average waiting time and average turnaround time and display the result.What is Round Robin Scheduling?Round robin is a CPU scheduling algorithm that is designed especially for time sharing systems. It is more like a FCFS scheduling algorithm with one change that in Round Robin processes are bounded with a quantum time size. A small unit of time is known as Time Quantum or Time Slice. Time quantum can range from 10 to 100 milliseconds. CPU treat ready queue ... Read More

Priority Queue Introduction in C/C++

Sunidhi Bansal
Updated on 23-Dec-2019 07:25:27

527 Views

A priority queue is a type of queue in which elements are inserted or deleted according to the priorities assigned to them where priority is an integer value that can range between 0-10 where 0 shows the element with the highest priority and 10 shows the element with the lowest priority. There are two rules that are followed for implementing priority queue −Data or element with the highest priority will get executed before the data or element with the lowest priority.If two elements have the same priority than they will be executed in the sequence they are added in the ... Read More

Priority Queue using Linked List in C

Sunidhi Bansal
Updated on 23-Dec-2019 07:15:27

4K+ Views

We are given with the data and the priority as an integer value and the task is to create a linked list as per the priority given and display the result.Queue is a FIFO data structure in which the element which is inserted first is the first one to get removed. A Priority Queue is a type of queue in which elements can be inserted or deleted depending upon the priority. It can be implemented using queue, stack or linked list data structure. Priority queue is implemented by following these rules −Data or element with the highest priority will get ... Read More

C Program for FCFS Scheduling

Sunidhi Bansal
Updated on 02-Sep-2023 13:57:50

54K+ 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 processWaiting Time is the difference between turnaround time and burst timeWaiting Time = turnaround time – burst timeWhat is FCFS Scheduling?First Come, First Served (FCFS) also known as First In, First Out ... Read More

C Program for focal length of a lens

Sunidhi Bansal
Updated on 20-Dec-2019 11:20:43

410 Views

Given two floating values; image distance and object distance from a lens; the task is to print the focal length of the lens.What is focal length?Focal length of an optical system is the distance between the center of lens or curved mirror and its focus.Let’s understand with the help of figure given below −In the above figure i is the object, and F is the image of the object which is formed and f is the focal length of the image.So to find the focal length of the image from the lens the formula is −1F= 1O+1IWhere, F is the ... Read More

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

Arnab Chakraborty
Updated on 17-Dec-2019 13:26:14

122 Views

Here we will see some program that will return different results if they are compiled in C or C++ compilers. We can find many such programs, but here we are discussing about some of them.In C and C++, the character literals are treated as different manner. In C, they are treated as int but in C++, they are treated as characters. So if we check the size using sizeof() operator, it will return 4 in C, and 1 in C++.Example Live Demo#include int main() {    printf("The character: %c, size(%d)", 'a', sizeof('a')); }OutputThe character: a, size(4)Example#include int main() {    printf("The ... Read More

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

Arnab Chakraborty
Updated on 02-Dec-2024 11:54:26

7K+ Views

As we know the bit-wise AND is represented as ‘&’ and the logical operator is represented as ‘&&’. There are some fundamental differences between them. These are as follows − bitwise AND operator The bitwise AND (&) operator performs a bit-by-bit AND operation between two integers. The bitwise AND operator works on integer, short int, long, unsigned int type data, and also returns that type of data. Here, Each bit should be 1 to give the result as 1, else it will result in 0, 1 & 1 = 11 & 0 = 00 & 1 = 00 & 0 ... Read More

C Program Coin Change

sudhir sharma
Updated on 22-Nov-2019 09:28:52

3K+ Views

In this problem, we are given a value n, and we want to make change of n rupees, and we have n number of coins each of value ranging from 1 to m. And we have to return the total number of ways in which make the sum.ExampleInput : N = 6 ; coins = {1, 2, 4}. Output : 6 Explanation : The total combination that make the sum of 6 is : {1, 1, 1, 1, 1, 1} ; {1, 1, 1, 1, 2}; {1, 1, 2, 2}; {1, 1, 4}; {2, 2, 2} ; {2, 4}.Example#include ... Read More

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

sudhir sharma
Updated on 08-Nov-2023 00:13:33

27K+ Views

We are given a graph with a source vertex in the graph. And we have to find the shortest path from the source vertex to all other vertices of the graph. The Dijikstra's algorithm is a greedy algorithm to find the shortest path from the source vertex of the graph to the root node of the graph. Algorithm Step 1 : Create a set shortPath to store vertices that come in the way of the shortest path tree. Step 2 : Initialize all distance values as INFINITE and assign distance values as 0 for source vertex so that it is ... Read More

Binary to Gray code using recursion in C program

sudhir sharma
Updated on 09-Jul-2020 11:49:04

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 number of the code cannot differ more than one bit. This property of gray code makes it useful more 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.ExampleLet’s take an example of gray code coInput : 1001 Output : 1101AlgorithmStep 1 : Do with input n :    Step 1.1 : if n ... Read More

Advertisements