frequency counter without filling
please give feedback on :)
https://www.facebook.com/invigorating.arslaan
/*
You have a character array of size 100. Array contains letters ranging between A-Z and a-z. You are required to tell the frequency of each letter in the array. You can ignore punctuation marks.
Example
I am A proud Pakistani.
Sample Output:
A=4,B=0,……I = 3…P =2 ,…..,Z=0.
*/
#include "iostream"
#include "stddef.h"
#include <math.h>
using namespace std;
int main( )
{
const int n = 100;
char array[n] ="I am A Proud pakistani...,Are you?";
int length = 0;
int alphabet[26]={0};
//computing length
while(array[length]!=0)
length++;
int index=0;
for (int i = 0 ; i <length ; i++){
if(array[i]>='a' && array[i]<= 'z'){
index = static_cast <int> (array[i]) - static_cast <int> ('a');
alphabet[index]++;
}
else{
if(array[i]>='A' && array[i]<= 'Z'){
index = static_cast <int> (array[i]) - static_cast <int> ('A');
alphabet[index]++;
}
}
}
cout<<"Array after rotation"<<endl;
for(int j = 0 ; j <26 ; j++)
cout<<static_cast<char> (j+'a')<<" "<<alphabet[j]<<endl;
return 0;
}
https://www.facebook.com/invigorating.arslaan
/*
You have a character array of size 100. Array contains letters ranging between A-Z and a-z. You are required to tell the frequency of each letter in the array. You can ignore punctuation marks.
Example
I am A proud Pakistani.
Sample Output:
A=4,B=0,……I = 3…P =2 ,…..,Z=0.
*/
#include "iostream"
#include "stddef.h"
#include <math.h>
using namespace std;
int main( )
{
const int n = 100;
char array[n] ="I am A Proud pakistani...,Are you?";
int length = 0;
int alphabet[26]={0};
//computing length
while(array[length]!=0)
length++;
int index=0;
for (int i = 0 ; i <length ; i++){
if(array[i]>='a' && array[i]<= 'z'){
index = static_cast <int> (array[i]) - static_cast <int> ('a');
alphabet[index]++;
}
else{
if(array[i]>='A' && array[i]<= 'Z'){
index = static_cast <int> (array[i]) - static_cast <int> ('A');
alphabet[index]++;
}
}
}
cout<<"Array after rotation"<<endl;
for(int j = 0 ; j <26 ; j++)
cout<<static_cast<char> (j+'a')<<" "<<alphabet[j]<<endl;
return 0;
}
Comments
Post a Comment