Sunidhi Bansal

Sunidhi Bansal

809 Articles Published

Articles by Sunidhi Bansal

Page 7 of 81

C Program for Reversed String Pattern

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 838 Views

In C programming, a reversed string pattern is a way to display a string in a triangular format where each row contains characters in reverse order, and when the string runs out, asterisks (*) fill the remaining positions. This creates an interesting visual pattern that grows row by row. Syntax void printReversedPattern(char str[], int length); Algorithm The approach to create this pattern involves the following steps − Start from the first row and print increasing number of characters For each row, calculate the starting position using formula: k = ((i*(i+1))/2)-1 Print characters ...

Read More

C Program to check if an Array is Palindrome or not

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 15K+ Views

Given an array arr[] of any size n, our task is to find out whether the array is palindrome or not. A palindrome is a sequence which reads the same backwards and forwards, like: MADAM, NAMAN, etc. To check if an array is palindrome, we compare elements from both ends moving towards the center − 1 2 3 2 1 ...

Read More

C Program to check Plus Perfect Number

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 380 Views

A Plus Perfect Number (also known as Armstrong Number or Narcissistic Number) is a number where the sum of its digits raised to the power of the number of digits equals the original number itself. Syntax int isPlusPerfect(int number); For example − 371: 3³ + 7³ + 1³ = 27 + 343 + 1 = 371 ✓ 163: 1³ + 6³ + 3³ = 1 + 216 + 27 = 244 ≠ 163 ✗ Plus Perfect Number Check: 371 ...

Read More

C Program to convert first character uppercase in a sentence

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 4K+ Views

Given a string with mixed case letters, the task is to convert the first character of each word to uppercase and the rest to lowercase. This creates a proper title case format where each word begins with a capital letter. For example, given the string "hElLo world", we need to convert the first character 'h' to uppercase 'H' and make all other characters lowercase except for the first character after spaces, which should also be uppercase. Syntax void convertToTitleCase(char str[], int n); Example Input and Output Input: str[] = {"heLlO wORLD"} Output: ...

Read More

C Program to check if a date is valid or not

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 4K+ Views

In C programming, validating a date requires checking multiple constraints including day, month, year ranges, leap years, and month-specific day limits. A valid date should range from 1/1/1800 to 31/12/9999. Syntax int datevalid(int day, int month, int year); int isleap(int year); Date Validation Constraints Date must be between 1 and 31 Month must be between 1 and 12 Year must be between 1800 and 9999 April, June, September, November have maximum 30 days February has 29 days in leap years, 28 days otherwise Example: Complete Date Validation This program implements ...

Read More

C Program to check Strong Number

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 7K+ Views

A Strong Number is a number whose sum of the factorials of its digits equals the original number. For example, 145 is a strong number because 1! + 4! + 5! = 1 + 24 + 120 = 145. Syntax int factorial(int digit); int isStrongNumber(int number); Algorithm Extract each digit from the number starting from the unit place Calculate the factorial of each digit Sum all the factorials Compare the sum with the original number Example Let's implement a C program to check if a number is a Strong Number ...

Read More

C Program to check if matrix is singular or not

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 1K+ Views

Given a matrix as mat[row][column], our task is to check whether the given matrix is singular or not through a function and display the result. A singular matrix is a matrix whose determinant is zero. If the determinant is not zero then the matrix is non-singular. So to find whether the matrix is singular or non-singular we need to calculate determinant first. For a 3x3 matrix, the determinant can be calculated as − $$M1[3][3]\:=\:\begin{bmatrix}a & b & c \d & e & f \g & h & i \end{bmatrix}$$ |m1| = a(e*i - f*h) - b(d*i ...

Read More

Program to compute Log n in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 594 Views

In C programming, computing the logarithm base 2 of a number n can be achieved using recursive or iterative approaches. The logarithm function determines the power to which a base must be raised to obtain a given number. The mathematical relationship is: if logb x = y, then by = x For example: log2 64 = 6, because 26 = 64 Syntax unsigned int log2n(unsigned int num); Method 1: Using Recursive Approach This method uses recursion to divide the number by 2 until it becomes 1 or less − #include ...

Read More

Products of ranges in an array in C

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 655 Views

The product of ranges in an array problem involves calculating the product of elements between given left (L) and right (R) indices under modulo P. This is useful in competitive programming to handle large products efficiently. Syntax int calculateProduct(int A[], int L, int R, int P); Parameters A[] − The input array of integers L − Left index (1-based) R − Right index (1-based) P − Prime modulo value Algorithm Step 1: Convert 1-based indices to 0-based (L-1, R-1) Step 2: Initialize result as 1 Step 3: ...

Read More

C Program for diamond pattern with different layers

Sunidhi Bansal
Sunidhi Bansal
Updated on 15-Mar-2026 351 Views

A diamond pattern in C is a symmetric arrangement of numbers that forms a diamond shape. The pattern starts with a single digit at the top, expands to show increasing sequences in the middle, and then contracts back to a single digit at the bottom. Syntax void print_pattern(int n); Approach The algorithm for creating a diamond pattern with n layers follows these steps − The pattern has (2 * n + 1) total rows First and last rows contain only "0" with proper spacing For rows 1 to n-1: numbers increase from ...

Read More
Showing 61–70 of 809 articles
« Prev 1 5 6 7 8 9 81 Next »
Advertisements