64,636
社区成员
发帖
与我相关
我的任务
分享
using namespace std;
or
using std::ifstream;
#include <iostream>
#include <fstream>
using namespace std; // 这里
int main() // c++ 里main需要声明返回类型
{
int matrix[384][3];
char filename[] = "384.txt";
ifstream f("384.txt");
if (f.fail()) // 判断是否打开成功
return 1;
int r,c;
while(f>>r) //读行号
{
f>>c; //读列号
f>>matrix[r][c]; //读权值
}
int i,j,m;
int b[384][384];
for(i=0;i <=383;i++)
{
for(j=0;j <=383;j++)
{
b[i][j]=0;
for(m=0;m <3;m++)
{
b[i][j]=matrix[i][m]*matrix[i][m]+b[i][j];
}
}
}
printf("here is the answer:\n");
for(i=0;i <=383;i++)//所有数组下标都以0开始
{
for(j=0;j <=383;j++)
{
printf("%d ",b[i][j]);
}
printf("\n");
}
f.close(); // 关闭文件
return 0;
}
#include <iostream>
#include <fstream>
using namespace std;