A string is said to be complete if it contains all the characters from a to z.
For a user-entered string, check if it is complete or not.
Sample Input: The quick brown fox jumps over a lazy dog
Sample Output: The entered string is complete.
CODE:
#include<stdio.h>
main()
{
// Variable declaration//
int index=0,count1[26]={0},count=0,i;
char str[50];
char temp;
/*Input*/
printf("Enter string:\n");
gets(str);
for(i=0;str[i];i++) //this loop will convert uppercase alphabets to lowercase
{
if(str[i]>=65 && str[i]<=90) //here if str array greater than 64 and less than 91 so condition will work
{
temp=str[i];
str[i]=temp+32; //here i add 32 to each array example:if array equal to 65 than add 32
}
}
/* actual Working */
while (str[index] != '\0') //this loop will run until array index not equal to null
{
if (str[index] >= 'a' && str[index] <= 'z') //here I cheak that if array index >=a and <= to z
count1[str[index]-'a']++; //then count1 subtract by index value and increment in count1
index++;
}
for (index = 0; index < 26; index++)
{
if (count1[index] != 0)
count=count+1;
}
if(count==26) //if count equal to 26 then this condition will run
{
printf("The entered string is complete");
}
else
{
printf("The entered string is not complete");
}
return 0;
}
Program Output:
For more problems click here
No comments:
Post a Comment