0% found this document useful (0 votes)
37 views3 pages

Reverse A String

This document contains code snippets for 3 different C++ programs: 1) A program to reverse a string by copying the characters from the end of the string to a new string. 2) A program to transpose a matrix by copying each row of the original matrix to the corresponding column of the new matrix. 3) A program to check if a string is a palindrome by comparing the first and last characters, then moving inward, until the middle is reached or a mismatch is found.

Uploaded by

Sonam Gupta
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)
37 views3 pages

Reverse A String

This document contains code snippets for 3 different C++ programs: 1) A program to reverse a string by copying the characters from the end of the string to a new string. 2) A program to transpose a matrix by copying each row of the original matrix to the corresponding column of the new matrix. 3) A program to check if a string is a palindrome by comparing the first and last characters, then moving inward, until the middle is reached or a mismatch is found.

Uploaded by

Sonam Gupta
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/ 3

*reverse a string

#include<iostream.h>
#include<stdlib.h>
int main()
{
char str[80];
int i,j;
cout<<"enter any string :";
gets(str);
for(i=0;str[i]!='\0';++i);
char rev[80];
int k;
for(j=i-1,k=0;j>=0;--j,++k)
rev[k]=str[j];
rev[k]='\0';
cout<<"\n String in reverse order is :0 ";
puts(rev);
return 0;
}
*transpose a matrix
#include<iostream.h>
void read(int A[][10],int r,int c)
{
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
cin>>A[i][j];

}
void display(int A[][10],int r,int c)
{
for(int i=0;i<r;i++)
{
cout<<"\n"<<"\n";
for(int j=0;j<c;j++)
cout<<A[i][j]<<"\t";
}
}
void transpose(int A[][10],int B[][10],int r,int c)
{
for(int j=0;j<c;j++)
for(int i=0;i<r;i++)
B[i][j]=A[i][j];
display(B,c,r);
}
void main()
{
int A[10][10],B[10][10],m,n;
cout<<"Enter the eLEMENTS :p ";
cin>>m>>n;
read(A,m,n);
cout<<"\n Matrix is \n ";
display(A,m,n);
transpose(A,B,m,n);

}
*palindrome or not
#include<iostream.h>
Int main()
{
Char string[80],c;
Cout<<enter string;
Cin.getline(string,80);
For(int len=0;string[len]!=\0;len++);
Int I,j,flag=1;
For(i=0,j=len-1;I<len/2;i++,j--)
{
If(string[i]!=string[j])
{
Flag=0;
Break;
}
}
If(flag!=0)
Cout<<palindrome;
Else
Cout<<not;
Return 0;
}

You might also like