From 2056452f8775e40119cfcdf4309af54982b3e3b6 Mon Sep 17 00:00:00 2001 From: Sayal860 <78461443+Sayal860@users.noreply.github.com> Date: Thu, 14 Oct 2021 07:56:47 +0530 Subject: [PATCH] Create frequency of each character in a string --- frequency of each character in a string | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 frequency of each character in a string diff --git a/frequency of each character in a string b/frequency of each character in a string new file mode 100644 index 0000000..6c2a37d --- /dev/null +++ b/frequency of each character in a string @@ -0,0 +1,33 @@ +#include +#include +#define MAX 100 // Maximum string size +int main(){ + char string[MAX]; + int i, length; + int frequency[20]; + + printf("enter the string:\n "); + gets(string); + length = strlen(string); + + for(i=0; i<20; i++){ + frequency[i] = 0; + } + + for(i=0; i='a' && string[i]<='z'){ + frequency[string[i] - 97]++; + } + else if(string[i]>='A' && string[i]<='Z'){ + frequency[string[i] - 65]++; + } + } + printf("\nFrequency of all characters in string: \n"); + for(i=0; i<20; i++){ + if(frequency[i] != 0){ + printf("'%c' = %d\n", (i + 97), frequency[i]); + } + } + return 0; +}