Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 952 of 2547
Product of maximum in first array and minimum in second in C
Given two arrays, we need to find the product of the maximum element from the first array and the minimum element from the second array. This is a common programming problem that demonstrates array traversal and basic mathematical operations. Syntax int findMaxElement(int arr[], int size); int findMinElement(int arr[], int size); int calculateProduct(int arr1[], int arr2[], int n1, int n2); Method 1: Using Sorting Approach In this approach, we sort both arrays and then multiply the last element of the first array with the first element of the second array − #include ...
Read MoreBitwise recursive addition of two integers in C
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 bitwise operations is similar to manual addition we learned in school. For finding the sum, we add each digit and if a carry is generated, we add it to the next digit position. We will use the XOR operator to find the sum and the AND operation to check for carry. If there is a carry, we recursively add it back to the result. This is the ...
Read MoreC Programming Language Standard
In this article, we will learn about the standards defined in the C programming language. These standards specify how programs should be compiled and executed as defined by the development community. To understand this concept, let's examine a common C program that demonstrates standard compliance issues − What is the C Programming Language Standard? The C programming language standard defines the official specification for how C compilers should behave. It establishes the correct syntax, semantics, and behavior of C programs. The latest C standard is ISO/IEC 9899:2018, also known as C18, which was released in June 2018. ...
Read MoreC program to store Student records as Structures and Sort them by Name
In this problem, we are given a student's record which contains student_id, student_name, and student_percentage. Our task is to create a C program to store student records as structures and sort them by name using string comparison. Syntax struct Student { int student_id; char student_name[50]; int student_percentage; }; int qsort(void *base, size_t nitems, size_t size, int (*compar)(const void *, const void*)); Example Input and Output Input − student record − { student_id = 1, student_name = Nupur, student_percentage = ...
Read MoreMaximum number of threads that can be created within a process in C
In this article, we will explore how to determine the maximum number of threads that can be created within a process in C. Understanding thread limits is crucial for developing efficient multi-threaded applications. A thread is a lightweight process that can be independently managed by the scheduler. Multiple threads can be associated with a single process, and they require less time for context switching compared to processes. Threads share memory with their peer threads and require fewer resources for creation and termination. Syntax int pthread_create(pthread_t *thread, const pthread_attr_t *attr, ...
Read MoreCount minimum bits to flip such that XOR of A and B equal to C in C++
We are given three binary sequences A, B and C of length N. Each sequence represents a binary number. We have to find the number of bit flips required in A and B such that XOR of A and B results in C. Syntax int flipCount(int A[], int B[], int C[], int n); First, let us understand the XOR operation truth table − X ...
Read MoreFind a permutation that causes worst case of Merge Sort in C
Merge sort has a consistent O(n log n) time complexity, but in practice, certain input permutations require more comparisons during the merge operations. The worst case occurs when the merge operation at each level compares every element from both subarrays before completing. Syntax void generateWorstCase(int arr[], int left, int right); Understanding the Worst Case The worst case for merge sort happens when at each merge operation, elements from left and right subarrays are alternately selected. This forces maximum comparisons since we cannot skip any elements during merging. Algorithm To generate the worst ...
Read Morefillpoly() function in C
The fillpoly() function in C is part of the graphics.h library and is used to draw and fill a polygon with the current fill pattern and color. It takes the same arguments as drawpoly() but additionally fills the interior of the polygon. Syntax void fillpoly(int numpoints, int *polypoints); Parameters numpoints − Specifies the number of points in the polygon polypoints − Pointer to an array containing x, y coordinates of each point The polypoints array should contain numpoints * 2 integers, where each pair represents the x and y coordinates of ...
Read MoreFlood fill algorithm using C graphics
The flood fill algorithm is a technique used to fill a connected region with a specific color. It starts from a seed pixel and recursively fills all adjacent pixels that have the same color as the original pixel. Syntax void floodFill(int x, int y, int newColor, int oldColor); Note: This example requires Turbo C/C++ or a compatible graphics library with graphics.h support. Modern compilers may need additional setup for graphics functions. Algorithm Steps The flood fill algorithm follows these steps − Check if the current pixel coordinates are within ...
Read MoreC program to simulate Nondeterministic Finite Automata (NFA)
In this problem, we will create a C program to simulate Non-deterministic Finite Automata (NFA). NFA is a finite state machine that can move to any combination of states for an input symbol, meaning there is no exact state to which the machine will move. Syntax struct node { int data; struct node* next; char edgetype; }; int nfa(node** graph, int current, char* input, int* accept, int start); Formal Definition of NFA NFA can be represented by 5-tuple (Q, Σ, δ, ...
Read More