kiem tien, kiem tien online, kiem tien truc tuyen, kiem tien tren mang
Thứ Tư, 5 tháng 3, 2014


/* Vi du Xau 1
  1- Nhap vao 1 xau ky tu co do dai <= 100
  2- In xau
  3- Cho biet do dai xau
  4- Dem so lan xuat hien cua ky tu c trong xau (c nhap tu ban phim)
  5- Tach xau thanh cac tu
  6- Dem so tu trong xau
  7-BTVN - Nhap vao mot xau,  kiem tra xem xau co nam trong xau ban dau hay khong???
*/

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

// khai bao
char str[100];

// 1- ham nhap
void Nhap(){
printf("\n Nhap xau: ");
fflush(stdin);
gets(str);
}

// 2-In xau
void InXau(){
// in xuoi
printf("\n In xau: %s",str);
// in nguoc
printf("\n In xau nguoc lai:");
for(int i=strlen(str);i>=0;i--)
printf("%c",str[i]);
}
// 3- Do dai xau
int DoDai(char xau[]){
 int l=strlen(xau);
 return l;
}

//  4- dem ky tu c trong xau
int Dem(char xau[], char c){
int dem=0;
for(int i=0;i<strlen(xau);i++)
if (xau[i]==c) dem++;
return dem;
}

// 5- Tach tu
void TachTu(char xau[]){
 printf("\n Tach xau thanh cac tu:\n");
 for(int i=0; i<strlen(xau);i++)
if (xau[i]==' ') printf("\n");
else printf("%c",xau[i]);
}

// 6- dem so tu trong xau
int DemTu(char xau[]){
int dem=0;
for(int i=0;i<strlen(xau);i++)
if (xau[i]==' ') dem++;
return dem+1;
}

// 7- kiem tra xem xau co nam trong xau ban dau hay khong
int XauCon(char xau1[], char xau2[]){
 int test=0, n1=strlen(xau1), n2=strlen(xau2); // abcder de;
 if(n1<n2)
test=0;
 else{
 int i=0, viTriBatDau=0;
 while (i<n2&&viTriBatDau<n1){
if(xau2[i]==xau1[viTriBatDau]){ i++; viTriBatDau++;}
else  {i=0; viTriBatDau++;}
 }

 if(i==n2) test=1;
 else test=0;
 }

 return test;
}

// Ham main
int main(){

Nhap();
InXau();

printf("\n Do dai xau :%d",DoDai(str));

char c;
printf("\n Nhap ky tu can dem:");

scanf("%c",&c);

printf("\n Dem ky tu trong xau :%d",Dem(str,c));

TachTu(str);

printf("\n Dem so tu trong xau: %d",DemTu(str));

char xau[100];
printf("\n Nhap vao xau con can kiem tra: ");
fflush(stdin);
gets(xau);

if (XauCon(str,xau)==1) printf("\n Xau con ");
else   printf("\n Khong phai xau con");

getch();
return 0;
}
05 Mar 2014

0 nhận xét:

Đăng nhận xét

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

domain, domain name, premium domain name for sales

Bài đăng phổ biến