Question 5

Code for Pangram Checking

Pangram Checking

Given a string check if it is Pangram or not. A pangram is a sentence containing every letter in the English Alphabet.

Examples : The quick brown fox jumps over the lazy dog ” is a Pangram [Contains all the characters from ‘a’ to ‘z’]
“The quick brown fox jumps over the dog” is not a Pangram [Doesn’t contains all the characters from ‘a’ to ‘z’, as ‘l’, ‘z’, ‘y’ are missing]

We create a mark[] array of Boolean type. We iterate through all the characters of our string and whenever we see a character we mark it. Lowercase and Uppercase are considered the same. So ‘A’ and ‘a’ are marked in index 0 and similarly ‘Z’ and ‘z’ are marked in index 25.

After iterating through all the characters we check whether all the characters are marked or not. If not then return false as this is not a pangram else return true.

Code for checking whether a string is Pangram or not

53 comments on “Question 5”


  • ayushkumarshaw980

    Python
    alphabet = “abcdefgfijklmnopqrstuvwxyz”
    string = “The quick brown fox jumps over the lazy dog”
    flag = True
    for i in alphabet:
    if i in string:
    continue
    else:
    flag = False
    break

    if flag:
    print(“Pangram”)
    else:
    print(“Not Pangram”)


  • thirunagirisimhadri

    x = input() a = x.upper() b = [] for i in range(0, 9 1): b.append(0) for i in a: if i == ” “: continue b[ord(i)] = 1 b = b[65:91] if 0 in b: print(x, “is not a program”) else: print(x, “is a program”)


  • pdhote592

    #include
    #include
    using namespace std;

    bool panagram(string & str){
    vector alphabets(26);
    for(int i=0;i<str.length();i++){
    char ch=str[i];
    if(alphabets[ch-'a']!=1){
    alphabets[ch-'a']=1;
    }
    }
    for(int i=0;i<alphabets.size();i++){
    if(alphabets[i]!=1){
    return false;
    }
    }
    return true;

    }
    int main(){
    string str="The quick brown fox jumps over the dog";
    if(panagram(str)==true){
    cout<<"The string is a panagram"<<endl;
    }
    else{
    cout<<"The string is not a panagram"<<endl;
    }
    }