C Program to Count number of Lowercase and Uppercase Letters


Introduction

C Program to Count number of Lowercase and Uppercase Letters. I have used Code:: Blocks compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

 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
#include <stdio.h>
#include <string.h>

int main()
{
    char string[100];
    int c = 0, count[26] = {0};

    printf("Enter a string:\t");
    gets(string);

    while ( string[c] != '\0' )
    {

        if ( string[c] >= 'a' && string[c] <= 'z' )
            count[string[c]-'a']++;

        else if(string[c] >= 'A' && string[c] <= 'Z' )
            count[string[c]-'A']++;

        else
            printf("ERROR!!\n");

        c++;
    }

    for ( c = 0 ; c < 26 ; c++ )
    {
        if( count[c] != 0 )
            printf("%c : %d\n",c+'a',count[c]);
    }

    return 0;
}

Result

C language

     





Related Topics




Popular Posts