Found 1339 Articles for C

C Programming Language Standard

sudhir sharma
Updated on 05-Aug-2020 07:35:32

1K+ Views

In this problem, we will learn about the standards that are defined in the C programming language. These are those standard ways in which the program is to be ideally compiled by the compiler as defined by the development community.To understand what I am saying take an easy example of a common C program that you all must have encountered and have seen the issue coming but haven’t got deep into it.The main() function’s void return type −See the following program −void main() {    //program code }This program will run ok if we use the turbo c compiler but ... Read More

C program to store Student records as Structures and Sort them by Name

sudhir sharma
Updated on 05-Aug-2020 07:34:38

2K+ Views

In this problem, we are given a student’s record which contains student_id, student_name, student_percentage. Our task is to create a C program to store student records as structure and sort them by name.Let’s take an example to understand the problem, Input − student record ={{ student_id = 1, student_name = nupur, student_percentage = 98}, { student_id = 2, student_name = Akash, student_percentage = 75}, { student_id = 3, student_name = Yash, student_percentage = 62}, { student_id = 4, student_name = Jyoti, student_percentage = 87}, { student_id = 5, student_name = Ramlal, student_percentage = 80}}Output − student record ={{ student_id = ... Read More

Maximum number of threads that can be created within a process in C

Sunidhi Bansal
Updated on 04-Aug-2020 12:29:20

1K+ Views

Given the task is to find the maximum number of threads that can be created within a process in C.A thread is lightweight process and can be independently managed by the scheduler. Because a thread is a component of a process, therefore multiple number of threads can be associated in a process and also it takes less time for context switching as it is lighter than the process.Threads require less resources than the processes and they also share memory with its peer threads. All user level peer threads are treated as a single task by the operating system. Less time ... Read More

Count minimum bits to flip such that XOR of A and B equal to C in C++

Sunidhi Bansal
Updated on 28-Jul-2020 11:16:37

377 Views

We are given with three binary sequences A, B and C of length N. Each sequence represents a binary number. We have to find no. of flips required of bits in A and B such that XOR of A and B results in C. A XOR B becomes C.First of all let us learn about truth table of XOR operation −XYX XOR Y000011101110From the above table we observe that for the same values in X and Y, X XOR Y results 0 else it results 1. So this will be helpful for finding bits to be flipped in A and ... Read More

Find a permutation that causes worst case of Merge Sort in C

Arnab Chakraborty
Updated on 23-Jul-2020 08:33:31

312 Views

ConceptWith respect of a given set of elements, determine which permutation of these elements would result in worst case of Merge Sort?We know, asymptotically, merge sort always consumes O(n log n) time, but the cases that need more comparisons generally consume more time in practice. Now we basically require determining a permutation of input elements that would lead to largest number of comparisons when sorted implementing a typical Merge Sort algorithm.Example Consider the below set of elements as Sorted array 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26Resultant input array that will result ... Read More

fillpoly() function in C

Arnab Chakraborty
Updated on 23-Jul-2020 08:18:25

673 Views

ConceptNow the header file graphics.h contains fillpoly() function which is implemented to draw and fill a polygon such as triangle, rectangle, pentagon, hexagon etc. So this function require same arguments as drawpoly().Syntaxvoid fillpoly( int number, int *polypoints );In this case, number indicates (n + 1) number of points where, n is the number of vertices in a polygon and polypoints points to a sequence of (n*2) integers.Input arr[] = {320, 150, 400, 250, 250, 350, 320, 150};Output Explanation So the declaration of fillpoly() contains two arguments: number specifies (n + 1) number of points where n is indicated as the number of vertices ... Read More

Flood fill algorithm using C graphics

Arnab Chakraborty
Updated on 23-Jul-2020 07:34:42

5K+ Views

ConceptWith respect of a given rectangle, our task is to fill this rectangle applying flood fill algorithm.Input rectangle(left = 50, top = 50, right= 100, bottom = 100) floodFill( a = 55, b = 55, NewColor = 12, OldColor = 0)Output Method// A recursive function to replace previous color 'OldColor' at '(a, b)' and all surrounding pixels of (a, b) with new color 'NewColor' and floodFill(a, b, NewColor, OldColor)If a or b is outside the screen, thenreturn.If color of getpixel(a, b) is same asOldColor, thenRecur for top, bottom, right and left.floodFill(a+1, b, NewColor, OldColor);

C Program to Sort an array of names or strings

sudhir sharma
Updated on 18-Jul-2020 06:19:21

2K+ Views

In this problem, we are given an array of string. Our task is to create a c program to sort an array of name or string. This program will sort all the names we have given in the input in ascending alphabetical order.Let’s take an example to understand the problem, InputnamesArray = ["Rishabh", "Jyoti", "Palak", "Akash"]Output["Akash", "jyoti", "palak", "Rishabh"]To solve this we will use the qsort() function of the standard template library as we know sorting of integer values the thing that changes here is we are considering string for comparison instead of integer values.So, the comparator that is used ... Read More

C program to simulate Nondeterministic Finite Automata (NFA)

sudhir sharma
Updated on 18-Jul-2020 06:16:51

4K+ Views

In this problem, we are will create a C program to simulate non-deterministic Finite automata (NFA).NFA (Non-deterministic Finite automata) finite state machine that can move to any combination of states for an input symbol i.e. there is no exact state to which the machine will move.Formal definition of NDFA −NFA / NDFA (Non-deterministic Finite automata) can be represented by 5-tuple (Q, ∑, δ, q0, F) where −Q is a finite set of states.∑ is a finite set of symbols called the alphabets.δ is the transition function where d: Q × ∑ → 2Q (Here the power set of Q (2Q) ... Read More

C Program to reverse each node value in Singly Linked List

sudhir sharma
Updated on 18-Jul-2020 06:09:34

427 Views

In this article, we are given a linked list. Our task is to create a C program to reverse each node value in singly linked list.We will take each node of the linked list and reverse the value.Linked list is a sequence of links that contains items that are linked to another link.Let’s take an example to understand the problem, Input34 12 89 56 72Output43 21 98 65 27To solve this problem, we will traverse the singly linked list and take each node. And then reverse the value of the current node.Program to reverse each node value in Singly Linked ... Read More

Advertisements