Skip to main content

Check Pangrams in given string

Here given code implementation process.

//C Program
//Check Pangrams in given string
#include <stdio.h>

void pangrams(char str[],int size)
{
  
  //Used to store check alphabet characters
  char result[26];

  //flag which is indicate the status of pangrams
  //Initial it's true [1]
  int status=1;

  //Set initial values of resultant array
  for (int i = 0; i < 26; ++i)
  {
    result[i]='!';
  }
  for (int i = 0; i < size; ++i)
  {
    if( (str[i]>='a'&&str[i]<='z'))
    {
      //When get a small character
      result[str[i]-'a'] = str[i];
    }
    else if((str[i]>='A'&&str[i]<='Z'))
    {
      //When get a capital character
      result[str[i]-'A']=str[i];
    }
  }

  for (int i = 0; i < 26; ++i)
  {
    if(result[i]=='!')
    {
      //When [i] position character are NOT exist
      status=0;
      break;
    }
  }
  //Display results
  if(status==1)
  {
    printf("[%s] \n Is an pangrams\n",str);
  }else
  {
     printf("[%s] \n Is not an pangrams\n",str);
  }
}

int main()
{
  char str1[]="Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.";

  //Get the size of text
  int size=sizeof(str1)/sizeof(str1[0])-1;
  
  pangrams(str1,size);
  
  //Define text string 
  char str2[]="This is a simple text message";

  //Get the size of text
  size=sizeof(str2)/sizeof(str2[0])-1;
  
  pangrams(str2,size);
  
  return 0;
}

Output

[Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.]
 Is an pangrams
[This is a simple text message]
 Is not an pangrams
// Java program
// Check Pangrams in given string

public class MyString {

  public  void is_pangrams(String str)
  {
    int size = str.length();
    //Used to store check alphabet characters
    char[] result = new char[size];

    //Flag which is indicate the status of pangrams
    //Initial it's true [1]
    boolean status=true;

    //Set initial values of resultant array
    for (int i = 0; i < 26; ++i)
    {
      result[i]='!';
    }
    for (int i = 0; i < size; ++i)
    {
      if( (str.charAt(i)>='a'&&str.charAt(i)<='z'))
      {
        //When get a small character
        result[str.charAt(i)-'a'] = str.charAt(i);
      }
      else if((str.charAt(i)>='A'&&str.charAt(i)<='Z'))
      {
        //When get a capital character
        result[str.charAt(i)-'A']=str.charAt(i);
      }
    }

    for (int i = 0; i < 26; ++i)
    {
      if(result[i]=='!')
      {
        //When [i] position character are NOT exist
        status=false;
        break;
      }
    }
    //Display results
    if(status==true)
    {
      System.out.print("["+str+"] \n Is an pangrams\n");
    }
    else
    {
       System.out.print("["+str+"] \n Is not an pangrams\n");
    }
  }
  public static void main(String[] args) {

    MyString obj = new MyString();
    
    String text = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.";

    obj.is_pangrams(text);

    text = "This is a simple text message";

    obj.is_pangrams(text);
  }
}

Output

[Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.]
 Is an pangrams
[This is a simple text message]
 Is not an pangrams
// C++ program
// Check Pangrams in given string
#include<iostream>

using namespace std;
class MyString {
  public:
    void is_pangrams(string str) {
      int size = str.size();
      char result[size];
      //Flag which is indicate the status of pangrams
      //Initial it's true [1]
      bool status = true;
      //Set initial values of resultant array

      for (int i = 0; i < 26; ++i) {
        result[i] = '!';
      }
      for (int i = 0; i < size; ++i) {
        if ((str[i] >= 'a' &&
            str[i] <= 'z')) {
          //When get a small character
          result[str[i] - 'a'] = str[i];
        } else
        if ((str[i] >= 'A' &&
            str[i] <= 'Z')) {
          //When get a capital character
          result[str[i] - 'A'] = str[i];
        }
      }
      for (int i = 0; i < 26; ++i) {
        if (result[i] == '!') {
          //When [i] position character are NOT exist
          status = false;
          break;
        }
      }
      //Display results

      if (status == true) {
        cout << "[" << str << "] \n Is an pangrams\n";
      } else {
        cout << "[" << str << "] \n Is not an pangrams\n";
      }
    }
};
int main() {
  MyString obj =  MyString();
  string text = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.";
  obj.is_pangrams(text);
  text = "This is a simple text message";
  obj.is_pangrams(text);
  return 0;
}

Output

[Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.]
 Is an pangrams
[This is a simple text message]
 Is not an pangrams
// C# program
// Check Pangrams in given string
using System;
public class MyString {
  public void is_pangrams(String str) {
    int size = str.Length;
    
    //Used to store check alphabet characters
    char[] result = new char[size];
    //Flag which is indicate the status of pangrams
    //Initial it's true [1]
    Boolean status = true;
    //Set initial values of resultant array

    for (int i = 0; i < 26; ++i) {
      result[i] = '!';
    }
    for (int i = 0; i < size; ++i) {
      if ((str[i] >= 'a' &&
          str[i] <= 'z')) {
        //When get a small character
        result[str[i] - 'a'] = str[i];
      } else
      if ((str[i] >= 'A' &&
          str[i] <= 'Z')) {
        //When get a capital character
        result[str[i] - 'A'] = str[i];
      }
    }
    for (int i = 0; i < 26; ++i) {
      if (result[i] == '!') {
        //When [i] position character are NOT exist
        status = false;
        break;;
      }
    }
    //Display results

    if (status == true) {
      Console.Write("[" + str + "] \n Is an pangrams\n");
    } else {
      Console.Write("[" + str + "] \n Is not an pangrams\n");
    }
  }
  public static void Main(String[] args) {
    MyString obj = new MyString();
    String text = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.";
    obj.is_pangrams(text);
    text = "This is a simple text message";
    obj.is_pangrams(text);
  }
}

Output

[Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.]
 Is an pangrams
[This is a simple text message]
 Is not an pangrams
<?php
// Php program
// Check Pangrams in given string
class MyString {
  public  function is_pangrams($str) {
    $size = strlen($str);
    //Used to store check alphabet characters
        //Set initial values of resultant array
    $result = array_fill(0, $size, '!');
    //Flag which is indicate the status of pangrams
    //Initial it's true [1]
    $status = true;
    for ($i = 0; $i < 26; ++$i) {
      $result[$i] = '!';
    }
    for ($i = 0; $i < $size; ++$i) {
      if ((ord($str[$i]) >= ord('a') &&
          ord($str[$i]) <= ord('z'))) {
        //When get a small character
        $result[ord($str[$i]) - ord('a')] = $str[$i];
      } else
      if ((ord($str[$i]) >= ord('A') &&
          ord($str[$i]) <= ord('Z'))) {
        //When get a capital character
        $result[ord($str[$i]) - ord('A')] = $str[$i];
      }
    }
    for ($i = 0; $i < 26; ++$i) {
      if ($result[$i] == '!') {
        //When [i] position character are NOT exist
        $status = false;
        break;
      }
    }
    //Display results

    if ($status == true) {
      echo("[". $str ."] \n Is an pangrams\n");
    } else {
      echo("[". $str ."] \n Is not an pangrams\n");
    }
  }
}

function main() {
  $obj = new MyString();
  $text = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.";
  $obj->is_pangrams($text);
  $text = "This is a simple text message";
  $obj->is_pangrams($text);

}
main();

Output

[Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.]
 Is an pangrams
[This is a simple text message]
 Is not an pangrams
// Node Js program
// Check Pangrams in given string
class MyString {
  is_pangrams(str) {
    var size = str.length;
    //Used to store check alphabet characters
       //Set initial values of resultant array
    var result = Array(size).fill('!');
    //Flag which is indicate the status of pangrams
    //Initial it's true [1]
    var status = true;

    for (var i = 0; i < size; ++i) {
      if (((str[i]).charCodeAt(0) >= ('a').charCodeAt(0) &&
          (str[i]).charCodeAt(0) <= ('z').charCodeAt(0))) {
        //When get a small character
        result[(str[i]).charCodeAt(0) - ('a').charCodeAt(0)] = str[i];
      } else
      if (((str[i]).charCodeAt(0) >= ('A').charCodeAt(0) &&
          (str[i]).charCodeAt(0) <= ('Z').charCodeAt(0))) {
        //When get a capital character
        result[(str[i]).charCodeAt(0) - ('A').charCodeAt(0)] = str[i];
      }
    }

    for (var i = 0; i < 26; ++i) {
      if (result[i] == '!') {
        //When [i] position character are NOT exist
        status = false;
        break;
      }
    }

    //Display results

    if (status == true) {
      process.stdout.write("[" + str + "] \n Is an pangrams\n");
    } else {
      process.stdout.write("[" + str + "] \n Is not an pangrams\n");
    }
  }
}

function main(args) {
  var obj = new MyString();
  var text = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.";
  obj.is_pangrams(text);
  text = "This is a simple text message";
  obj.is_pangrams(text);
}

main();

Output

[Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.]
 Is an pangrams
[This is a simple text message]
 Is not an pangrams
#  Python 3 program
#  Check Pangrams in given string
class MyString :
  def is_pangrams(self, str) :
    size = len(str)
    # Set initial values of resultant array
    result = ['!'] * size
    status = True
    i = 0
    while (i < size) :
      if ((ord(str[i]) >= ord('a') and ord(str[i]) <= ord('z'))) :
        # When get a small character
        result[ord(str[i]) - ord('a')] = str[i]
      elif ((ord(str[i]) >= ord('A') and ord(str[i]) <= ord('Z'))) :
        # When get a capital character
        result[ord(str[i]) - ord('A')] = str[i]
      
      i += 1
    
    i = 0
    while (i < 26) :
      if (result[i] == '!') :
        # When [i] position character are NOT exist
        status = False
        break
      
      i += 1
    
    # Display results

    if (status == True) :
      print("[", str ,"] \n Is an pangrams\n", end = "")
    else :
      print("[", str ,"] \n Is not an pangrams\n", end = "")
    
  

def main() :
  obj = MyString()
  text = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm."
  obj.is_pangrams(text)
  text = "This is a simple text message"
  obj.is_pangrams(text)


if __name__ == "__main__":
  main()

Output

[ Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm. ]
 Is an pangrams
[ This is a simple text message ]
 Is not an pangrams
#  Ruby program
#  Check Pangrams in given string
class MyString 
  def is_pangrams(str) 
    size = str.length()
    # Set initial values of resultant array
    result = Array.new(size) { '!' }
    status = true
    i = 0
    while (i < size) 
      if (((str[i]).ord >= ('a').ord &&
          (str[i]).ord <= ('z').ord)) 
        # When get a small character
        result[(str[i]).ord - ('a').ord] = str[i]
      elsif (((str[i]).ord >= ('A').ord &&
          (str[i]).ord <= ('Z').ord)) 
        # When get a capital character
        result[(str[i]).ord - ('A').ord] = str[i]
      end
      i += 1
    end
    i = 0
    while (i < 26) 
      if (result[i] == '!') 
        # When [i] position character are NOT exist
        status = false
        break
      end
      i += 1
    end
    # Display results

    if (status == true) 
      print("[", str ,"] \n Is an pangrams\n")
    else 
      print("[", str ,"] \n Is not an pangrams\n")
    end
  end
end
def main() 
  obj = MyString.new()
  text = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm."
  obj.is_pangrams(text)
  text = "This is a simple text message"
  obj.is_pangrams(text)
end
main()

Output

[Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.] 
 Is an pangrams
[This is a simple text message] 
 Is not an pangrams
// Scala program
// Check Pangrams in given string
class MyString {
  def is_pangrams(str: String): Unit = {
    var size: Int = str.length();

    //Set initial values of resultant array
    var result: Array[Character] = Array.fill[Character](size)('!');
    var status: Boolean = true;
    var i: Int = 0;
    while (i < size) {
      if ((str(i) >= 'a' &&
          str(i) <= 'z')) {
        //When get a small character
        result(str(i) - 'a') = str(i);
      } else
      if ((str(i) >= 'A' &&
          str(i) <= 'Z')) {
        //When get a capital character
        result(str(i) - 'A') = str(i);
      }
      i += 1;
    }
    i = 0;
    while (i < 26 && status==true) {
      if (result(i) == '!') {
        //When [i] position character are NOT exist
        status = false;
      }
      i += 1;
    }
    //Display results

    if (status == true) {
      print("[" + str + "] \n Is an pangrams\n");
    } else {
      print("[" + str + "] \n Is not an pangrams\n");
    }
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    var obj: MyString = new MyString();
    var text: String = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.";
    obj.is_pangrams(text);
    text = "This is a simple text message";
    obj.is_pangrams(text);
  }
}

Output

[Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.]
 Is an pangrams
[This is a simple text message]
 Is not an pangrams
// Swift program
// Check Pangrams in given string
class MyString {
  func is_pangrams(_ str: String) {
    let size: Int = str.count;
    //Set initial values of resultant array
    var result: [Character] = Array(repeating: "!", count: size);
    var status: Bool = true;
    var i: Int = 0;
        var data = Array(str);
        var ch : String = " ";
    while (i < size) {
            ch = String(data[i]);
      if ((UnicodeScalar(ch)!.value  >=  UnicodeScalar("a")!.value) &&
             UnicodeScalar(ch)!.value  <=  UnicodeScalar("z")!.value) {
        //When get a small character
        
                result[Int(UnicodeScalar(ch)!.value - UnicodeScalar("a")!.value)] = data[i];
      } else
      if ((UnicodeScalar(ch)!.value  >=  UnicodeScalar("A")!.value) &&
             UnicodeScalar(ch)!.value  <=  UnicodeScalar("Z")!.value) {
        //When get a capital character
        result[Int(UnicodeScalar(ch)!.value - UnicodeScalar("A")!.value)] = data[i];
      }
      i += 1;
    }
    i = 0;
    while (i < 26) {
      if (result[i] == "!") {
        //When [i] position character are NOT exist
        status = false;
        break;
      }
      i += 1;
    }
    //Display results

    if (status == true) {
      print("[", str ,"] \n Is an pangrams\n", terminator: "");
    } else {
      print("[", str ,"] \n Is not an pangrams\n", terminator: "");
    }
  }
}
func main() {
  let obj: MyString = MyString();
  var text: String = "Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm.";
  obj.is_pangrams(text);
  text = "This is a simple text message";
  obj.is_pangrams(text);
}
main();

Output

[ Text version of binary is combination of zeros and ones, per line just an instruction which is work on system. Quickly write your algorithm. ]
 Is an pangrams
[ This is a simple text message ]
 Is not an pangrams




Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment