새로새록

[c++]4. 10*10 행렬 본문

소프트웨어융합/경희대 c++ 과제

[c++]4. 10*10 행렬

류지나 2020. 7. 14. 23:57

0~100 사이의 정수를 랜덤하게 10x10 행렬로 만들고 txt파일을 생성해 그 결과를 확인할 수
있는 프로그램을 작성하라.

#include <iostream>
#include <fstream>
using namespace std;
int main()
{
	ofstream ofs;
	ofs.open("temp.txt");
	int num;
	for (int i = 0; i < 100; i++)
	{
		num = rand() % 101;
		ofs << num << " ";
		if (i % 10 == 9)
			ofs << endl;
	}
	ofs.close();
	return 0;
}