将列的总和添加为字符串类型矩阵的最后一行。第一行也是标题

时间:2016-06-01 16:15:19

标签: c++

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
  int i,j,k,grand1;
  char s1;
  char a[5][5][20];/*a 3x3 matrix of string data type*/
  clrscr();
  for(i=0;i<5;i++)
  {
    for(j=0;j<5;j++)
    {
      cout<<"enter value in ("<<i<<","<<j<<" )cell of first sheet ";
      gets(a[i][j]);
    }
  }
  /*value enter in the first matrix*/
  cout<<endl;

  /*display table1*/
  for(i=0;i<5;i++)
  {
    for(j=0;j<5;j++)
    {
      cout<<a[i][j]<<"\t";
    }
    cout<<endl;
  }


  strcpy(a[5][1],"SUM");
  for(i=1;i<5;i++)
  {
    s1=0;
    for(k=0;k<4;k++)
    {
      s1=s1+int(a[i][k]); /*here it shows Lvalue error*/
    }
    a[5][i]=int(s1);
  }


  for(i=1;i<5;i++)
  {
    grand1=grand1+int(a[5][i]);
  }
  cout<<"grand sum of table1"<<grand1<<endl;
  /*here the table1 terminates*/

  getche();
}

代码已经完成.....并且错误仍然存​​在请求帮助。如果只是我将错误的行作为注释,那么代码也会被编译并运行。即其余的代码都没问题。错误仅在最后一行中持续存在。此外,由于第一行用于标题和休息,所有行包含除第一列以外的数值...所以我需要最后4行的库仑总和作为矩阵的元素。(最后一行)。

0 个答案:

没有答案