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
Articles by karthikeya Boyini
Page 47 of 143
Add 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 MoreProgram to calculate area of Circumcircle of an Equilateral Triangle
A circumcircle is a circle that passes through all vertices of a polygon. For an equilateral triangle, the circumcircle can be calculated using the relationship between the triangle's side length and the circle's radius. Syntax Area = (π × a²) / 3 where a = side length of equilateral triangle Mathematical Formula The area of the circumcircle of an equilateral triangle with side length a is given by − Area = (π × a²) / 3 This formula is derived from the fact that the circumradius R of an equilateral triangle is ...
Read MoreProgram to calculate the area of an Circle inscribed in a Square
A circle inscribed in a square is a circle which touches all four sides of the square. The diameter of the inscribed circle is equal to the side of the square. The area can be calculated using the formula (π/4) × a² where 'a' is the length of side of square. Square with Inscribed Circle r = a/2 Side = a ...
Read MoreProgram to calculate area and perimeter of Trapezium
A trapezium is a quadrilateral that has at least one pair of parallel sides. The area and perimeter of a trapezium can be calculated using specific mathematical formulas. Syntax Perimeter = side1 + side2 + side3 + side4 Area = 0.5 * (parallel_side1 + parallel_side2) * height Formula Explanation Perimeter: Sum of all four sides of the trapezium Area: Half the product of the sum of parallel sides and the perpendicular distance between them Example This program calculates the area and perimeter of a trapezium using the given measurements − ...
Read MoreProgram to find the perimeter of a rhombus using diagonals
A rhombus is a quadrilateral where all four sides have equal length. The perimeter of a rhombus can be calculated using two methods: adding all sides or using the diagonal lengths. When using diagonals, we apply the mathematical relationship between the diagonals and side length. Syntax perimeter = 2 * sqrt(pow(d1, 2) + pow(d2, 2)); Where d1 and d2 are the lengths of the two diagonals. Mathematical Formula The perimeter of a rhombus using diagonals is calculated as: Perimeter = 2 × √(d1² + d2²) ...
Read MorePrint a long int in C using putchar() only
Here we will see how to print long int value using the putchar() function in C. We can easily print the value of some variables using printf() in C, but here the restriction is, we cannot use any other function except putchar(). As we know that the putchar() is used to print only characters. We can use this function to print each digit of the number. When one numeric value is passed, we have to add character '0' with it to get the ASCII form. Syntax void print_long(long value); int putchar(int character); Example ...
Read MoreHow will implement Your Own sizeof in C
In C, the sizeof operator returns the size in bytes of a variable or data type. We can implement our own version of sizeof using pointer arithmetic. The concept is based on the fact that when we increment a pointer by 1, it moves by the size of the data type it points to. Syntax #define my_sizeof(variable) (char *)(&variable+1)-(char*)(&variable) How It Works The implementation uses pointer arithmetic − &variable gives the address of the variable &variable+1 gives the address after one complete element Casting both to (char*) makes the subtraction return bytes ...
Read MoreDifference between "int main()" and "int main(void)" in C/C++?
In C programming, you might notice two different ways to declare the main function: int main() and int main(void). While both are valid, there is a subtle but important difference in how C treats them. Syntax int main() int main(void) Key Difference In C, int main() means the function can accept any number of arguments, while int main(void) explicitly specifies that the function takes no arguments. In C++, both forms are equivalent and mean "no arguments". Example 1: Function Without void When a function is declared without void, C allows it to ...
Read MoreHeap overflow and Stack overflow in C
In C programming, memory management involves two primary areas: the heap and the stack. Both can experience overflow conditions that lead to program crashes or undefined behavior. Understanding these overflows is crucial for writing robust C programs. Heap Overflow The heap is a region of memory used for dynamic allocation. Functions like malloc(), calloc(), and realloc() allocate memory from the heap at runtime. Heap overflow occurs when the program exhausts available heap memory. This typically happens in two scenarios − Allocating Excessive Memory Attempting to allocate extremely large amounts of memory can cause heap overflow ...
Read More