C program to find Pangrams | HackerRank

Questions

Write a program to find Pangrams. Pangram is a  sentence which contains every letter of the alphabet. Given a sentence check whether it is Pangram or not.

INPUT:

“The quick brown fox jumps over the lazy dog”

OUTPUT:

Pangram

INPUT:

“welcome to wisdom overflow”

OUTPUT:

Not Pangram

Logic

  • Get the sentence from the user. We use gets() which terminates only when enter is pressed.
  • Initialize the count array with zero for all the characters.
  • Count the frequency of each character and update the count array.
  • Finally, if any element in the array is zero then it is Not Pangram or else it is Pangram.

Program

#include<stdio.h>
int main()
{
    char str[50];
    int i;
    /*count array is used to find the count of each character in the sentence*/
    int count[26]={0};              //intiallizing all elements of array with 0
    printf("enter the sentence");
    gets(str);

    /*Ascci Values
      A-65
      a-97
      white space - 32
    */

    for(i=0;str[i]!='\0';i++)
    {
        if(str[i]==32)
            continue;                   //skip if white space

        /*Count
        index 0 - a,A
        index1 - b,B
        ...
        */
        if(str[i]>96)                   //If small letter
            count[str[i]-97] +=1;       //increment the count
       else                             //If capital letter
            count[str[i]-65] +=1;
    }
    for(i=0;i<26;i++)
    {
        /*If any element in count array is zero, then it is not Panagram*/
        if(count[i]==0)
          {
             printf("Not Panagram");
             exit(-1);
          }
    }
        printf("Panagram");
}

To find the anagram in a string array

Sree Hari Sanjeev

The founder and CEO of Wisdom Overflow. His enthusiasm and effort has taken the blog to next level. You will be motivated just by taking a look at his daily schedule.