11:03 AM
C++ Program of COUNTING DIFFERENT CHARACTERS IN A STRING

Write a Program of COUNTING DIFFERENT CHARACTERS IN A STRING

 

#include<iostream.h> 
#include<conio.h>

main()

{

int a[26],A[26],i,c=0;

char str[100];

clrscr();

puts("Enter a string->");

gets(str);

for(i=0;i<26;i++)

{

a[i]=0;

A[i]=0;

}

for(i=0;str[i]!='\0';i++)

{

c=str[i];

if(c<97)

{

c=c-65;

A[c]++;

}

else

{

c=c-97;

a[c]++;

}

}

for(i=0;i<26;i++)

{

if(a[i]!=0)

printf("\n%c occurs %d times",i+97,a[i]);

}

for(i=0;i<26;i++)

{

if(A[i]!=0)

printf("\n%c occurs %d times",i+97,A[i]);

}

getch();

}

Note:
      If you want to change in this program please write through the comment on this page. you can also past similar program 
                 of c++ with output.your comment is valuable to the other user and person.

Views: 86 | Added by: vijoriya | Tags: Characters, String, c++, program, different, Counting | Rating: 0.0/0
Total comments: 0
avatar