- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 1401 Articles for C
172 Views
Array is a sequence of elements of same data type. in this problem we are going to consider integer array for solving the problem. in this problem we are going to find sum of Elements found by dividing the element from the element proceeding it.Let’s take a few examples to understand this Problem better −Example 1 −Array : 3 , 5 ,98, 345 Sum : 26Explanation − 3 + 5/3 + 98/5 + 345/98 = 3 + 1 + 19 + 3 = 26We have divided each element with its preceding element and considered only integer parts of the divisions ... Read More
731 Views
_Generic keyword in C is used to define MACRO for different data types. This new keyword was added to the C programming language in C11 standard release. the _Generic keyword is used to help the programmer use the MACRO in a more efficient way.this keyword translate the MACRO based on the type of the variable. let's take an example ,#define dec(x) _Generic((x), long double : decl, \ default : Inc , \ float: incf )(x)The above syntax is how to declare any MACRO as generic for different methods.Let's take an example code, this code will define a MACRO that will ... Read More
101 Views
Osiris Number is a number whose value is equal to the sum of values of all number formed by adding all the permutations of its own digits.In this problem, we are given a 3-Digit number N, and we will check weather the number N is an Osiris number.Let’s take an example, Input : N = 132 Output : 132ExplanationAll sub-samples of N : 13 , 12, 21, 23 ,32 31.Sum = 13+12+21+23+32+31 = 132To do this, we have a formula to check whether the given number is Osiris number or not.Example Live Demo#include int main() { int n = ... Read More
58 Views
Area of a square is equal to the product of sides of the square.We are considering a figure in which the midpoints of sides of each square make another square. And so on until a specific number of squares.This figure shows a square made by joining the midpoints of a square.For this figure the let the side be a, The length of side of inner square will beL2 = (a/2)2 + (a/2)2 L2 = a2(1/4 + 1/4) = a2(1/2) = a2/2 L = a2/ (\sqrt{2}).Area of square2 = L2 = a2/2.For the next square, the area of square 3 = ... Read More
166 Views
A rhombus inscribed in a rectangle touches the sides of the rectangle so by this we can infer that the diagonals of the largest inscribed rhombus are equal to the length and breadth of the rectangle.If we have the length(l) and breadth(b) of the rectangle, the length of the diagonal of the largest rhombus inscribed inside it is d1 = l and d2 = b.The area of a rhombus is given by the formula, Area = (d1*d2)/2Putting the values of d1 and d2. We get, Area = (l*b)/2Using this formula we can create a program that calculates the area of ... Read More
1K+ Views
A circle inscribed in a rectangle touches the larger side of the rectangle with its ends i.e. the length is tangent to the circle.A rectangle inscribed in a semicircle touches its arc at two points. The breadth of the rectangle is equal to the diameter of the circle.If R is the radius of semi-circle.Length of the rectangle = √2R/2Breadth of the rectangle = R/√2Radius of biggest circle inscribed isr = b/2 = R/2√2Using this formula we can find the area of this circle inscribed in a rectangle which is inscribed in a semicircle, Area = (π*r2) = π*R/8Example Live Demo#include ... Read More
240 Views
An array is a container of elements of the same data types. In product array Puzzle, the product of all elements is found.In this Product Array Puzzle, we need to find the product of all elements of the array except element. The condition is that you cannot use the division operator and store this to another array.For solving this we will be creating two products, one for all left elements and one for all right elements. And then adding this left and right products to get the desired products.Example Live Demo#include #include void productfind(int arr[], int n) { int *left ... Read More
2K+ Views
Structure allows us to create user defined datatype. Structure member can be primitive datatype or it can be an array of statically allocated memory. When we assign one structure variable to another then shallow copy is performed. However, there is an exception, if structure member is an array then compiler automatically performs deep copy. Let us see this with example −Example Live Demo#include #include typedef struct student { int roll_num; char name[128]; } student_t; void print_struct(student_t *s) { printf("Roll num: %d, name: %s", s->roll_num, s->name); } int main() { student_t s1, s2; s1.roll_num = ... Read More
273 Views
Given an input string with vowels and consonants. Rearrange the string such a way that vowels and consonants occupies alternate position in final string. As we are arranging vowels and consonants at alternate position the input string must satisfy either of the following conditions −Number of vowels and consonants must be same e.g. string "individual" has 5 vowels and 5 consonants.If number of vowels are more, then difference between number of vowels and number of consonants must be 1 e.g. string "noe" has 2 vowels and 1 consonant.If number of consonants are more, then difference between number of consonants and ... Read More
4K+ Views
Syntax of ternary operator is −(expression-1) ? expression-2 : expression-3This operator returns one of two values depending on the result of an expression. If "expression-1" is evaluated to Boolean true, then expression-2 is evaluated and its value is returned as a final result otherwise expression-3 is evaluated and its value is returned as a final result.ExampleLet us write a program to find maximum of two numbers using ternary operator. Live Demo#include using namespace std; int main() { int a = 10; int b = 20; int max = a > b ? a : b; cout