Question:
how to loop this using turbo C.?
jeL
2010-10-13 06:51:47 UTC
please help me to create a program that will display the value of a,e,i,o,u when you are going to input lines or phrases.sample output are looks like this.
"the number of A's are: 3"
"the number of E's are:5"
so on...please help me...
Three answers:
cja
2010-10-13 08:29:38 UTC
I would encourage you to avoid the brute force approach; i.e., nowhere in your code should you see a statement such as:



    if (c == 'a') { . . .



Try something like this:



#include

#include

#include

#include



#define MAX_LINE_LEN 80

#define EOS '\0'



const char *vowels = "aeiou";

int vowelIndex(char c);



int main(int argc, char *argv[]) {

    char s[MAX_LINE_LEN];

    const char *p;

    size_t *vCount = calloc(strlen(vowels), sizeof(size_t)),

        vCountSize = strlen(vowels) * sizeof(size_t);

    int x;



    while (1) {

        printf("\n> ");

        fgets(s,MAX_LINE_LEN,stdin);

        *(strchr(s,'\n')) = EOS;

        for (p = s; *p != EOS; p++) {

            if ((x = vowelIndex(*p)) != -1) {

                vCount[x]++;

            }

        }

        printf("Vowel counts:\n");

        for (p = vowels; *p != EOS; p++) {

            printf("%c : %d\n",*p, vCount[p - vowels]);

        }

        memset(vCount, 0, vCountSize);

    }

    free(vCount);

    return 0;

}



int vowelIndex(char c) {

    int x = -1;

    char *p = strchr(vowels, tolower((int)c));



    if (p != NULL) {

        x = p - vowels;

    }

    return x;

}



#if 0



Sample run:



> hello, world.

Vowel counts:

a : 0

e : 1

i : 0

o : 2

u : 0



> Another One

Vowel counts:

a : 1

e : 2

i : 0

o : 2

u : 0



> aeiouAEIOU

Vowel counts:

a : 2

e : 2

i : 2

o : 2

u : 2



#endif
Rohit Khanna
2010-10-13 14:08:46 UTC
Let i explain it to you with an example:-



int a[5];

for(int i=1;i<=5;i++)

{

cin>>a[5];

}

int countA=0,countE=0;

for(int i=1;i<=5;i++)

{

if(a[i]='A' || a[i]='a')

countA++;

if(a[i]='E' || a[i]='e')

countB++;

}

cout<<"the number of A's are: "<
cout<<"the number of E's are: "<




IF u got then make it best....
JoelKatz
2010-10-13 13:58:00 UTC
Okay. What help do you need?


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...