Programming in C 312303 Practical No.21 Develop C program using in-built mathematical and string functions

Programming in C 312303 Practical No.21 Develop a C program using in-built mathematical and string functions

Hello MSBTE students, in this blog post we solved Programming in C 312303 Practical No.21 in which we gained knowledge about Develop C program using in-built mathematical and string functions.

Programming in C 312303 Practical No.21
Programming in C 312303 Practical No.21

In this practical, students will learn how to create their own functions and use pre-made functions. They will also learn how to work with strings, do math calculations, and use various other tools. By the end, students will be able to do things like compare words, make copies of words, and find values like sine and cosine.

Exercise

1. Checking palindrome using string function
Answer:
#include <stdio.h>
#include <ctype.h>
#include <string.h>
int is_palindrome(const char *str) {
  int len = strlen(str);
  for (int i = 0; i < len / 2; i++) {
    // Convert characters to lowercase for case-insensitive comparison
    char left = tolower(str[i]);
    char right = tolower(str[len – 1 – i]);
    if (left != right) {
      return 0; // Not a palindrome
    }
  }
  return 1; // Palindrome
}
int main() {
  char str[100];
  printf(“Enter a string: “);
  fgets(str, 100, stdin);
  // Remove trailing newline character
  str[strcspn(str, “n”)] = ‘

Leave a Reply

Your email address will not be published. Required fields are marked *