Search
 
SCRIPT & CODE EXAMPLE
 

C

c program to find the frequency of all characters in a string

#include <stdio.h>
#include <string.h>
 
int main()
{
    char s[1000];  
    int  i,j,k,count=0,n;
 
    printf("Enter  the string : ");
    gets(s);
     
    for(j=0;s[j];j++);
	 n=j; 
    
	printf(" frequency count character in string:
");
 
    for(i=0;i<n;i++)  
    {
     	count=1;
    	if(s[i])
    	{
		
 		  for(j=i+1;j<n;j++)  
	      {   
	    	
	        if(s[i]==s[j])
    	    {
                 count++;
                 s[j]='';
	     	}
	      }  
	      printf(" '%c' = %d 
",s[i],count);
 
	       
	   
       }
	   
	   
 	} 
 	 
     
    return 0;
}
Comment

c program to find the frequency of characters in a string

#include <stdio.h>
int main() {
    char str[1000], ch;
    int count = 0;

    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);

    printf("Enter a character to find its frequency: ");
    scanf("%c", &ch);

    for (int i = 0; str[i] != ''; ++i) {
        if (ch == str[i])
            ++count;
    }

    printf("Frequency of %c = %d", ch, count);
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: addition of two numbers in c 
C :: c read n bytes code 
C :: mpi example 
C :: check if string is the same c 
C :: inputting an array in c 
C :: lateinit kotlin 
C :: ft_putchar 
C :: how to add 1 to 10 in c 
C :: how to compareTo in java 
C :: create array of strings in c from user input 
C :: quick sort c 
C :: gcd and lcd in c 
C :: bubble sort c 
C :: replace a substring with another substring in c 
C :: pid of a process in c 
C :: to execute a program using C 
C :: argparse allow line break 
C :: bcopy 
C :: command args c 
C :: while loop c 
C :: C float and double Output 
C :: Regex to match any character being repeated more than 10 times 
C :: arduino dont working dc motor 
C :: obstacle avoiding robot in c++ program 
C :: how to do Employing defensive code in the UI to ensure that the current frame is the most top level window 
C :: how to change the mapping from jkil to wasd in vim 
C :: c enums 
C :: cmake boilerplate for visual studio c++ project 
C :: __isoc99_sscanf 
C :: 50 north main 07522 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =