当前位置: 代码迷 >> 综合 >> C++,解一元二次方程
  详细解决方案

C++,解一元二次方程

热度:33   发布时间:2024-01-19 15:32:12.0

 

 

#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
void main()
{
const char* filename = "c:/解方程程序结果.txt";
ofstream ofile(filename);
if(!ofile.is_open())
{
std::cerr << "Error opening file";
exit(EXIT_FAILURE);
}
int y;
cout<<"输入Y:";
cin>>y;	
ofile<<"输入y: "<<y<<endl;
int y3 = (int)pow(y,1.0/3.0) +1;
int y2 = (int)pow(y,1.0/2.0) +1;
int a=0,b=0,c=0;
int x,sum;
cout<<"方程 a*x^2 + b*x + c = y 的解是: "<<endl;
ofile<<"方程 a*x^2 + b*x + c = y 的解是: "<<endl;
for(a=1;a<y2;a++){
for(b=0;b<y2;b++){
for(c=0;c<y2;c&#
  相关解决方案