Majority Uppercase and Lowercase Conversion ID:6855

 Majority Uppercase and Lowercase Conversion  ID:6855 


A string S is given as the input to the program. The program must convert all the alphabets in S to uppercase if the count of the uppercase alphabets is greater than the count of the lower case alphabets and print the string. If the count of the lowercase alphabets is greater than the count of the uppercase alphabets then the program must convert all the alphabets to lowercase alphabets and print the string. If the count of upper case and lower alphabets are equal then the program must print the string without any modifications.


Boundary Condition(s):

1 <= Length of string <= 1000


Example Input/Output:

Input:

dEmOcRAcY


Output:

DEMOCRACY

PROGRAM IN C:


#include<stdio.h>

#include<stdlib.h>

void lc(char s[])

{

    for(int i=0;i<strlen(s);i++)

    {

        printf("%c",tolower(s[i]));

    }

}

void uc(char s[])

{

    for(int i=0;i<strlen(s);i++)

    {

        printf("%c",toupper(s[i]));

    }

}

void ulc(char s[])

{int y=0,z=0;

    for(int i=0;i<strlen(s);i++)

    {int r=(int)s[i];

        if(r>96 && r<123)

        y++;

        else if(r>64 && r<91)

        z++;

    }

    if(y>z)

    {

        lc(s);

    }

else if(y==z)

    {

        printf("%s",s);

    }

    else

    {

        uc(s);

    }

}

int main()

{

char a[1000];

scanf("%s",a);

ulc(a);

}

Comments

Popular Posts