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 19 of 96
Check 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 MoreWrite a C program for electing a candidate in Elections by calling functions using Switch case
This C program demonstrates how to create an electronic voting system using functions and switch case statements. The program allows users to cast votes for candidates and view the vote count results. Syntax switch(expression) { case constant1: // statements break; case constant2: // statements break; default: ...
Read MoreHow to align the output using justificationsin C language?
In C, justifications in printf() statements allow you to format and align output data in various ways. By using width specifiers and alignment flags, you can create well-formatted tables and organized output displays. Syntax printf("%-width format_specifier", value); // Left justification printf("%width format_specifier", value); // Right justification (default) To implement left justification, insert a minus sign (-) before the width value. Without the minus sign, the output is right-justified by default. Example 1: Left Justification with Fixed Width This example demonstrates left justification using %-15s for strings and %-15d ...
Read MoreWrite C program to calculate balance instalment
In C programming, calculating loan balance installments involves computing the remaining amount after each monthly payment, considering compound interest. This program demonstrates how to calculate the outstanding balance after making monthly payments on a loan with interest. Syntax balance = principal + (principal * (interest_rate / 100) / 12); remaining_balance = balance - monthly_payment; Formula for Interest Calculation The monthly interest calculation follows this approach − Monthly Interest: principal * ((annual_rate / 100) / 12) Balance with Interest: principal + monthly_interest Remaining Balance: balance_with_interest - monthly_payment Example: Loan Balance Calculator ...
Read MoreC program on calculating the amount with tax using assignment operator
In C programming, calculating tax on an amount is a common application of arithmetic and assignment operators. This program demonstrates how to compute the total amount by adding a specific tax percentage to the original amount. Syntax total_amount = original_amount + (original_amount * tax_rate); Problem Write a C Program to enter the amount in dollars and then display the amount by adding 18% as tax. Solution Let's consider the restaurant person adding 18% tax to every bill of the customer. The logic applied to calculate tax is − value = ...
Read More