Skip to main content

Featured

Mastering Hollow Square Patterns in C: Stars, Numbers, Alphabets & Binary

πŸ”’ C Program to Print Hollow Continuous Number Square πŸ“„ Source Code: #include <stdio.h> int main() { int num, k = 0; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { if(i == 1 || i == num || j == 1 || j == num) { // k increments sequentially only along the borders printf("%d ", k++); } else { printf(" "); } } printf("\n"); } return 0; } πŸ“‹ Copy Code πŸ’» Expected Output (Input: 5): Enter the number: 5 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 πŸ”’ C Program to Print Standard Hollow Binary Row Square πŸ“„ Source Code (Fixed Specifier): #include <stdio.h> int main() { ...

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

πŸŒ™