Tuesday, August 3, 2021

Pascal Program to Count the vowels

Pascal Program to Count the vowels in a given String

 
{Pascal Program to Count the vowels  in a given String}
program CountVowels;
{ Define Variables }
var s:String;
       i,c:integer;
       x:char;
begin
   {enter the name}
   Write('Enter a String?');
   readln(s);
   s:=UpCase(s);
   c:=0;
   {count the vowels in the string}
   for i:=1 to length(s)   do
   begin
        x:=s[i];
        if ( (x='A') or (x='E') or (x='I') or (x='O') or (x='U')) then
        begin
           c:=c+1;
        end;
   end;
   {Display Number of vowels}
   writeln('------------------------------------');
   writeln('Number of vowels in the String ',s,' is=: ',c);
   writeln('------------------------------------');   
   readln;
end.

Pascal Program to Count the vowels in a given String using a user defined function

 
{Pascal Program for Count the vowels  in a given String}
program CountVowels;
{ Define Variables }
var s:String;
       i,c:integer;
       x:char;
{function to check whether given charcter is a vowel}
function checkVowel(v:char):boolean  ;
begin
     if ( (v='A') or (v='E') or (v='I') or (v='O') or (v='U')) then
        checkVowel :=true
     else
         checkVowel:=false;
end;
{Main Progrm}
begin
   {Enter a input String }
   Write('Enter a String?');
   readln(s);
   s:=UpCase(s);
   c:=0;
   {count the vowels in the string using above function}
   for i:=1 to length(s)   do
   begin
        x:=s[i];
        {call the defined function}
        if ( checkVowel(x)) then
        begin
           c:=c+1;
        end;
   end;
   {Display the Number of vowels}   
   writeln('------------------------------------');
   writeln('Number of vowels in the String ',s,' is=: ',c);
   writeln('------------------------------------');   
   readln;
end.

Pascal Program to Count the vowels in a given String using Pascal Procedure with in/out parameter

 
{Pascal Program for Count the vowels  in a given String Using Procedure}
program CountVowels;
{ Define Variables }
var s:String;
       i,c:integer;
       x:char;
       ccv:boolean;
{Procedure to check whether given charcter is a vowel}
procedure checkVowel(v:char; var cv:boolean) ;
begin
     if ( (v='A') or (v='E') or (v='I') or (v='O') or (v='U')) then
        cv:=true
     else
         cv:=false;
end;
{Main Progrm}
begin
   {Enter a input String }
   Write('Enter a String?');
   readln(s);
   s:=UpCase(s);
   c:=0;
   {count the vowels in the string using above function}
   for i:=1 to length(s)   do
   begin
        x:=s[i];
        {call the procedure}
        ccv:=false;
        checkVowel(x,ccv);
        if (ccv=true) then
        begin
           c:=c+1;
        end;
   end;
   {Display the Number of vowels}
   writeln('------------------------------------');
   writeln('Number of vowels in the String ',s,' is=: ',c);
   writeln('------------------------------------');
   readln;
end. 


Click below link to Get Practical Explanation:




No comments:

Post a Comment