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
C Articles
Page 76 of 96
Average of odd numbers till a given odd number?
The average of odd numbers till a given odd number is calculated by finding the sum of all odd numbers from 1 to that number, then dividing by the count of odd numbers. This is a fundamental concept that demonstrates both iterative and mathematical approaches. Syntax Average = Sum of odd numbers / Count of odd numbers Average = (n + 1) / 2 // Formula approach (where n is odd) Example: Manual Calculation For odd numbers till 9: Odd numbers: 1, 3, 5, 7, 9 Sum: 1 + 3 ...
Read MorePower Function in C/C++
The power function in C is used to calculate the power of a given number. The pow() function finds the value of a raised to the power b i.e., ab. Syntax double pow(double base, double exponent); The pow() function accepts two double values as parameters and returns a double value as output. It is defined in the math.h header file. If you pass integers to the power function, they are automatically converted to double data type. However, there's a potential precision issue with this conversion. Sometimes floating-point representation might store values slightly differently (e.g., ...
Read MoreArea of the largest triangle that can be inscribed within a rectangle?
A rectangle is a quadrilateral that has opposite sides equal and parallel, with adjacent sides at 90°. A triangle is a closed figure with three sides. The largest triangle that can be inscribed within a rectangle has its base equal to the length of the rectangle and height equal to the breadth of the rectangle. This triangle spans the entire diagonal of the rectangle. Length (l) Breadth (b) Largest Triangle ...
Read More1's and 2's complement of a Binary Number?
Binary numbers are expressed in base 2, using only the digits '0' and '1'. Each digit in a binary number is called a bit. Understanding 1's and 2's complement is essential for representing signed numbers in computer systems. 1's Complement One's complement of a binary number is obtained by inverting all bits − changing every '0' to '1' and every '1' to '0'. Syntax 1's complement = invert all bits Example: 101100 → 010011 2's Complement Two's complement of a binary number is obtained by adding 1 to the 1's complement of ...
Read MoreSum of the first N Prime numbers
In C programming, finding the sum of the first N prime numbers involves identifying prime numbers sequentially and adding them together. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Syntax int isPrime(int num); int sumOfFirstNPrimes(int n); Algorithm The approach involves checking each number starting from 2 for primality, and when a prime is found, adding it to the sum until we have found N primes − Start with the first prime number (2) Check each subsequent number for primality Add ...
Read MoreSum of first N natural numbers which are divisible by X or Y
The sum of first N natural numbers which are divisible by X or Y involves finding all numbers from 1 to N that are multiples of either X or Y, then adding them together. This is a common problem in competitive programming and mathematical computations. Syntax // Method 1: Loop approach for(int i = 1; i
Read MoreC Program to Add two Integers
A program to add two integers takes two numbers, performs their mathematical sum, and stores the result in another variable. Syntax int sum = number1 + number2; Method 1: Adding Fixed Values This approach demonstrates adding two predefined integer values − #include int main() { int a = 545; int b = 123; int sum = a + b; printf("The first number is %d", a); ...
Read MoreC Program for Program to find the area of a circle?
The area is a quantity that represents the extent of the figure in two dimensions. The area of a circle is the area covered by the circle in a two-dimensional plane. To find the area of a circle, the radius [r] or diameter [d] (2 × radius) is required. The formula used to calculate the area is (π × r2) or {(π × d2)/4}. Syntax area = π × radius × radius area = (π × diameter × diameter) / 4 Method 1: Finding Area Using Radius This method calculates the circle area ...
Read MoreAdd 1 to a given number?
Adding 1 to a given number is a fundamental operation in C programming that increments a variable's value by one. This operation is commonly used in loops, counters, and iterative processes. Syntax variable = variable + 1; // Method 1: Addition assignment variable++; // Method 2: Post-increment ++variable; // Method 3: Pre-increment There are multiple methods to add 1 to a given number in C ...
Read MoreAverage of first n even natural numbers?
The average of first n even natural numbers is the sum of the numbers divided by the count of numbers. The first n even natural numbers are 2, 4, 6, 8, ..., 2n. Syntax Average = Sum of first n even numbers / n You can calculate this using two methods − Find the sum of n even natural numbers using a loop and divide by n Use the mathematical formula for direct calculation Method 1: Using Loop This method iterates through the first n even numbers, calculates their sum, ...
Read More