c program please correct the below code

c program please correct the below code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  #include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],m,n,m1,n1;
int i,j,k,ch;
clrscr();
printf("Enter The Order of Matrix A : ");
scanf("%d%d",&m,&n);
printf("Enter The Values for Matrix A:\n");
for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\nEnter The Order of Matrix B : ");
scanf("%d%d",&m1,&n1);
printf("\nEnter The Values for Matrix B.");
for(i=0;i<=m1;i++)
{
for(j=0;j<=n1;j++)
{
scanf("%d",&b[i][j]);
}
}
while(1)
{
printf("\nt\Matrix Manipulation");
printf("\n\t\t-------------------------\n");
printf("\n1.matrix addition");
printf("\n2.matrix substraction");
printf("\n3.matrix multiplication");
printf("\n4.matrix transpose");
printf("\n5.exit\n");
printf("Enter your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
if((m==m1)&&(n==n1))
{
printf("\nSum of the given Two Matrixes is:\n");
for(i=0;i<=m1;i++)
{
for(j=0;j<=n1;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%d ",c[i][j]);
}
printf("\n");
}
}
else
printf("Addition is Not Possible");
break;
case 2:
if((m==m1)&&(n==n1))
{
printf("\n Difference Of the given Two Matrices is:\n");
for(i=0;i<=m1;i++)
{
for(j=0;j<=n1;j++)
{
c[i][j]=a[i][j]-b[i][j];
printf("%d ",c[i][j]);
}
printf("\n");
}
}
else
printf("Subtraction is Not Possible");
break;
case 3:
if(m1==n)
{
for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
c[i][j]=0;
for(k=0;k<=n;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
printf("\n The Product of the given Matrix is:\n");
for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
printf("\t%d ",c[i][j]);
}
printf("\n");
}
}
else
printf("\n The product is Not Possible");
break;
case 4:
for(i=0;j<n;i++)
{
for(j=0;j<m;j++)
{
c[i][j]=a[j][i];
} }
printf("The transpose of the given Matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
printf("%d \t ",c[i][j]);
printf("\n");
}
break;
case 5:
exit(0);
break;
}
getch();
}
}
Last edited on
Have you looked at the errors your compiler is reporting and tried to fix those errors?

Line 30: \M is not a valid escape sequence. Did you mean \tM ?

Lines 32-36: Missing opening "

Line 116: exit() requires the <stdlib.h> header

Line 2: <conio.h> is not a standards compliant header. You should avoid it.

p.s. Try using some reasonable indentation to make your program more readable.
Last edited on
There are many syntax errors in this code. Especially in the printf lines (where it seems that you forgot to close the quotation marks). Correct them first, and then we can help you with the logic errors.
printf lines corrected.
Last edited on
Line 30 is still not correct. See my previous comment.
Mentors
I dont know to correct. If I knew, I myself would have done that. Please do correct my mistakes. I had struggled with this program for more than 6 hours :(
printf("\nt\Matrix Manipulation");

this is not correct.
you need

printf("\n\tMatrix Manipulation");

if your desire was to have end of line followed by tab.
\n is end of line
\t is tab
\\ is \
\" is "
and you don't see most of the rest of these -- they exist to either print unprintable characters or to insert things that are part of the c syntax (such as " as a character to print) which otherwise would confuse the compiler ("stuff"otherstuff"" is no good, you need "stuff\"otherstuff\"") .


\M isn't anything at all.

Topic archived. No new replies allowed.