**************************************************************************************************************************************************
A C++ Program to make the Frequency count of letters in a given Text
**************************************************************************************************************************************************
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #include<iostream.h> #include<conio.h> #include<string.h> char temp[30]; int check(char x,int n) { for(int i=0;i<n;i++) { if(temp[i]==x) return 0; } return 1; } void main() { char str[30],ch; int i,j,l,count=0,n=0; clrscr(); cout<<"\n Enter any string and end with $ ::"; cin.get(ch); do { str[n]=ch; n++; cin.get(ch); }while(ch!='$'); str[n]=''; cout<<"\n\n------------------------------------\n"; cout<<"\n\tLetter\tFrequency\n"; cout<<"\n\n------------------------------------\n"; for(i=0;str[i]!='';i++) { l=0; count=check(str[i],i); for(j=0;j<n;j++) { if(str[i]==str[j] && count==1 && str[i]!=' ') l++; } if(count==1 && str[i]!=' ') { temp[i]=str[i]; cout<<"\t"<<str[i]<<"\t"<<l<<endl; } } cout<<"\n\n------------------------------------\n"; getch(); } /* Input and Output :- Enter any string and end with $ ::This is a sample program ------------------------------------ Letter Frequency ------------------------------------ T 1 h 1 i 2 s 3 a 3 m 2 p 2 l 1 e 1 r 2 o 1 g 1 ------------------------------------ */ |
19 total views, 18 views today