#include<stdio.h> #include<conio.h> #include<string.h> int is_palindrome(char*);
ID: 3940522 • Letter: #
Question
#include<stdio.h>
#include<conio.h>
#include<string.h>
int is_palindrome(char*); //function prototype
int main()
{
char string[100],*ptr; // declaring the string variable , max size up to 101 characters.
int result; // a variable declared to store the result of is_palindrome()
printf("Enter a string ");
gets(string);
ptr=&string[0]; //Getting input from the user.
result = is_palindrome(ptr); // string is sent as an argument to the is_palindrome()
if ( result == 1 ) //if else case, if is_palindrome() returns 1 then the string is palindrome
printf(""%s" is a palindrome string. ", string);
else
printf(""%s" is not a palindrome string. ", string);
getch();
return 0;
}
int is_palindrome(char* string)
{
char *p1=string; //pointer storing the address of the first character
char *p2=string+strlen(string)-1; // pointer storing the address of the last character
while(p2>p1){
if(tolower(*p1)!=tolower(*p2)){ //comparing the characters from beginning and end
return(0);
}
p1++;
p2--;
}
return(1);
}
please fix this code I need it to work in gcc compiler I need it ASAP
Find the values of x for which the series below converges, and find the sum of the series for those values of x. sigma_n = 0^infinity (-4)^n (x - 5)^n sin x - 1/2 sin^2 x + 1/4 sin^3 x - 1/8 sin^4 x = Please be as detail as possible.Explanation / Answer
#include<stdio.h>
//#include<conio.h> //remove this as this is not allowed
#include <ctype.h> //include this for using tolower function
#include<string.h>
int is_palindrome(char*); //function prototype
int main()
{
char string[100],*ptr; // declaring the string variable , max size up to 101 characters.
int result; // a variable declared to store the result of is_palindrome()
printf("Enter a string ");
//gets(string);
scanf("%s",string); //use scanf instead of gets as gets is removed from c99
ptr=&string[0]; //Getting input from the user.
result = is_palindrome(ptr); // string is sent as an argument to the is_palindrome()
if ( result == 1 ) //if else case, if is_palindrome() returns 1 then the string is palindrome
printf(""%s" is a palindrome string. ", string);
else
printf(""%s" is not a palindrome string. ", string);
//getch(); //remove getch() as there is no use of getch here and it is not allowed in c also
return 0;
}
int is_palindrome(char* string)
{
char *p1=string; //pointer storing the address of the first character
char *p2=string+strlen(string)-1; // pointer storing the address of the last character
while(p2>p1){
if(tolower(*p1)!=tolower(*p2)){ //comparing the characters from beginning and end
return(0);
}
p1++;
p2--;
}
return(1);
}
*****OUTPUT****
Enter a string
heleh
"heleh" is a palindrome string.
sh-4.3$ main
Enter a string
hihi
"hihi" is not a palindrome string.
*****OUTPUT****
Note:i have fixed this code which is running fine in gcc compiler,please ask question in case of any doubt,Thanks.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.