Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
{
if(s[i] == s[j])
printf("\npalindrome");
}
if (s[i]!=s[j])
{printf("NO");
return;
}
thông cảm nhé)#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <io.h>
FILE *f;
char s[50];
void open()
{int i,j;
f = fopen("sample.inp","rt");
fscanf(f,"%s",s);
fclose(f);
}
void process()
{ int i,j;
f = fopen("sample.out","wt");
for(i = 0,j = strlen(s)-1;i<=(strlen(s)-1)/2; i++,j--)
if (s[i]!=s[j])
{fprintf(f,"NO");
fclose(f);
return;
}
fprintf(f,"YES");
fclose(f);
}
void main()
{ open();
process();
}
đây là code mình viết
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
void main(){
char s[50];
int i, d, n, j;
printf("\nNhap chuoi : ");
scanf("%c", s);
d = strlen(s);
n = d/2;
for(i = 0, j = d ; i < n; i++ , j--)
{
if(s == s[j])
printf("\npalindrome");
}
printf("\nnot palindrome");
}
ko biết sai chổ nào xin các pro chỉ ra giúp
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
void main()
{ clrscr();
char *n;
int i;
printf("\nEnter your text : ");
gets(n);
printf("\nYour text is : %s\n", n);
printf("The text is reversed is: ",n);
for(i = strlen(n) ; i >= 0 ; i--)
printf("%c",*(n+i));
getch();
}
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
void main()
{ clrscr();
char *n,temp;
int i,j;
printf("\nEnter your text : ");
gets(n);
printf("\nYour text is : %s\n", n);
for(i=0,j=strlen(n)-1;i<(strlen(n)/2);i++,j--)
{ temp=*(n+i);
*(n+i)=*(n+j);
*(n+j)=temp;
}
printf("The text is reversed is: %s",n);
getch();
}
Write a C program to reverse a character aray using pointer
Đây là code mình viết
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
void main(){
char *p;
char temp, n;
int i, j;
printf("\nEnter your text : ");
scanf("%s", n);
printf("\nYour text is : %s", n);
p = (char*)malloc(n*sizeof(char));
for(i = 0 ; i < strlen(n)-1 ; i++)
{
for(j = i+1 ; j < strlen(n) ; j++)
{
temp = *(p+i);
*(p+i)=*(p+j);
*(p+j)=temp;
}
}
free(p);
for(i = 0 ; i < strlen(n) ; i++)
{
printf("The text is reversed is : %s",*(p+i));
}
getch();
}
Khi chạy ct thi vẫn ra file exe nhưng mà báo đống lỗi và run cai exe đó thi no lai bao debug
khi mình thay cái strlen(n) = strlen (p) thi chay ko báo lỗi nhung cũng bị debug
Bạn nào biết giai thích hộ mình , và mình nên sữa như thế nào
mà nếu cậu muốn thế này thì phải cho n là int rồi đặt nó là số kí tự tối đa của chuỗi.mình khai báo char n va *p sau đó minh mới gán cho
p = (char*)malloc(n*sizeof(char));