From 3c7d1eb5c42dcd583b52312e39a46d493864a9e2 Mon Sep 17 00:00:00 2001 From: ntua-el21401 Date: Mon, 24 Feb 2025 18:03:55 +0200 Subject: [PATCH] Create palindrome.dana Program that reads a word and checks if it's a palindrome or not --- dana/programs/palindrome.dana | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 dana/programs/palindrome.dana diff --git a/dana/programs/palindrome.dana b/dana/programs/palindrome.dana new file mode 100644 index 0000000..f74c77c --- /dev/null +++ b/dana/programs/palindrome.dana @@ -0,0 +1,24 @@ +def checkPalindrome is byte: word as byte[] + var length is int := 0 + loop: + if word[length] = '\0': break + length := length + 1 + + var i is int := 0 + loop: + if i >= length / 2: break + if word[i] <> word[length - i - 1]: + return false + i := i + 1 + return true + +def main + var word is byte[100] + + writestring: "Gimme a word!\n" + readstring: 100, word + + if checkPalindrome(word): + writestring: "It is a palindrome!\n" + else: + writestring: "It is not a palindrome\n"