Found 1401 Articles for C

C Program for Naive algorithm for Pattern Searching

sudhir sharma
Updated on 24-Dec-2019 06:18:02

7K+ Views

Pattern matching in C− We have to find if a string is present in another string, as an example, the string "algorithm” is present within the string "naive algorithm". If it is found, then its location (i.e. position it is present at) is displayed. We tend to create a function that receives 2 character arrays and returns the position if matching happens otherwise returns -1.Input: txt = "HERE IS A NICE CAP"    pattern = "NICE" Output: Pattern found at index 10 Input: txt = "XYZXACAADXYZXYZX"    pattern = "XYZX" Output: Pattern found at index 0    Pattern found at ... Read More

C Program for Minimum number of jumps to reach the end

sudhir sharma
Updated on 24-Dec-2019 06:12:27

524 Views

We are given, an array of non-negative integers denoting the maximum number of steps that can be made forward from that element. The pointer is initially positioned at the first index [0 index] of the array. Your goal is to reach the last index of the array in the minimum number of steps. If it is not possible to reach the end of the array then print the maximum integer.naive approach is to begin from initial{the primary} component and recursively call for all the components accessible from the first element. The minimum range of jumps to reach the end from ... Read More

C Program for Minimum Cost Path

sudhir sharma
Updated on 24-Dec-2019 06:06:27

719 Views

Here, we will solve the minimum cost path problem in C. The implication is done on a 2D-matrix where each cell has a cost to travel. We have to find a path from the left top corner to the bottom right corner with minimum travel cost. You can only traverse down and right lower cells from a given cell.To solve this particular problem dynamic programming is much better to approach than recursion.Given cost matrix cost[ ][ ] and a position (m, n), we have to write a function that returns cost of minimum path to reach (m, n) from (0, ... Read More

Problem with scanf() when there is fgets()/gets()/scanf() after it in C

Sunidhi Bansal
Updated on 23-Dec-2019 11:37:34

415 Views

The problem states that what will be the working or the output if the scanf is followed by fgets()/gets()/scanf().fgets()/gets() followed by scanf()Example Live Demo#include int main() {    int x;    char str[100];    scanf("%d", &x);    fgets(str, 100, stdin);    printf("x = %d, str = %s", x, str);    return 0; }OutputInput: 30 String Output: x = 30, str =Explanationfgets() and gets() are used to take string input from the user at the run time. I above code when we run enter the integer value then it won’t take the string value because when we gave newline after the integer ... Read More

Process Synchronization in C/C++

Sunidhi Bansal
Updated on 23-Dec-2019 11:33:09

6K+ Views

Process synchronization is the technique to overcome the problem of concurrent access to shared data which can result in data inconsistency. A cooperating process is the one which can affect or be affected by other process which will lead to inconsistency in processes data therefore Process synchronization is required for consistency of data.The Critical-Section ProblemEvery process has a reserved segment of code which is known as Critical Section. In this section, process can change common variables, update tables, write files, etc. The key point to note about critical section is that when one process is executing in its critical section, ... Read More

Printing source of a C program itself

Sunidhi Bansal
Updated on 23-Dec-2019 11:01:17

520 Views

Given the task is to print the written C program itself.We have to write a C program which will print itself. So, we can use file system in C to print the contents of the file of which we are writing the code, like we are writing the code in “code 1.c” file, so we open the file in the read mode and read all the contents of the file and print the results on the output screen.But, before opening a file in read mode, we must know the name of the file we are writing code in. So, we ... Read More

C Program for Round Robin scheduling

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

8K+ 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

338 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

3K+ 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

46K+ 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

Advertisements