In: Computer Science
Create array of size 52 . if letter is lower case increate at first 26 position like a at 0,b at 1. Silipar to that,if letter is uppercase increament from 26,like A at26,B at 27...
Code
#include<stdio.h>
int main()
{
char c[]="samplecheck"; //sample string
int s[52];
for(int i=0;i<52;i++) //set all elements to 0
s[i]=0;
for(int i=0;i<strlen(c);i++)
{
if(islower(c[i])) //if lower increase from position 0-25
{
s[(int)c[i]-97]++;
}
if(isupper(c[i])) //if upper increase from position 26-51
{
s[(int)c[i]-39]++;
}
}
int tot=0;
for(int i=0;i<52;i++)
{
if(s[i]!=0) // if not zero the letter is presented in the word
tot+=1;
}
printf("there is %d different letters in the word %s",tot,c);
return 0;
}
Terminal Work
.