Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that takes a string input from user and stores it in an array. T

ID: 3801968 • Letter: W

Question

Write a program that takes a string input from user and stores it in an array. Then, write a function to test that string whether it reads the same way forward and backward. The function should return 1 if it does, otherwise returns 0. For example: "radar, " "able was i ere i saw Elba, " will return 1, whereas "I like C" will return 0. Write another similar function that will ignore blanks. For example: the second function will return 1 for "a man a plan a canal panama", but the first function will return 0. Do NOT use recursion.

Explanation / Answer

Hi,

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

int main(){
  
int i, length;
int flag = 0;
  
printf("Enter a number:");
scanf("%d", &length);

char string1[length];

printf("Enter a string:");
scanf("%s", string1);
  

  
for(i=0;i < length ;i++){
if(string1[i] != string1[length-i-1]){
flag = 1;
break;
   }
   }
  
if (flag) {
printf("0 ");
}
else {
printf("1 ");
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote