C Articles

Page 60 of 96

Betrothed numbers in C?

sudhir sharma
sudhir sharma
Updated on 04-Oct-2019 2K+ Views

Betrothed numbers are pair of two numbers in a way that the sum of their divisors when added by is equal to another number.For example (a,  b) are a pair of betrothed numbers if s(a) = b + 1 and s(b) = a + 1, where s(b) is the aliquot sum of b: an equivalent condition is that σ(a) = σ(b) = a + b + 1, where σ denotes the sum-of-divisors function.The first few pairs of betrothed numbers are: (48,  75), (140,  195), (1050,  1925), (1575,  1648), (2024,  2295), (5775,  6128).All known pairs of betrothed numbers have opposite parity. Any pair of the same parity must exceed 1010.AlgorithmStep 1: Find the sum of all divisors for both numbers. Step 2: Finally ...

Read More

Array elements that appear more than once in C?

sudhir sharma
sudhir sharma
Updated on 04-Oct-2019 1K+ Views

Array is a container of elements of Same data types length needs to be defined beforehand. And an element can appear in any order and any number of times in an array. so in this program we will find elements that appear more than once in an array.Problem description − We have given an array arr[] in which we have to find which of the element are repeating in the array an app to print them.Let’s take an example to understand this better.Example, Input: arr[] = {5, 11, 11, 2, 1, 4, 2} Output: 11 2ExplanationWe have an array arr ...

Read More

Array sum after dividing numbers from previous in C?

sudhir sharma
sudhir sharma
Updated on 04-Oct-2019 293 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

_Generic keyword in C ? 1: 20

sudhir sharma
sudhir sharma
Updated on 04-Oct-2019 902 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

A Product Array Puzzle in C?

sudhir sharma
sudhir sharma
Updated on 03-Oct-2019 376 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

Deep Copy of Struct Member Arrays in C

Narendra Kumar
Narendra Kumar
Updated on 26-Sep-2019 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

C/C++ Ternary Operator

Narendra Kumar
Narendra Kumar
Updated on 26-Sep-2019 5K+ 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

Read More

C Program for Armstrong Numbers

Sunidhi Bansal
Sunidhi Bansal
Updated on 23-Sep-2019 696 Views

We are given a task where we have to check a number n entered by the user, whether it’s Armstrong or not.An Armstrong number is when the sum of all the digits power by the number of digits or we can say order of digits n, is same as the digit.So below is a simple representation how to find the Armstrong number −Formula −wxyz…. = pow(w, n) +pow(x, n) + pow(y, n) + pow(z, n) + …..AlgorithmSTART Step 1-> Declare a function to find the value after power operation on the number    int power(int a, int b)     ...

Read More

C Program for Area And Perimeter Of Rectangle

Sunidhi Bansal
Sunidhi Bansal
Updated on 23-Sep-2019 3K+ Views

Given a length and breadth of a rectangle we have to find its area and Perimeter.Rectangle is 2-D figure containing four sides and four angles of 90 degree each. All the sides of rectangle are not equal only the opposite sides of a rectangle are equal. The diagonals in a rectangle also are of the same length.Below is a diagrammatic representation of rectangle.Here A represents the breadth and B represents length of the rectangle.To find the Area of a rectangle the formula is: Length x BreadthAnd Perimeter of a rectangle is − 2 x (Length+Breadth).ExamplesInput: 20 30 Output: area of rectangle ...

Read More

C Program for n-th odd number

Sunidhi Bansal
Sunidhi Bansal
Updated on 23-Sep-2019 1K+ Views

Given a number N we have to find the N-th odd number.Odd numbers are the numbers which are not completely divided by 2 and their remainder is not zero. Like 1, 3, 5, 7, 9, ….If we closely observe the list of even numbers we can also represent them as(2*1)-1=1, (2*2)-1=3, ( 2*3)-1=5, (2*4)-1=7, ….(2*N)-1.So, to solve the problem we can simply multiply the number N with 2 and subtract 1 from the result, that makes up an odd number.ExamplesInput: 4 Output: 7 The 4th odd number is 1, 3, 5, 7.. Input: 10 Output: 19AlgorithmSTART    STEP 1 -> ...

Read More
Showing 591–600 of 953 articles
« Prev 1 58 59 60 61 62 96 Next »
Advertisements