Found 1401 Articles for C

Product of N with its largest odd digit in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:07:52

348 Views

Given a number N with we have to product the number with its largest odd digit. If there is no odd digit then print -1.Like we have initialized N with “153” and the largest odd digit in this number is 5 so the result would be the product of 153 with 5 i.e. 153 * 5 = 765 and if the number has no odd digit like 246 then the output must be -1.Input − N = 198Output − 1782Explanation − 198 * 9 = 1782Input − N = 15382Output − 76910Explanation − 15382 * 5 = 76910Approach used below ... Read More

Product of maximum in first array and minimum in second in C

Sunidhi Bansal
Updated on 13-Aug-2020 08:05:26

207 Views

Given two arrays arr1[] and arr2[] of some size n1 and n2 respectively, we have to find the product of maximum element of first array arr1[] and minimum element of the second array arr2[].Like we have elements in arr1[] = {5, 1, 6, 8, 9} and in arr2[] = {2, 9, 8, 5, 3} so the maximum element in arr1 is 9 and the minimum element in arr2 is 2 so the product of both is 9*2 = 18, likewise we have to write a program to solve the given problem.Input arr1[] = {6, 2, 5, 4, 1} arr2[] = {3, ... Read More

Bitwise recursive addition of two integers in C

sudhir sharma
Updated on 05-Aug-2020 08:00:49

3K+ Views

In this problem, we are given two numbers. Our task is to create a C program for the Bitwise recursive addition of two integers.The logic to find the sum using the Bitwise operations is similar to what we used to do when we were in preschool. For finding the sum, we used to add each digit of the number and if a carry is there, we add it to the next digit.We will do a similar thing, find the sum using the XOR operator and check for the carry using the AND operation. If there is a carry we will ... Read More

C Programming Language Standard

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

974 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

839 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

278 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

224 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

473 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

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

Advertisements