C program to count the frequency of each character in a string using a for a loop. | लूप के लिए उपयोग करके स्ट्रिंग में प्रत्येक वर्ण की आवृत्ति को गिनने का सी प्रोग्राम।












C program to count the frequency of each character in a string using a for a loop.




C program to count the frequency of each character in a string using a for a loop.



#include <stdio.h> #include <string.h> #define MAX 100 int main() { char text[MAX]; int i, len; int freq[26]; printf("\n Enter any string: "); gets(text); len = strlen(text); for(i=0; i<26; i++) { freq[i] = 0; } for(i=0; i='a' && text[i]<='z') { freq[text[i] - 97]++; } else if(text[i]>='A' && text[i]<='Z') { freq[text[i] - 65]++; } } printf("\n Frequency of all characters in the given string: "); for(i=0; i<26; i++) { if(freq[i] != 0) { printf("'%c' = %d\n", (i + 97), freq[i]); } } return 0; }


Output:

Enter any string: I love string programming The minimum occurring character in the given string is 'I' = 1.



Exercise: 1
C program to count frequency of each character in a string.