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 Remove Duplicate Characters from a String

🧹 C Program to Remove Duplicate Characters from a String

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

int main() {
    int i, j, k;
    char str[100];

    printf("Enter the string:\n");
    scanf(" %[^\n]", str);  // space before %[^\n] to handle newline

    for (i = 0; str[i] != '\0'; i++) {
        j = i + 1;
        while (str[j] != '\0') {
            if (str[j] == str[i]) {
                // Shift all characters one position to the left
                for (k = j; str[k] != '\0'; k++) {
                    str[k] = str[k + 1];
                }
                // Don't increment j here — next character is already shifted
            } else {
                j++;
            }
        }
    }

    printf("After removing Duplicate Elements in Given String: %s\n", str);
    return 0;
}
  

πŸ“ Explanation:

This program reads a string from the user and removes duplicate characters by shifting the remaining characters left whenever a duplicate is found.

πŸ’‘ Sample Output:

Enter the string:
programming
After removing Duplicate Elements in Given String: progamin
  

πŸ” Keywords:

remove duplicates from string in C, string manipulation in C, C string interview programs, delete repeated characters, remove duplicate characters in C

Comments

Popular Posts

πŸŒ™