Programming In C Practical 18

Question 1
Write a program to check string is palindrome or not.
Palindrom.cpp
C
				#include<stdio.h>
#include<conio.h>

void main()
{
	clrscr();
	char str[30];
	int i=0,j=0,flag=0;
	printf("\nEnter a string: ");
	scanf("%s",str);
	while(str[i]!='\0')
	{
		i++;
	}
	i--;
	while(j<=i)
	{
		if(str[j]!=str[i])
		{
			flag=1;
			break;
		}
		j++;
		i--;
	}
	
	if(flag==1)
		printf("\nString is not palindrom");
	else
		printf("\nString is palindrom");
	
	getch();
}
			
Output
Question 2
Write a program to demonstrate all string library functions.
Format.cpp
C
				#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 clrscr();
 char str[50],str1[50],str2[50],str3[50],str4[50],str5[50],str6[50];
 int len;
 printf("\n-----------------String length----------------");
 printf("\nEnter string:");
 scanf("%s",str);
 len=strlen(str);
 printf("Length of string is: %d",len);

 printf("\n\n-----------------String concatanation----------------");
 printf("\nEnter string 1:");
 scanf("%s",str1);
 printf("\nEnter string 2:");
 scanf("%s",str2);
 strcat(str1,str2);
 printf("Concat string is: %s",str1);

 printf("\n\n-----------------String comparison-----------------");
 printf("\nEnter string 1:");
 scanf("%s",str3);
 printf("\nEnter string 2:");
 scanf("%s",str4);
 if(strcmp(str3,str4)==0)
	 printf("Strings are same");
 else
	 printf("Strings are not same");

 printf("\n\n-----------------String copy----------------");
 printf("\nEnter string:");
 scanf("%s",str5);
 strcpy(str6,str5);
 printf("Copied string is: %s",str6);

 getch();
}
			
Output

Leave a Comment

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