By GokiSoft.com| 20:58 22/09/2023|
Lập Trình C

Bài tập ôn tập String - Lập trình C

Bài 1 : Nhập vào chuỗi -> in ra độ dại của chuỗi đó 

Bài 2 : Nhập vào 2 chuỗi s1, s2 -> Thực hiện nối chuỗi s2 vào s1 -> In ra độ dài của chuỗi s1

Bài 3 : Nhập vào chuỗi str -> in ra màn hình mỗi ký tự trong chuỗi trên 1 dòng

Ví dụ : chuỗi nhập : gokisoft.com

Kết quả in :

g

o

k

i

s

o

f

t

.

c

o

m

Phản hồi từ học viên

5

(Dựa trên đánh giá ngày hôm nay)

Do Trung Duc [T2008A]
Do Trung Duc

2020-09-19 09:48:58



//Bài 1 : Nh?p vào chu?i -> in ra d? d?i c?a chu?i dó 
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
	
	char s[50]; 
	printf("Nhap chuoi s: ");
	gets(s);
	
	int len=strlen(s);
	printf("Do dai chuoi s la: %d", len);
	
	return 0;
}



Trần Văn Lâm [T2008A]
Trần Văn Lâm

2020-09-18 16:17:39



#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//BAI 2
int main(int argc, char *argv[]) {
	char s1[10], s2[20];
	fflush(stdin); fflush(stdout);
	printf("\nNhap s1:");
	
	gets(s1);
	fflush(stdin); fflush(stdout);
	printf("\nNhap s2:");
	gets(s2);
	
	strcat(s1,s2);
	printf("\Chuoi noi: %s", s1);
	
	strlen(s1);
	printf("\nDo dai chuoi s1 = %d", s1);
	
	
	return 0;
}



Trần Văn Lâm [T2008A]
Trần Văn Lâm

2020-09-18 15:37:59



#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//BAI1
int main(int argc, char *argv[]) {
	char h[1508];
	int len;
	printf("\nNhap chuoi h:");
	gets(h);
	len = strlen(h);
	printf("\nDo dai chuoi h = %d", len);
	return 0;
}



vuong huu phu [T2008A]
vuong huu phu

2020-09-18 14:50:04


bai3
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
 char t[100];
 int i=0;
 
 printf("\n nhap chuoi t = ");
 fflush(stdin);fflush(stdout);
 gets(t);
 
 while (i<strlen(t)){
 	printf("\n%c",t[i]);
 	i++;
 }
 
	return 0;
}



vuong huu phu [T2008A]
vuong huu phu

2020-09-18 14:37:32

bai 2


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
 char s1[100],s2[100],s3[100];
 printf("\n nhap s1 = ");
 fflush(stdin);fflush(stdout);
 gets(s1);
 printf("\n nhap s2 = ");
 fflush(stdin);fflush(stdout);
 gets(s2);
 strcat(s1,s2);
 printf("\n chuoi noi la = %s",s1);
 int i=strlen(s1);
 printf("\n do dai chuoi s1 = %d",s1);
 
	return 0;
}



vuong huu phu [T2008A]
vuong huu phu

2020-09-18 14:19:38


bai 1


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
 char a[50];
 printf("\n nhap chuoi ");
 gets(a);
 int i=strlen(a);
 printf("\n do dai cua chuoi = %d",i);
	return 0;
}



nguyễn Sử [T2008A]
nguyễn Sử

2020-09-18 13:23:07



#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bai1:
int main(int argc, char *argv[]) {
	int i;
	
	char s[999];
	
	printf("\nNhap chuoi s: ");
	
	scanf("%d, &s");
	
	gets(s);
	
	printf("\nDo dai cua chuoi: %d", i);
	
//bai2:
	char s1[111], s2[999];
		
	printf("\nNhap s1: ");
	scanf("%s, &s1");
	gets(s1);

	printf("\nNhap s2: ");
	scanf("%s, &s2");
	gets(s2);
	
	strcat(s2, s1);
	printf("\nNoi chuoi: %s", s2);


//bai3:
	char  str[999];
	
	printf("\nNhap str: ");
	scanf("%s, &str");
	gets(str);

	for(i=0;i<strlen(str);i++)
	printf("\n%s\n",str[i]);





	
	return 0;
}



Đức Sơn [T2008A]
Đức Sơn

2020-09-18 10:09:44



//Bai 1:
	char N[] = "Gokisoft";
   int i = 0;
   
   while(N[i] != '\0') {
      i++;
   }
   
   printf("\nDo dai cua chuoi la:'%s', %d", N, i);
   
//Bai 2:
    char s1[50];
    char s2[50];
    char s3[50];
    int len;
    
    printf("\nNhap 1:\n");
    gets(s1);
    
    printf("\nNhap 2:\n");
    gets(s2);
    
    strcpy(s3,s1);
    strcat(s3,s2);
    
    printf("\nNoi chuoi:%s",s3);
    
//Bai 3:
    char* str = "Le cong duc";
    int i = 0;

    for ( i < strlen(str), i++); {
    if (str[i] != ' ') {
    printf("%c",str[i]);
} else {
    printf("\n");
}
}
    printf("\n");
      
    
	return 0;
	
   
}



Triệu Văn Lăng [T2008A]
Triệu Văn Lăng

2020-09-18 09:41:35



#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int n, i;
	printf("\n===============================bai 1");
    printf("\nnhap so phan tu cua chuoi: "); scanf("%d",&n);
    char s[n];
    
    for(i=0;i<=n;i++) {
    	printf("\nnhap s[%d]: ",i); scanf("%s",&s[i]);
	}
    int len= strlen(s);
	printf("\ndo dai chuoi s la %d",len);
	 
	printf("\n===============================bai 2");
	char s1[10], s2[10];
	printf("\nnhap s1= "); scanf("%s",&s1);
	printf("\nnhap s2= "); scanf("%s",&s2);
	
	strcat(s2,s1);
	puts(s2);
	int len1= strlen(s1);
	printf("\ndo dai chuoi s1 la: %d",len1);
	
	printf("\n===============================bai 3");
	char str[100], k, t;
	printf("\nnhap chuoi str= "); scanf("%s",&str);
	printf("\nchuoi str la %s",str);
	k=strlen(str)+1;
	for(t=0;t<=k;t++) {
		printf("\n%c",str[t]);
	}
	
	
	
	
	
	return 0;
}



hainguyen [T2008A]
hainguyen

2020-09-18 09:37:45



#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	//bai 1
	char s1[100];
	int len;
	
	printf("\nNhap s1: \n");
	gets(s1);

	
   
	//bai 2
	char s3[100];
	char s2[100];
	printf("\nNhap s2: \n");
	gets(s2);
	strcat(s3, s1);
	printf("\nNoi chuoi: %s", s3);
	
	
	//bai 3

	char str[100], i, n;
	printf("\nNhap str: ");
	gets(str);
	n = strlen(str)+1;
	for(i=0; i<=n; i++){
		printf("\n%c", str[i]);
		

}
	return 0;
}