C program to count total Upper/Lower case and total elements

-- Leave a Comment
Hello Here is a program to count the UPPERCASE lowercase and Total Characters in a String.
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
35
36
37
38
39
40
41
42
43
44
45
46
47
#include<stdio.h>
#define MAX 100
int ucase(char asent[]);
int lcase(char asent[]);
int total(char asent[]);
void main()
    {
    int u,l,t;
    char asent[MAX];
    printf("Enter a Sentence:-\n");
    gets(asent);
    u=ucase(asent);
    l=lcase(asent);
    t=total(asent);
    printf("In the Sentence ");
    puts(asent);
    printf("Total Letters are %d. Among them %d are UPPERCASE and %d are lowercase",t,u,l);
    }
int ucase(char thesent[MAX])
    {
    int i,count=0;
    for (i=0;thesent[i]!='\0';i++)
        {
        if(thesent[i]>='A' && thesent[i]<='Z')
        count++;
        }
    return (count);
    }
int lcase(char thesent[MAX])
    {
    int i,count=0;
    for (i=0;thesent[i]!='\0';i++)
        {
        if(thesent[i]>='a' && thesent[i]<='z')
        count++;
        }
    return (count);
    }
int total(char thesent[MAX])
    {
    int i,count=0;
    for (i=0;thesent[i]!='\0';i++)
        {
        count++;
        }
    return (count);
    }

We pass the string and Check their case and increment if they are with in the boundary.

Hello This is Sagar Devkota. Studying Bachelor of Software Engineering at Pokhara University. I know something about Linux, Android, Java, Nodejs, Unity3D and 3 dots :)

0 comments:

Post a Comment