strrev in c

Problem Statement

Program Code for Each string reversal if its contain equal vowel and consonant count.

Solution

 #include<stdio.h>

#include <stdlib.h>

#include<string.h>

int main()

{

char s[1000];

int i,j,n,count,count1;

while(scanf("%s",s)==1) //accepting the whole strings by splitting.

{

    n=strlen(s);

    count=0;

    count1=0;

    i=0;

    while(i<n)

    {

        if(s[i]=='a'||s[i]=='e'||s[i]=='i'||s[i]=='o'||s[i]=='u'||s[i]=='A'||s[i]=='E'||s[i]=='I'||s[i]=='O'||s[i]=='U')

        count++;

        else

        count1++;

        i++;

    }

    if(count==count1) //checking for vowel and consonant count

    {

        for(j=n-1;j>=0;j--)

        {

            printf("%c",s[j]);

        }

        printf(" ");

    }

    else

    printf("%s ",s);

}

return 0;

}

Note;

we have to reverse the word if its contain equal vowel and consonant count.

else print the string as it is.


input 1

hi runout the onion.

output 1

ih tuonur the onion.


Explanation:

ih(1vowel==1consonants so interchanged)

runout(3vowel==3consonants so interchanged)

the(vowels and consonants are not equal so not interchanged)

onion(vowels and consonants are not equal so not interchanged)


input 2

code blocks

output 2

edoc blocks

Rajesh

This Blog will help you to find out the c programs solution easily and also you can able to understand the program.Please follow our blog for more useful updates.

Post a Comment (0)
Previous Post Next Post