String

C program to check whether given string is palindrome or not

#include<stdio.h> #include<conio.h> #include<string.h> void main() { int i,j,flag=1,len; char str[50]; clrscr(); printf(“Enter any string:”); gets(str); len=strlen(str); for(i=0,j=len-1;i<len/2;++i,–j) if(str[i]!=str[j]) { flag=0; break; } if(flag) printf(“String is palindrome“); else printf(“String is not palindrome”); getch(); }

C program to reverse a string

#include<stdio.h> #include<conio.h> #include<string.h> void main() { int i,n; char a[30]; clrscr(); printf(“Enter any string:”); gets(a); n=strlen(a); printf(“Reverse of string:”); for(i=(n-1);i>=0;–i) printf(“%c”,a[i]); getch(); }

C program to read a string and print it in alphabetical order

#include<stdio.h> #include<conio.h> #include<string.h> void main() { int i,j,n,ch1,ch2; char a[50],temp; clrscr(); printf(“Enter any string:”); scanf(“%s”,a); n=strlen(a); for(i=1;i<n;++i) for(j=0;j<(n-i);++j) { ch1=a[j]; ch2=a[j+1]; if(ch1>ch2) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } printf(“String after arranging %s”,a); getch(); }

C++ Program to convert first letter of each word of a string to uppercase and other to lowercase

#include<iostream.h> #include<conio.h> #include<stdio.h> #include<ctype.h> void main() { clrscr(); int i; char a[30]; cout<<“Enter a string:”; gets(a); for(i=0;a[i]!=’’;++i) { if(i==0) { if(islower(a[i])) a[i]=toupper(a[i]); } else { if(a[i]!=’ ‘) { if(isupper(a[i])) a[i]=tolower(a[i]); } else { i++; if(islower(a[i])) a[i]=toupper(a[i]); } } } cout<<“nnNew string is: “<<a; getch(); }

C++ Program to Reverse All the Strings Stored in an Array

Here you will get C++ program to reverse all the strings stored in an array. #include<iostream> #include<string.h> #include<stdio.h> using namespace std; int main() { char a[3][50]; int i,j,k,len; cout<<“Enter 3 strings:\n”; for(i=0;i<3;i++) { gets(a[i]); } cout<<“\nThe list of orignal strings:\n” ; for(i=0;i<3;i++) { cout<<a[i]<<“\n”; } cout<<“\nThe list of changed strings:\n”; for(i=0;i<3;i++) { len=strlen(a[i]); for(j=0,k=len-1;k>=0;j++,k–) { …

C++ Program to Reverse All the Strings Stored in an Array Read More »