0% found this document useful (0 votes)
11 views2 pages

Practical No 15

The document contains two C programs: the first checks if a string is a palindrome without using string library functions, while the second swaps two strings using string library functions. The palindrome program calculates the length of the string and compares characters from both ends, while the swap program utilizes 'strcpy' to exchange the values of two strings. Example outputs for both programs are provided to demonstrate their functionality.

Uploaded by

technovision22co
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Practical No 15

The document contains two C programs: the first checks if a string is a palindrome without using string library functions, while the second swaps two strings using string library functions. The palindrome program calculates the length of the string and compares characters from both ends, while the swap program utilizes 'strcpy' to exchange the values of two strings. Example outputs for both programs are provided to demonstrate their functionality.

Uploaded by

technovision22co
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1) Program to Check if a String is a Palindrome (Without Using

String Library Functions)

#include<stdio.h>
#include<conio.h>
void main()
{
char str[100];
int i, len = 0, flag = 1;

printf("Enter a string: ");


scanf("%s", str);

while (str[len] != '\0')


{
len++;
}

for (i = 0; i < len / 2; i++)


{
if (str[i] != str[len - i - 1])
{
flag = 0;
break;
}
}

if (flag)
printf("The string is a palindrome.\n");
else
printf("The string is not a palindrome.\n");

getch();
}

----------------------OUTPUT-----------------

Enter a string: madam


The string is a palindrome.
(2) Program to Swap Two Strings Using String Library Functions

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

void main()
{
char str1[100], str2[100], temp[100];

printf("Enter first string: ");


scanf("%s", str1);
printf("Enter second string: ");
scanf("%s", str2);

strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);

printf("After swapping:\n");
printf("First string: %s\n", str1);
printf("Second string: %s\n", str2);

getch();
}

Example Output

Enter first string: Hello


Enter second string: World
After swapping:
First string: World
Second string: Hello

You might also like