fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. #define MAX 100
  6. void thuongSangHoa(char a[MAX]){
  7. int n = strlen(a);
  8. for (int i = 0; i < n; i++)
  9. {
  10. if (a[i] >= 97 && a[i] <= 122)
  11. {
  12. a[i] -= 32;
  13. }
  14.  
  15. }
  16.  
  17. }
  18.  
  19. void hoaSangThuong(char a[MAX]){
  20. int n = strlen(a);
  21. for (int i = 0; i < n; i++)
  22. {
  23. if (a[i] >= 65 && a[i] <= 90)
  24. {
  25. a[i] += 32;
  26. }
  27.  
  28. }
  29.  
  30. }
  31.  
  32. void kyTuDauInHoa(char a[MAX]){
  33. int n = strlen(a);
  34. hoaSangThuong(a);
  35.  
  36. for (int i = 0; i < n; i++)
  37. {
  38. if (a[i] == ' ')
  39. {
  40. a[i + 1] -= 32;
  41. }
  42. }
  43.  
  44. a[0] -= 32;
  45.  
  46. }
  47.  
  48. int main(){
  49. system("cls");
  50. char a[MAX];
  51. printf("Nhap vao chuoi: ");
  52. gets(a);
  53.  
  54. thuongSangHoa(a);
  55. printf("Chuoi sua khi chuyen sang chu in hoa: ");
  56. for (int i = 0; i < strlen(a); i++)
  57. {
  58. printf("%c", a[i]);
  59. }
  60.  
  61. hoaSangThuong(a);
  62. printf("\nChuoi sua khi chuyen sang chu thuong: ");
  63. for (int i = 0; i < strlen(a); i++)
  64. {
  65. printf("%c", a[i]);
  66. }
  67.  
  68. kyTuDauInHoa(a);
  69. printf("\nChuoi sua khi chuyen sang chu ky tu dau la in hoa: ");
  70. for (int i = 0; i < strlen(a); i++)
  71. {
  72. printf("%c", a[i]);
  73. }
  74.  
  75. return 0;
  76. }
Success #stdin #stdout #stderr 0.01s 5296KB
stdin
Standard input is empty
stdout
Nhap vao chuoi: Chuoi sua khi chuyen sang chu in hoa: 
Chuoi sua khi chuyen sang chu thuong: 
Chuoi sua khi chuyen sang chu ky tu dau la in hoa: �
stderr
sh: 1: cls: not found