Advertisement
AedenCak3

C program to print Unique Letters in a string

Dec 8th, 2021
907
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.46 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     int arr[26] = {0};
  7.     char string[100];
  8.     int i;
  9.     printf("Enter a sentence: \n");
  10.  
  11.     gets(string);
  12.     for(i=0; i<strlen(string); i++)
  13.     {
  14.  
  15.         arr[(tolower(string[i]))-97] = 1;
  16.  
  17.     }
  18.  
  19.     printf(" The Unique letters in the string are : \n");
  20.  
  21.     for(int i=0; i<26; i++)
  22.     {
  23.         if(arr[i] > 0)
  24.  
  25.             printf("%c  ", (i+97));
  26.     }
  27.    
  28.    
  29.     return 0;
  30. }
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement