Q. Write a program to check whether the given string is pangram or not.

Solution :- In this program we will check whether the given string is pangram or not.

Pangram :- If a string contains every letter of the English alphabet i.e all 26 alphabets then the string is known as Pangram.
For Example :-
String1 = The quick brown fox jumps over the lazy dog
So as we can see that the given strings contains all letters of English alphabet therefore the string is Pangram.

Pangram Algorithm

START
Step 1 : Declare an empty hashset.
Step 2 : Iterate over the string and insert each character in the hashset.
Step 3 : Once the string has been traversed, check the size of the hashset. If it is equal to 26, that means we have covered each of the character in English alphabet.
Step 4 : If the size of hashset is less than 26, it means that the string is not a pangram
STOP


Pangram Program

  • C
  • C++
  • Java
  • Python
  • C#
  • PHP
  • #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char str[100]="The quick brown fox jumps over the lazy dog";
    int i,value[26]={0},count=0;
    for(i=0;str[i]!='\0';i++)
    {
    if('a'<=str[i] && str[i]<='z')
    {
    count+=!value[str[i]-'a'];
    value[str[i]-'a']=1;
    }
    else if('A'<=str[i] && str[i]<='Z')
    {
    count+=!value[str[i]-'A'];
    value[str[i]-'A']=1;
    }
    }
    if(count==26)
    {
    printf("The String is a Pangram String.");
    }
    else
    {
    printf("The String is not a Pangram String.");
    }
    getch();
    }
    
    #include< bits/stdc++.h >  
    using namespace std; 
    bool check_pangram (string &str) 
    { 
    // Create a hash table to mark the characters 
    // present in the string 
    vector< bool > mark(26, false); 
    int index; 
    // Traverse all characters 
    for (int i=0; i< str.length(); i++) 
    { 
    // If uppercase character, subtract 'A' 
    // to find index. 
    if ('A' <= str[i] && str[i] <= 'Z') 
    index = str[i] - 'A'; 
    // If lowercase character, subtract 'a' 
    // to find index. 
    else if('a' <= str[i] && str[i] <= 'z') 
    index = str[i] - 'a'; 
    mark[index] = true; 
    } 
    for (int i=0; i<=25; i++) 
    if (mark[i] == false) 
    return (false); 
    return (true); 
    } 
    // Driver Program to test above functions 
    int main() 
    { 
    string str = "The quick brown fox jumps over the lazy dog"; 
    if (check_pangram(str) == true) 
    printf ("The String is a Pangram String."); 
    else
    printf ("The String is not a Pangram String."); 
    return(0); 
    } 
    
    public class LFC {
    public static void main(String[] args) {
    String str = "The quick brown fox jumps over the lazy dog"; 
    boolean[] value = new boolean[26]; 
    int index = 0;
    int flag = 1;
    for (int i = 0; i < str.length(); i++) {
    if ( str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
    index = str.charAt(i) - 'A'; 
    }else if( str.charAt(i) >= 'a' &&  str.charAt(i) <= 'z') {
    index = str.charAt(i) - 'a'; 
    }
    value[index] = true; 
    }
    for (int i = 0; i <= 25; i++) {
    if (value[i] == false)
    flag = 0;
    }
    if (flag == 1)
    System.out.print("The String is a Pangram String.");
    else
    System.out.print("The String is not a Pangram String.");
    }
    }
    
    import string 
    def check_pangram(str1): 
    alphabet = "abcdefghijklmnopqrstuvwxyz"
    for char in alphabet: 
    if char not in str1.lower(): 
    return False
    return True
    # Driver code 
    str1 = 'the quick brown fox jumps over the lazy dog'
    if(check_pangram(str1) == True): 
    print("The String is a Pangram String.") 
    else: 
    print("The String is not a Pangram String.") 
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    namespace forDemo
    {
    class Pangram
    {
    static void Main(string[] args)
    {
    string alpha = "abcdefghijklmnopqrstuvwxyz";
    int count=0;
    string str1 = "the quick brown fox jumps over the lazy dog";
    foreach (char c in alpha)
    {
    foreach (char l in str1.ToLower())
    {
    if (c == l)
    {
    count++;
    break;
    }
    }
    }
    if (count == 26)
    System.Console.WriteLine("The String is a Pangram String.");
    else
    System.Console.WriteLine("The String is not a Pangram String.");
    System.Console.ReadLine();
    }
    }
    }
    
    $input="the quick brown fox jumps over the lazy dog";
    if(isPangram($input)==true)
    {
    echo "The String is a Pangram String.";
    }
    else {
    echo "The String is not a Pangram String.";
    }
    function isPangram($input)
    {
    $alphabet = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z');
    $isPangram = false;
    $array = str_split($input);
    foreach ($array as $char) {
    if (ctype_alpha($char)) {
    if (ctype_upper($char)) {
    $char = strtolower($char);
    }
    $key = array_search($char, $alphabet);
    if ($key !== false) {
    unset($alphabet[$key]);
    }
    }
    }
    if (!$alphabet) {
    $isPangram = true;
    }
    return $isPangram;
    
    #include<stdio.h>
    #include<conio.h>
    void main()
    {
    char str[100]="The quick brown fox jumps over the lazy dog";
    int i,value[26]={0},count=0;
    for(i=0;str[i]!='\0';i++)
    {
    if('a'<=str[i] && str[i]<='z')
    {
    count+=!value[str[i]-'a'];
    value[str[i]-'a']=1;
    }
    else if('A'<=str[i] && str[i]<='Z')
    {
    count+=!value[str[i]-'A'];
    value[str[i]-'A']=1;
    }
    }
    if(count==26)
    {
    printf("The String is a Pangram String.");
    }
    else
    {
    printf("The String is not a Pangram String.");
    }
    getch();
    }
    

    Output

    The String is a Pangram String.
    

    Recommended Programs

       Prime Number Program
       Fibonacci Series Program