xyx
#include
#include
#include
#include void main()
{
int m1[30][30],m2[30][30],m3[30][30]={0};
int i,j,x,k,r1,r2,c1,c2,n,ch,sum=0;
char wish,y;
clrscr();
printf(“enter no of row for 1st matrix”);
scanf(“%d”,&r1);
printf(“enter no of col for 1st matrix”);
scanf(“%d”,&c1);
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
{
printf(“\n\t\t enter a[%d][%d]:”,i,j);
scanf(“%d”,&m1[i][j]);
}
printf(“enter no of row for 2nd matrix”);
scanf(“%d”,&r2);
printf(“enter no of col for 2nd matrix”);
scanf(“%d”,&c2);
for(i=0;i<r2;i++)
for(j=0;j<c2;j++)
{
printf(“\n\t\t enter a[%d][%d]:”,i,j);
scanf(“%d”,&m2[i][j]);
}
menu:
printf(“\n for sum of matrix press 1”);
printf(“\n for mutiplication of matrix press 2”);
printf(“\n for transpose of 1st matrix press 3”);
printf(“\n for cheaking symatericness of 1st matrix press 4”);
printf(“\n for cheaking sqew symatry matrix press 5\n”);
scanf(“%d”,&ch);
switch(ch)
{
case 1://addition
if((r1==r2)&&(c1==c2))
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
m3[i][j]=m1[i][j]+m2[i][j];
}
else
{
exit(0);
}
for(i=0;i<r1;i++)
{
printf(“\n”);
for(j=0;j<c1;j++)
printf(“\t\t%d”,m3[i][j]);
}
break;
case 2://multiplication
sum=0;
if(c1==r2)
{
for(i=0;i<r1;i++)
{
printf(“\n”);
for(j=0;j<c2;j++)
{
for(k=0;k<c1;k++)
{
sum+=(m1[i][k]*m2[k][j]);
}
printf(“\t\t%d”,sum);
sum=0;
}
}
}
else
exit(0);
break;
case 3:
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
m3[j][i]=m1[i][j] ;
}
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
printf(“\t\t%d”,m3[i][j]);
}
printf(“\n”);
}
break;
case 4:
/*int flag=0;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
m3[j][i]=m1[i][j];
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
if(m3[i][j]==m1[i][j])
flag++;
}
}
if(flag==r1*c1)
printf(” 1st matrix is symatric”);
else
printf(” 1st matrix is not symatric”);*/
int flag=1;
for(i=0;i<r1;i++)
{
for(j=i+1;j<c1;j++)
{
if(m1[i][j]!=m1[j][i])
{
flag=0;
}
}
}
if(flag==1)
printf(” 1st matrix is symatric”);
else
printf(” 1st matrix is not symatric”);
break;
case 5://skew symatric
int fl=0;
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
m3[j][i]=m1[i][j];
}
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
if(m3[i][j]==-m1[i][j])
fl++;
}
}
if(fl==r1*c1)
printf(” 1st matrix is skew symatric”);
else
printf(” 1st matrix is not skew symatric”);
}
getch();
}//prg terminates
if(str[i]!=str[j])
{
flag=0;
break;
}
}
if(flag==1)
printf(“\nthe string is palindrom.”);
else
printf(“\nthe string is not palindrom.”);
break;
case 6:
printf(“Enter the string: “);
flushall();
gets(str);
printf(“\nEnter the second string: “); //TO FIND WETHER SUBSTRING EXISTS OR NOT
gets(str4);
for(m=0;str[m]!=’\0′;m++);
for(k=0;k<=m-1;k++)
{
for(j=0;str4[j]!=’\0′;j++)
{
if(str[k+j]!=str4[j])
{
flag=0;
break;
}
}
if(str4[j]==’\0′)
{
flag=1;break;}
}
if(flag==1)
printf(“\nsubstring found at position:%d “,j+k);
else
printf(“\n substring donot exists”);
break;
default:
printf(“\n wrong choice!!!!”);
break;
}
printf(“\nwant to continue(y/n)”);
scanf(“%c”,&wish);
}
while(wish!=’n’);
getch();
}
{
printf(” %d”,set3[k]);
}
break;
case 2: //for intersection
printf(“enter the size of sets1”);
scanf(“%d”,&n1);
printf(“enter the element of set1”);
for(i=0;i<n1;i++)
scanf(“%d”,&set1[i]);
printf(“enter the size of sets2”);
scanf(“%d”,&n2);
printf(“enter the elements of set2”);
for(i=0;i<n2;i++)
scanf(“%d”,&set2[i]);
k=0;
for(i=0;i<n2;i++)
{
flag=1;
for(j=0;j<n1;j++)
{
if(set2[i]==set1[j])
{
flag=0;
break;
}
}
if(flag==0)
{
set3[k]=set2[i];
k++;
}
}
p=k;
for(k=0;k <p;k++)
{
printf(” %d”,set3[k]);
}
break;
case 3://for subtraction
printf(“enter the size of sets1”);
scanf(“%d”,&n1);
printf(“enter the element of set1”);
for(i=0;i<n1;i++)
scanf(“%d”,&set1[i]);
printf(“enter the size of sets2”);
scanf(“%d”,&n2);
printf(“enter the elements of set2”);
for(i=0;i<n2;i++)
scanf(“%d”,&set2[i]);
k=0;
for(i=0;i<n1;i++)
{
flag=1;
for(j=0;j<n2;j++)
{
if(set1[i]==set2[j])
{
flag=0;
break;
}
}
if(flag==1)
{
set3[k]=set1[i];
k++;
}
}
p=k;
for(k=0;k <p;k++)
{
printf(” %d”,set3[k]);
}
break;
}
printf(“\n want to continue: “);
flushall();
scanf(“%c”,&wish);
}
while(wish!=’n’);
} //prg terminates