Skip to content

Commit 7cc60a4

Browse files
ashwekMadhavBahl
authored andcommitted
Day 4 - C (#52)
* Create vowels.c * Create max_chars.c * Update README.md
1 parent a73d208 commit 7cc60a4

File tree

3 files changed

+128
-6
lines changed

3 files changed

+128
-6
lines changed

day4/C/max_chars.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 25/12/2018
4+
*/
5+
6+
#include<stdio.h>
7+
8+
void main(){
9+
10+
char Str[50];
11+
int i, Max = 0;
12+
int possibleChar[94] = {0}; //ASCII 32-126
13+
14+
printf("Enter a string = ");
15+
scanf("%[a-zA-Z-0-9 ]s", Str); //Modify control string to accept blank spaces in input
16+
17+
for(i=0; Str[i]!='\0'; i++){
18+
possibleChar[ (int)Str[i] - 32]++;
19+
if( possibleChar[Max] < possibleChar[ (int)Str[i] - 32] )
20+
Max = (int)Str[i] - 32;
21+
}
22+
23+
printf("Most frequent character = \'%c\'\n", (Max+32));
24+
}

day4/C/vowels.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author : ashwek
3+
* @date : 25/12/2018
4+
*/
5+
6+
#include<stdio.h>
7+
#include<ctype.h>
8+
9+
void main(){
10+
11+
char Str[50];
12+
int i, count=0;
13+
14+
printf("Enter a string = ");
15+
scanf("%s", Str);
16+
17+
for(i=0; Str[i]!='\0'; i++){
18+
switch(tolower(Str[i])){
19+
case 'a':
20+
case 'e':
21+
case 'i':
22+
case 'o':
23+
case 'u':
24+
count++;
25+
}
26+
}
27+
28+
printf("number of vowels = %d", count);
29+
30+
}

day4/README.md

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,13 @@ for char in string:
287287
print("Number of vowels in the string are : ",count)
288288

289289
```
290-
##Python Implementation
291290

292-
##[Solution](./Python/Shashankvowels.py)
291+
## [Solution](./Python/Shashankvowels.py)
292+
```Python
293293
"""
294294
* @author: Shashank Jain
295295
* @date: 25/12/2018
296296
"""
297-
```Python
298297
a=input("Enter the string to count no. of vowels?")
299298
b=list(a.replace(" ","").lower())
300299
c=['a','e','i','o','u']
@@ -306,7 +305,45 @@ for i in b:
306305
print(count)
307306
```
308307

308+
## C Implementation
309+
310+
### [Solution](./C/vowels.c)
311+
312+
```c
313+
/**
314+
* @author : ashwek
315+
* @date : 25/12/2018
316+
*/
317+
318+
#include<stdio.h>
319+
#include<ctype.h>
320+
321+
void main(){
322+
323+
char Str[50];
324+
int i, count=0;
325+
326+
printf("Enter a string = ");
327+
scanf("%s", Str);
328+
329+
for(i=0; Str[i]!='\0'; i++){
330+
switch(tolower(Str[i])){
331+
case 'a':
332+
case 'e':
333+
case 'i':
334+
case 'o':
335+
case 'u':
336+
count++;
337+
}
338+
}
339+
340+
printf("number of vowels = %d", count);
341+
342+
}
343+
```
344+
309345
</hr>
346+
310347
## Part B -- Max Chars Problem
311348

312349
**Question** - Given a string, write a program to return the character that appears most frequently in that string
@@ -456,13 +493,14 @@ print("The most occouring character in the string is : ", max(characters,key=cha
456493

457494
```
458495

459-
##Python Implementation
460-
###[Solution] (./Python/Shashankchar.py)
496+
### [Solution] (./Python/Shashankchar.py)
497+
498+
```python
461499
"""
462500
* @author: Shashank Jain
463501
* @date: 25/12/2018
464502
"""
465-
``` Python
503+
466504
a=input("Enter the string to count frequent occuring characters?")
467505
b=list(a.replace(" ","").lower())
468506
c=[]
@@ -476,3 +514,33 @@ g=max(e.values())
476514
print("maximum occurence is of {0}:{1}".format(f,g))
477515
```
478516

517+
## C Implementation
518+
519+
### [Solution](./C/max_chars.c)
520+
521+
```c
522+
/**
523+
* @author : ashwek
524+
* @date : 25/12/2018
525+
*/
526+
527+
#include<stdio.h>
528+
529+
void main(){
530+
531+
char Str[50];
532+
int i, Max = 0;
533+
int possibleChar[94] = {0}; //ASCII 32-126
534+
535+
printf("Enter a string = ");
536+
scanf("%[a-zA-Z-0-9 ]s", Str); //Modify control string to accept blank spaces in input
537+
538+
for(i=0; Str[i]!='\0'; i++){
539+
possibleChar[ (int)Str[i] - 32]++;
540+
if( possibleChar[Max] < possibleChar[ (int)Str[i] - 32] )
541+
Max = (int)Str[i] - 32;
542+
}
543+
544+
printf("Most frequent character = \'%c\'\n", (Max+32));
545+
}
546+
```

0 commit comments

Comments
 (0)