Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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