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 933 of 2547
How to find the product of given digits by using for loop in C language?
In C programming, finding the product of digits involves extracting each digit from a number and multiplying them together. This is commonly done using loops to repeatedly divide the number by 10 and extract the remainder. Syntax for(product = 1; num > 0; num = num / 10) { rem = num % 10; product = product * rem; } Method 1: Using For Loop The for loop approach initializes the product to 1 and continues until all digits are processed − #include ...
Read MoreHow to swap two arrays without using temporary variable in C language?
In C programming, swapping two arrays without using a temporary variable can be achieved using arithmetic or bitwise operations. This technique exchanges the contents of two arrays by manipulating the values directly, avoiding the need for additional memory space. Syntax for(i = 0; i < size; i++) { array1[i] = array1[i] + array2[i]; array2[i] = array1[i] - array2[i]; array1[i] = array1[i] - array2[i]; } Method 1: Using Arithmetic Operations This method uses addition and subtraction to swap array elements − ...
Read MoreC program to find palindrome number by using while loop
A palindrome number is a number which remains the same when its digits are reversed. For example, 121, 1331, and 7557 are palindrome numbers. In C programming, we can check if a given number is a palindrome by using a while loop to reverse the number and then comparing it with the original. Syntax while (condition) { // Extract last digit remainder = number % 10; // Build reversed number reversed = reversed * 10 + remainder; ...
Read MoreC program to convert centimeter to meter and kilometer
In C programming, converting between different units of length is a common task. This program demonstrates how to convert centimeters to meters and kilometers using simple mathematical formulas. Conversion Formulas 1 Meter = 100 Centimeters 1 Kilometer = 100000 Centimeters Syntax meter = centimeter / 100.0; kilometer = centimeter / 100000.0; Algorithm The algorithm to convert centimeter into meter and kilometer is as follows − Step 1: Declare variables for centimeter, meter, and kilometer. Step 2: Read length in centimeters from user input. Step 3: Convert to meters ...
Read MoreC program to find the sum of arithmetic progression series
An arithmetic progression (A.P.) is a sequence of numbers where each term after the first is obtained by adding a constant value called the common difference. This C program calculates the sum of an A.P. series using the mathematical formula. Syntax Sum of A.P. Series: S_n = n/2 * (2a + (n - 1) * d) nth term of A.P. Series: T_n = a + (n - 1) * d Where: a = first term n = number of terms d = common difference S_n = sum of n terms Example: Calculate ...
Read MoreC program to generate an electricity bill
In C, generating an electricity bill involves calculating charges based on different rate slabs depending on units consumed. Higher consumption leads to higher per-unit rates, implementing a progressive billing system commonly used by utility companies. Syntax if (units < slab1_limit) { amount = units * rate1; fixed_charge = charge1; } else if (units
Read MoreHow to add two complex numbers by passing structure to a function in C language?
In C programming, complex numbers can be represented using structures with real and imaginary parts as members. To add two complex numbers, we pass the structure variables to a user-defined function that performs the addition and returns the result. Syntax typedef struct complex { float real; float imag; } complex; complex addition(complex num1, complex num2); Algorithm The following steps outline the process for adding two complex numbers using structures − Step 1: Define a structure with real and imaginary parts Step 2: Declare ...
Read MoreWhat do you mean by static memory allocation in C programming?
Static memory allocation in C refers to memory allocation that happens at compile time. The memory size and location are determined before the program runs, and once allocated, the memory cannot be resized during program execution. Static Memory Compile Time Fixed Size Dynamic Memory Runtime Variable Size Memory Allocation Types Examples: Arrays, Local variables, Global variables Examples: malloc(), calloc(), realloc() Syntax ...
Read MoreWrite a C program to demonstrate post increment and pre increment operators
In C programming, the increment (++) and decrement (--) operators are used to increase or decrease a variable's value by 1. These operators can be applied in two forms: pre-increment/decrement and post-increment/decrement, which behave differently in expressions. Syntax /* Pre-increment/decrement */ ++variable; --variable; /* Post-increment/decrement */ variable++; variable--; Pre-Increment Operator (++variable) In pre-increment, the operator is placed before the operand. The value is first incremented and then the operation is performed on it. For example − z = ++a; // First: a = a + 1, Then: ...
Read MoreWrite C program using isupper() function
In C, the isupper() function is used to check if a character is an uppercase letter (A-Z). It is defined in the ctype.h header file and returns a non-zero value if the character is uppercase, otherwise returns 0. Syntax int isupper(int ch); Parameters: ch − The character to be checked (passed as int). Return Value: Non-zero if the character is uppercase, 0 otherwise. Example 1: Counting Uppercase Letters Using isupper() This program counts the total number of uppercase letters in a string using the isupper() function − #include #include ...
Read More