? Mastering DSA in C - 35 Questions & Answers ?
? Mastering DSA in C - 35 Questions & Answers ?
1. #include <stdio.h>
2. #include <string.h>
3.
4. int isPalindrome(char str[]) {
5. int length = strlen(str);
6. for (int i = 0; i < length / 2; i++) {
7. if (str[i] != str[length - i - 1])
8. return 0; // Not a palindrome
9. }
10. return 1; // Palindrome
11. }
12.
13. int main() {
14. char input[100];
15. printf("Enter a string: ");
16. scanf("%s", input);
17. if (isPalindrome(input))
18. printf("It's a palindrome.\n");
19. else
20. printf("It's not a palindrome.\n");
21. return 0;
22. }
23.
1. #include <stdio.h>
2.
3. int gcd(int a, int b) {
4. if (b == 0)
5. return a;
6. else
7. return gcd(b, a % b);
8. }
9.
10. int main() {
11. int num1, num2;
12. printf("Enter two numbers: ");
13. scanf("%d %d", &num1, &num2);
14. printf("GCD of %d and %d is %d\n", num1, num2, gcd(num1, num2));
15. return 0;
16. }
17.
CLICK ME HERE