Skip to content

Commit 83c764d

Browse files
committed
solve 7th problem of string in C
1 parent 1bbeacf commit 83c764d

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

a.out

8 Bytes
Binary file not shown.

solve_problem.c

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,50 @@
132132
// // 👉👉 🔹🔹 question 6️⃣ write a fuction named slice , which takes
133133
// a string & returns sclice from string from index n to m
134134

135+
// #include <stdio.h>
136+
// void sclice(char str[], int n, int m);
137+
// int main()
138+
// {
139+
// char str[] = "Coder Boy";
140+
// sclice(str, 3, 6); // Function call
141+
// return 0;
142+
// }
143+
144+
// // Function Definition
145+
// void sclice(char str[], int n, int m)
146+
// {
147+
// char newStr[45];
148+
// int j = 0;
149+
// for (int i = n; i <= m; i++, j++)
150+
// {
151+
// newStr[j] = str[i];
152+
// }
153+
// newStr[j] = '\0';
154+
155+
// puts(newStr);
156+
// }
157+
158+
// // 👉👉 🔹🔹 question 7️⃣ write a function to count occurrence of vowels in a string
135159
#include <stdio.h>
136-
void sclice(char str[], int n, int m);
160+
int countVowels(char str[]);
137161
int main()
138162
{
139-
char str[] = "Coder Boy";
140-
sclice(str, 3, 6); // Function call
163+
char str [] = "Education";
164+
printf("Vowel are : %d\n" , countVowels(str)); // Function call ;
141165
return 0;
142166
}
143-
144167
// Function Definition
145-
void sclice(char str[], int n, int m)
168+
int countVowels(char str[])
146169
{
147-
char newStr[45];
148-
int j = 0;
149-
for (int i = n; i <= m; i++, j++)
170+
int count = 0;
171+
for (int i = 0; str[i] != '\0'; i++)
150172
{
151-
newStr[j] = str[i];
173+
if (str[i] == 'a' || str[i] == 'e' || str[i] == 'i' || str[i] == 'o' || str[i] == 'u')
174+
{
175+
count ++;
176+
}
152177
}
153-
newStr[j] = '\0';
154-
155-
puts(newStr);
178+
return count ;
156179
}
157180

158181
// 1️⃣ 2️⃣ 3️⃣ 4️⃣ 5️⃣ 6️⃣ 7️⃣ 8️⃣ 9️⃣ 🔟

0 commit comments

Comments
 (0)