Q: How to find the vowels count of a given text by using switch in C program?
This C program is used to find the number of vowels in your given text by using a switch statement. Initially checking the character of text separately and match with case value. If the character matches with the condition, then increment by one in the vowel count or ignore the character. Finally print the number of vowels present in the given input text.
Vowels count program in C:
01
02
03
04
05
06
07
08
09
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
| //Header files#include<stdio.h>#include<conio.h>void main(){ //Program varaibles int eCou=0,aCou=0,oCou=0,iCou=0,conCou=0,uCou=0; char cha; clrscr(); //Function to clear the previous output printf("Enter ur text here : \n"); //Display function while((cha=getchar())!='\n') //Unconditional statement { switch(cha) //Switch statement { case 'a': aCou++; break; case 'e': eCou++; break; case 'i': iCou++; break; case 'o': oCou++; break; case 'u': uCou++; break; default: conCou++; } } printf("Number of Character \n"); printf("a\t%d;e\t%d;i\t%d;o\t%d;u\t%d;rest\t%d ;",aCou,eCou,iCou,oCou,uCou,conCou); getch();} |
C PROGRAM 2:
Q: How to find vowel count in a string by using unconditional statement and conditional statements?
01
02
03
04
05
06
07
08
09
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
48
49
50
51
52
| //Header file section#include#include//Global varaiblesint vowels(char []);int c_vowel(char);main(){// Program variableschar b[100];int c;printf("Enter the text\n"); //Display functiongets(b);c = count_vowels(b); //Assigning valueprintf("no of vowels: %d\n", c);return 0;}int vowels(char f[]){int count = 0, g = 0, flag;char a;do//Unconditional statement{a = f[g];flag = check_vowel(d);if ( flag == 1 )count++;c++;}while( a != '\0' );return count;}int check_vowel(char f){if ( f >= 'A' && f<= 'Z' ) //Conditional statementf = a + 'a' - 'A'; //Lower case to upper caseif ( f == 'a' || f == 'e' || f == 'i' || f == 'o' || f == 'u')return 1;return 0;} |
No comments:
Post a Comment