Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • C
  • C Basics
  • C Data Types
  • C Operators
  • C Input and Output
  • C Control Flow
  • C Functions
  • C Arrays
  • C Strings
  • C Pointers
  • C Preprocessors
  • C File Handling
  • C Programs
  • C Cheatsheet
  • C Interview Questions
  • C MCQ
  • C++
Open In App
Next Article:
C Program to Check for Palindrome String
Next article icon

C Program to Check if String is Pangram

Last Updated : 26 Oct, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Given a string Str. The task is to check if it is Pangram or not. 

A pangram is a sentence containing every letter in the English Alphabet.

Examples: 

Input: “The quick brown fox jumps over the lazy dog” 
Output: is a Pangram 
Explanation: Contains all the characters from ‘a’ to ‘z’] 

Input: “The quick brown fox jumps over the dog”
Output: is not a Pangram 
Explanation: Doesn’t contain all the characters from ‘a’ to ‘z’, as ‘l’, ‘z’, ‘y’ are missing

Recommended Practice
K-Pangrams
Try It!

Approach: Below is the idea to solve the problem

Create a mark[] array of Boolean types and iterate through all the characters of the string and mark it as visited. 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 check whether all the characters are marked or not. If not then return false as this is not a pangram else return true. 

Follow the below steps to Implement the idea:

  • Create a bool vector mark[] of size 26.
  • Iterate through all characters of the string str and mark str[i] – ‘a’ or str[i] – ‘A’ as 1 for lower and upper characters respectively.
  • Iterate through all the indices of mark[] 
    • If all indices are marked visited then return is a Pangram 
    • Else return  is not a Pangram.

Below is the Implementation of above approach

C




// A C Program to check if the given
// string is a pangram or not
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
  
// Returns true if the string is pangram else false
bool checkPangram(char str[])
{
    // Create a hash table to mark the characters
    // present in the string
    bool mark[26];
    for (int i = 0; i < 26; i++)
        mark[i] = false;
  
    // For indexing in mark[]
    int index;
  
    // Traverse all characters
    size_t size = strlen(str);
    for (int i = 0; i < size; 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';
  
        // If this character is other than english
        // lowercase and uppercase characters.
        else
            continue;
  
        mark[index] = true;
    }
  
    // Return false if any character is unmarked
    for (int i = 0; i <= 25; i++)
        if (mark[i] == false)
            return (false);
  
    // If all characters were present
    return (true);
}
  
// Driver Program to test above functions
int main()
{
    char str[]
        = "The quick brown fox jumps over the lazy dog";
    if (checkPangram(str) == true)
        printf(" %s 
is a pangram", str);
    else
        printf(" %s 
is not a pangram", str);
    return (0);
}
  
// This code is contributed by Aditya kumar (adityakumar129)
 
 
Output
 The quick brown fox jumps over the lazy dog   is a pangram

Time Complexity: O(n), where n is the length of our string 
Auxiliary Space: O(1), as 26 size Boolean vector is constant. 



Next Article
C Program to Check for Palindrome String
author
kartik
Improve
Article Tags :
  • C Language
  • C Programs
  • C Strings Programs

Similar Reads

  • C Program to Check for Palindrome String
    A string is said to be palindrome if the reverse of the string is the same as the string. In this article, we will learn how to check whether the given string is palindrome or not using C program. The simplest method to check for palindrome string is to reverse the given string and store it in a tem
    4 min read
  • C Program To Check If A Linked List Of Strings Forms A Palindrome
    Given a linked list handling string data, check to see whether data is palindrome or not? Examples: Input: a -> bc -> d -> dcb -> a -> NULL Output: True String "abcddcba" is palindrome. Input: a -> bc -> d -> ba -> NULL Output: False String "abcdba" is not palindrome. Reco
    2 min read
  • TCP Client-Server Program to Check if a Given String is Palindrome
    Prerequisites: Socket Programming in C/C++, TCP and UDP server using select, UDP Server-Client implementation in C TCP Client-Server Implementation in C This article describes a Client and Server setup where a Client connects, sends a string to the server and the server shows the original string and
    4 min read
  • Check if a string is palindrome in C using pointers
    Given a string. The task is to check if the string is a palindrome or not using pointers. You are not allowed to use any built-in string functions. A string is said to be a palindrome if the reverse of the string is same as the original string. For example, "madam" is palindrome because when the str
    2 min read
  • C Program to Find the Length of a String
    The length of a string is the number of characters in it without including the null character (‘\0’). In this article, we will learn how to find the length of a string in C. The easiest way to find the string length is by using strlen() function from the C strings library. Let's take a look at an ex
    2 min read
  • C Program to Check Vowel or Consonant
    In English, there are 5 vowel letters and 21 consonant letters. In lowercase alphabets, 'a', 'e', 'i', 'o', and 'u' are vowels and all other characters ('b', 'c', 'd, 'f'....) are consonants. Similarly in uppercase alphabets, 'A', 'E', 'I', 'O', and 'U' are vowels, and the rest of the characters are
    3 min read
  • String C/C++ Programs
    C program to swap two StringsC Program to Sort an array of names or stringsC Program to Check if a Given String is PalindromeC/C++ Program for Return maximum occurring character in the input stringC/C++ Program for Remove all duplicates from the input string.C/C++ Program for Print all the duplicate
    3 min read
  • C Program to check if two given strings are isomorphic to each other
    Given two strings str1 and str2, the task is to check if the two given strings are isomorphic to each other or not. Two strings are said to be isomorphic if there is a one to one mapping possible for every character of str1 to every character of str2 and all occurrences of every character in str1 ma
    2 min read
  • C Program to Compare Two Strings Lexicographically
    In C, lexicographic comparison refers to comparing each character of one string to the character of other string at same position based on their alphabetical order, just like how words are arranged in a dictionary. In this article, we will learn how to compare two strings lexicographically using the
    3 min read
  • C Program to Compare Two Strings Using Pointers
    In C, two strings are generally compared character by character in lexicographical order (alphabetical order). In this article, we will learn how to compare two strings using pointers. To compare two strings using pointers, increment the pointers to traverse through each character of the strings whi
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences