📄 complete.c
字号:
#include <stdio.h>
#include <string.h>
int main()
{
int array[20][100];
int n[20],temp[100];
char b[100];
int a=0;
FILE * file;
int i=0, j=0, p=0, q=0, m=0, sum=0, c=0;
char mytemp;
n[0]=0;
file = fopen("D:\\test.txt", "r");
while (!feof(file))
{
if ((mytemp= fgetc(file)) != '\n')
{
ungetc(mytemp,file);
fscanf(file, "%d", &array[i][j]);
j++;
n[i]++;
}
else
{
i++;
j=0;
n[i]=0;
}
}
a=i;
for (j=0; j<=a; j++)
{
for (i=0;i<n[j] ;i++ )
{
printf("%d ", array[j][i]);
printf(" ");
}
printf("\n");
}
fclose(file);
do
{
gets(b);
m=strlen(b);
for (i=0;i<1 ;i++ )
{
if (b[0]=='t'&&b[1]=='e'&&b[2]=='m'&&b[3]=='p'&&b[4]!='=')
{
switch (b[4])
{
case '+':
{
if (b[7]!='\0')
{
p=(b[6]-48)*10+(b[7]-48)-1;
}
else
{
p=b[6]-48-1;
}
if (c==n[p])
{
for (j=0;j<n[p] ;j++ )
{
temp[j]=temp[j]+array[p][j];
}
}
else
{
printf("The dimension of matrix are not the same");
printf("\n");
}
for (j=0;j<n[p] ;j++ )
{
printf("%d",temp[j]);
printf(" ");
}
printf("\n");
}
break;
case '-':
{
if (b[7]!='\0')
{
p=(b[6]-48)*10+b[7]-48-1;
}
else
{
p=b[6]-48-1;
}
if (c==n[p])
{
for (j=0;j<n[p] ;j++ )
{
temp[j]=temp[j]-array[p][j];
}
}
else
{
printf("The dimension of matrix are not the same");
printf("\n");
}
for (j=0;j<n[p] ;j++ )
{
printf("%d",temp[j]);
printf(" ");
}
printf("\n");
}
break;
case '.':
{
if (b[7]!='\0')
{
p=(b[6]-48)*10+b[7]-48-1;
}
else
{
p=b[6]-48-1;
}
if (c==n[p])
{
for (j=0;j<n[p] ;j++ )
{
sum+=temp[j]*array[p][j];
}
printf("sum=%d",sum);
}
else
{
printf("The dimension of matrix are not the same");
printf("\n");
}
printf("\n");
}
break;
}
}
else if (b[0]=='t'&&b[1]=='e'&&b[2]=='m'&&b[3]=='p'&&b[4]=='=')
{
if (b[7]=='+'||'-')
{
q=b[6]-48-1;
switch (b[7])
{
case '+':
{
if (b[10]!='\0')
{
p=(b[9]-48)*10+b[10]-48-1;
}
else
{
p=b[9]-48-1;
}
if (n[q]==n[p])
{
c=n[q];
for (j=0;j<n[q] ;j++ )
{
temp[j]=array[q][j]+array[p][j];
}
}
else
{
printf("The dimension of matrix are not the same");
printf("\n");
}
for (j=0;j<n[q] ;j++ )
{
printf("%d",temp[j]);
printf(" ");
}
printf("\n");
}
break;
case '-':
{
if (b[10]!='\0')
{
p=(b[9]-48)*10+b[10]-48-1;
}
else
{
p=b[9]-48-1;
}
if (n[q]==n[p])
{
c=n[q];
for (j=0;j<n[q] ;j++ )
{
temp[j]=array[q][j]-array[p][j];
}
}
else
{
printf("The dimension of matrix are not the same");
printf("\n");
}
for (j=0;j<n[q] ;j++ )
{
printf("%d",temp[j]);
printf(" ");
}
printf("\n");
}
break;
}
}
else if (b[7]=='0'||'1'||'2'||'3'||'4'||'5'||'6'||'7'||'8'||'9')
{
q=(b[6]-48)*10+b[7]-48-1;
switch (b[8])
{
case '+':
{
if (b[11]!='\0')
{
p=(b[10]-48)*10+b[11]-48-1;
}
else
{
p=b[10]-48-1;
}
if (n[q]==n[p])
{
c=n[q];
for (j=0;j<n[q] ;j++ )
{
temp[j]=array[q][j]+array[p][j];
}
}
else
{
printf("The dimension of matrix are not the same");
printf("\n");
}
for (j=0;j<n[q] ;j++ )
{
printf("%d",temp[j]);
printf(" ");
}
printf("\n");
}
break;
case '-':
{
if (b[11]!='\0')
{
p=(b[10]-48)*10+b[11]-48-1;
}
else
{
p=b[10]-48-1;
}
if (n[q]==n[p])
{
c=n[q];
for (j=0;j<n[q] ;j++ )
{
temp[j]=array[q][j]-array[p][j];
}
}
else
{
printf("The dimension of matrix are not the same");
printf("\n");
}
for (j=0;j<n[q] ;j++ )
{
printf("%d",temp[j]);
printf(" ");
}
printf("\n");
}
break;
default:
{
printf("Error");
printf("\n");
break;
}
}
}
else
{
printf("Error");
printf("\n");
}
}
else if (b[0]=='q')
{
printf("Byebye!");
printf("\n");
}
else
{
printf("Error");
printf("\n");
}
}
}
while (b[0]!='q');
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -