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 922 of 2547
C program to print string tokens
In C, string tokenization is the process of breaking a string into smaller parts (tokens) based on specified delimiters. The strtok() function from the string.h library is commonly used for this purpose. Syntax char *strtok(char *str, const char *delim); Parameters str − The string to be tokenized (NULL for subsequent calls) delim − A string containing the delimiter characters How It Works The strtok() function works by following these steps − First call: Pass the string and delimiter to get the first token Subsequent calls: Pass NULL as ...
Read MoreC program to dynamically make array and print elements sum
In C programming, dynamic memory allocation allows us to create arrays of variable size at runtime. This is useful when we don't know the array size at compile time. We use malloc() or calloc() functions from the stdlib.h header to allocate memory dynamically. So, if the input is like n = 6, and array elements 9, 8, 7, 2, 4, 3, then the output will be 33 because sum of 9 + 8 + 7 + 2 + 4 + 3 = 33. Syntax int *arr = (int*) malloc(size * sizeof(int)); int *arr = (int*) calloc(size, ...
Read MoreC program to find amount of volume passed through a tunnel
In C programming, we can solve problems involving conditional volume calculations using structures and functions. This program determines which boxes can pass through a tunnel based on height restrictions and calculates their volumes. Syntax struct Box { int length, width, height; }; int volume(struct Box box); int canPass(struct Box box, int tunnelHeight); Problem Description Given a tunnel with height 41 and unlimited width, we need to find the total volume of boxes that can pass through it. A box can pass if its height is strictly less than the ...
Read MoreC program to find marks of students for boys or girls
In C programming, we can solve problems involving array processing based on index patterns. This program calculates the sum of marks for either boys or girls, where boys' marks are stored at even indices (0, 2, 4, ...) and girls' marks are stored at odd indices (1, 3, 5, ...). Syntax int calculateMarks(int marks[], int n, char gender); Algorithm To solve this problem, we follow these steps − Initialize g_sum and b_sum to 0 Iterate through the array from index 0 to n-1 If index is odd, add marks to g_sum (girls) ...
Read MoreC program to find nth term of given recurrence relation
In C programming, we can find the nth term of a given recurrence relation where each term is the sum of the previous three terms. This type of recurrence relation follows the pattern S(n) = S(n-1) + S(n-2) + S(n-3) for n > 3, with given base cases. Syntax int solve(int a, int b, int c, int n); Recurrence Relation Definition The recurrence relation is defined as follows − S(1) = a (first base case) S(2) = b (second base case) S(3) = c (third base case) S(n) = S(n-1) + S(n-2) ...
Read MoreC 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 More