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 5 of 96
C program to find sum of digits of a five digit number
In C programming, finding the sum of digits of a five-digit number involves extracting each digit and adding them together. We use the modulo operator (%) to extract the last digit and integer division (/) to remove it from the number. Syntax int digitSum = 0; while (number != 0) { digitSum += number % 10; number /= 10; } So, if the input is like num = 58612, then the output will be 22 because 5 + 8 + 6 + 1 + 2 = 22. ...
Read MoreC program to write all digits into words using for loop
In C programming, converting digits to their word equivalents is a common task that helps beginners understand conditional statements and loops. This program takes a range of digits and prints each digit as its corresponding word using a for loop. Syntax for(initialization; condition; increment) { // Convert digit to word using if-else statements } Example: Converting Digits to Words in a Range This example demonstrates how to convert all digits from 3 to 8 into their word representations using a for loop − #include void digitToWord(int ...
Read MoreC program to convert digit to words
In C programming, converting a digit to its corresponding word representation is a common task. This involves taking a single digit (0-9) and converting it to its English word equivalent like "Zero", "One", "Two", etc. Syntax void digitToWord(int digit); Method 1: Using If-Else Statements This approach uses a series of if-else statements to check each digit and print the corresponding word − #include void digitToWord(int d) { if (d < 0 || d > 9) { printf("Beyond range ...
Read MoreC program to find sum and difference using pointers in function
In C programming, functions can return only one value at a time. However, when we need to calculate multiple results like sum and difference of two numbers, we can use pointers as function parameters. This technique allows us to modify the original variables directly through their memory addresses. Syntax void functionName(int *ptr1, int *ptr2); // Call the function functionName(&variable1, &variable2); Algorithm To solve this problem, we will follow these steps − Define a function that takes addresses of two variables as parameters Store the sum in a temporary variable Calculate the difference ...
Read MoreC program to find maximum of four integers by defining function
In C programming, we can find the maximum of four integers by defining our own function. We create a max() function that compares two numbers and returns the larger one, then use it repeatedly to find the maximum among all four numbers. So, if the input is like a = 5, b = 8, c = 2, d = 3, then the output will be 8. Syntax int max(int x, int y); Algorithm To solve this, we will follow these steps − Define a function max() that takes two integers x ...
Read MoreC program to find sum and difference of two numbers
In C programming, finding the sum and difference of two numbers is a fundamental operation. This program demonstrates how to perform arithmetic operations on different data types and handle the output formatting correctly based on the operands' types. Syntax // For integer arithmetic int result = num1 + num2; int result = num1 - num2; // For floating-point arithmetic float result = num1 + num2; float result = num1 - num2; Example 1: Sum and Difference of Integer Numbers This example shows basic arithmetic operations on integer values − ...
Read MoreC Program to read and write character string and sentence
In C programming, reading different types of input requires different functions. Reading a single character uses scanf() with %c, strings without spaces use scanf() with %s, and sentences with spaces require fgets() for proper handling. Syntax // Character input scanf("%c", &character); // String input (no spaces) scanf("%s", string); // Sentence input (with spaces) fgets(sentence, size, stdin); Example This program demonstrates reading a character, string, and sentence from user input − #include int main() { char character; char string[500]; ...
Read MoreWhat are the special symbols in C language?
In C programming language, special symbols have specific meanings and are essential for writing syntactically correct programs. This language provides low-level access to memory and is known for its performance and efficiency. The C language includes a character set of English alphabets (a-z, A-Z), digits (0-9), and special characters with specific meanings. Some special characters are operators, while combinations like "" are escape sequences. In C, symbols are used to perform special operations − Syntax [] () {} , ; * = # : . -> + - / % < > ! & | ^ ...
Read MoreHow to convert binary to Hex by using C language?
Binary numbers are represented using only 1's and 0's. Hexadecimal numbers use 16 digits: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F} where A=10, B=11, C=12, D=13, E=14, F=15. Syntax // Convert binary string to decimal first, then to hex int binaryToDecimal(long binary); void decimalToHex(int decimal, char hex[]); Converting Binary to Hex Process To convert binary to hexadecimal, group the binary digits into 4-bit blocks (nibbles) from right to left. Each 4-bit group represents one hexadecimal digit − Binary: 1110 0101 1011 ...
Read MoreC program to insert a node at any position using double linked list
A doubly linked list is a linear data structure where each node contains data and two pointers − one pointing to the previous node and another to the next node. This allows traversal in both directions and efficient insertion/deletion operations at any position. Syntax struct node { int data; struct node *prev; struct node *next; }; void insertAtPosition(int data, int position); Doubly Linked List Structure The doubly linked list structure consists of nodes where each node has three components − ...
Read More