forked from thantrieu/LearnC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbai5.8.c
54 lines (50 loc) · 910 Bytes
/
bai5.8.c
1
2
3
4
5
6
7
8
9
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
53
54
#include <stdio.h>
#include <string.h>
int dauCachDau(char* s) { // tim dau cach dau tien
int len = strlen(s);
int i;
for(i = 0; i < len; i++) {
if(s[i] == ' ') {
return i;
}
}
return -1;
}
int dauCachCuoi(char* s) { // tim dau cach cuoi cung
int len = strlen(s);
int i;
for(i = len - 1; i >= 0; i--) {
if(s[i] == ' ') {
return i;
}
}
return -1;
}
void hienThi(char *s) { // hien thi ket qua ra man hinh
int first = dauCachDau(s);
int last = dauCachCuoi(s);
int i;
int len = strlen(s);
if(first != -1 && last != -1) {
// in ten
for(i = last + 1; i < len - 1; i++) {
printf("%c", s[i]);
}
// in dem
for(i = first; i <= last; i++) {
printf("%c", s[i]);
}
// in ra ho
for(i = 0; i < first; i++) {
printf("%c", s[i]);
}
} else {
printf("Nhap dung dinh dang: ho dem ten");
}
}
int main(){
char s[100];
fgets(s, 99, stdin);
hienThi(s);
return 0;
}