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 30 of 2546
How to calculate transpose of a matrix using C program?
The transpose of a matrix is obtained by converting rows to columns and columns to rows. If A is an original matrix and B is its transpose, then element at position A[i][j] becomes B[j][i]. Syntax for (i = 0; i < rows; i++) for (j = 0; j < cols; j++) transpose[j][i] = matrix[i][j]; Example 1: Dynamic Input Matrix This example reads matrix dimensions and elements from user input − #include int main() { ...
Read MoreWrite a program to add two complex numbers using C
In C programming, complex numbers are mathematical entities that consist of real and imaginary parts. A complex number is represented in the form a + bi, where 'a' is the real part and 'b' is the imaginary part multiplied by 'i' (the square root of -1). Syntax struct complexNumber { int real; int imaginary; }; Algorithm To add two complex numbers, we add their real parts separately and imaginary parts separately − Real part: result_real = num1_real + num2_real Imaginary part: result_imaginary = num1_imaginary ...
Read MoreHow to print integers in the form of Pascal triangle using C?
Pascal's triangle is a triangular arrangement of integers where each number is the sum of the two numbers directly above it. This mathematical structure has many applications in combinatorics, algebra, and probability theory. Syntax // Using factorial approach int factorial(int n); int binomialCoefficient = factorial(row) / (factorial(col) * factorial(row - col)); // Using iterative approach int coefficient = 1; coefficient = coefficient * (row - col) / (col + 1); How Pascal Triangle Works Pascal's triangle follows these rules − The first and last elements of each row are ...
Read MoreHow to print Floyd's triangle (of integers) using C program?
Floyd's triangle is a right-angle triangle of consecutive numbers, starting with 1 in the top left corner. Each row contains one more number than the previous row, forming a triangular pattern − 1 2 3 4 5 6 7 8 9 10 Syntax for (i = 1; i = 1; i--) { for (j = 1; j
Read MoreCheck the number is Armstrong or not using C
An Armstrong number (also known as a narcissistic number) is a number that equals the sum of its own digits each raised to the power of the number of digits. For example, 153 is an Armstrong number because 1³ + 5³ + 3³ = 153. Syntax number = sum of (each digit ^ number_of_digits) Algorithm To check if a number is an Armstrong number − Count the number of digits in the given number Calculate the sum of each digit raised to the power of total digits Compare this sum with the ...
Read MoreUsing iterative function print the given number in reverse order in C language
In C programming, reversing a number means printing its digits in reverse order. This can be achieved using an iterative approach with a while loop that extracts digits from right to left and builds the reversed number. Syntax int reverse(int number) { int reversed = 0; while (number > 0) { reversed = reversed * 10 + number % 10; number = number / 10; } ...
Read MorePrinting the numbers in reverse order using Division and modulo operators using C
In C programming, we can reverse a number using division and modulo operators without using any predefined functions. This approach extracts individual digits from a number and reconstructs them in reverse order. Syntax int digit = number % 10; // Extract last digit int remaining = number / 10; // Remove last digit How It Works The logic to reverse a number using mathematical operators is − Modulo operator (%): Extracts the last digit of a number Division operator (/): Removes the last digit by integer division Extract digits ...
Read MoreDifferentiate the modulo and division by using C Programming language?
In C programming, the modulo and division operators are fundamental arithmetic operators that work with integers but produce different results from the same operands. Modulo (%) − Returns the remainder after integer division. Division (/) − Returns the quotient (whole number result) of integer division. Syntax result = dividend % divisor; // Modulo operation result = dividend / divisor; // Division operation Example 1: Basic Modulo and Division This example demonstrates the difference between modulo and division operators − #include int main() { ...
Read MoreWrite a C program to perform 3X3 matrix operations
In C, we can perform various operations on a 3x3 matrix such as calculating row sums, column sums, and diagonal sums. This program demonstrates how to read a 3x3 matrix and compute these basic operations. Syntax int matrix[3][3]; // 3x3 matrix declaration // Row sum: matrix[i][0] + matrix[i][1] + matrix[i][2] // Column sum: matrix[0][j] + matrix[1][j] + matrix[2][j] // Main diagonal: matrix[0][0] + matrix[1][1] + matrix[2][2] // Anti-diagonal: matrix[0][2] + matrix[1][1] + matrix[2][0] Algorithm Step 1: Declare a 3x3 matrix Step 2: Read 9 numbers from user Step 3: Store numbers in ...
Read MoreWrite a C program of library management system using switch case
A library management system in C allows you to store and manage book information efficiently. This program uses a structure to store book details and implements a menu-driven interface using switch-case statements for different operations. Syntax struct library { char bookname[50]; char author[50]; int noofpages; float price; }; Algorithm Step 1: Declare a structure to hold book data members Step 2: Declare variables for loop control and book counting Step 3: Use switch case to handle different ...
Read More