Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

πŸ”· Square Star Pattern πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Column-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } πŸ”· Reverse Square Alphabet Pattern (Row-wise) πŸ“‹ Copy Code #include <stdio.h> int main() { int num; ...

C program to check if a given string is a palindrome or not using a custom function

Palindrome Checker in C

πŸ” Palindrome Check in C (Using Custom Function)

#include<stdio.h>
#include<string.h>

void pal(char str[])
{
    int left = 0, right = strlen(str) - 1;
    while (left < right)
    {
        if (str[left] != str[right])
        {
            printf("No, Entered string is not palindrome:\n");
            return;
        }
        left++;
        right--;
    }
    printf("Yes, Entered string is palindrome:\n");
}

int main()
{
    char str[100];
    printf("Enter the string:\n");
    scanf("%[^\n]", str);
    pal(str);
}
  

πŸ“˜ Explanation:

πŸ”Ή The function `pal()` compares characters from the start and end moving toward the center.
πŸ”Ή If a mismatch is found, the string is not a palindrome.
πŸ”Ή The `scanf("%[^\n]", str)` reads a full line including spaces.
πŸ”Ή This logic is case-sensitive and does not ignore spaces or punctuation.

πŸ§ͺ Sample Output:

Enter the string:
madam
Yes, Entered string is palindrome:

Enter the string:
hello
No, Entered string is not palindrome:
    

🏷️ Keywords:

C palindrome program, check palindrome in C, string comparison, string reverse logic, C interview program, custom function for palindrome check

Comments

Popular Posts

πŸŒ™