Skip to content

Instantly share code, notes, and snippets.

@Kimxons
Created April 17, 2021 19:41
Show Gist options
  • Save Kimxons/cf172282985a79f65c33cd40bcd02bb6 to your computer and use it in GitHub Desktop.
Save Kimxons/cf172282985a79f65c33cd40bcd02bb6 to your computer and use it in GitHub Desktop.

Revisions

  1. Kimxons created this gist Apr 17, 2021.
    24 changes: 24 additions & 0 deletions palindrome in c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    #include<stdio.h>
    #include<string.h>

    void palindrome(char str[])
    {
    int leftmost_index = 0;
    int rightmost_index = strlen(str) - 1;

    while(rightmost_index > leftmost_index)
    {
    if(str[leftmost_index++] != str[rightmost_index--])
    {
    printf("%s not a palindrome\n", str);
    return;
    }
    }
    printf("%s is a palindrome\n", str);
    }

    int main()
    {
    palindrome("mom");
    return 0;
    }