Missing Characters to Make a String Pangram in C++

Share on facebook
Share on twitter
Share on linkedin
Share on twitter
Share on tumblr

In this C program, we will find the missing characters to make a string panagram. Panagram is any sentence that contains all the alphabets from A-Z.

It’s a difficult task to form a sentence that contains all the alphabets. However, let’s have a look at some of the sentences which can be said to as a panagram.

“The quick brown fox jumps over the lazy dog”.

The above sentence contains all the alphabets from ‘a’ to ‘z’.

Now let’s have a look at the C program which will help you find which character you need to add to make a given sentence a panagram

Missing Characters to Make a String Pangram in C

#include<bits/stdc++.h> 
using namespace std; 
const int CHAR_SIZE = 26; 
string missingChars(string s) 
{ 
	bool present[CHAR_SIZE] = {false}; 
	for (int m=0;m<s.length();m++) 
	{ 
		if (s[m] >= 'a' && s[m] <= 'z') 
			present[s[m]-'a'] = true; 
		else if (s[m] >= 'A' && s[m] <= 'Z') 
			present[s[m]-'A'] = true; 
	} 

	string res = ""; 
	for (int n=0; n<CHAR_SIZE; n++) 
		if (present[n] == false) 
			res.push_back((char)(n+'a')); 
	return res; 
} 

int main() 
{ 
	string s= "The quick brown fox j" "over the lazy dog"; 
	cout << missingChars(s); 
	return 0; 
}

Output:

mps