C++,解一元二次方程

 

 

#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&#
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值