SLGLS5357


私信TA

用户名:SLGLS5357

访问量:6870

签 名:

真的C

等  级
排  名 4308
经  验 1649
参赛次数 0
文章发表 2
年  龄 0
在职情况 学生
学  校 江西电力职业技术学院
专  业 物联网

  自我简介:

 

0.0分

53 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

?你函数呢?
2023-12-30 17:46:27
#include<stdio.h>
#include<math.h>
#define EPS 1e-6
void Num(float a,float b,float c);
int main()
{
	float a,b,c;
	scanf("%f%f%f",&a,&b,&c);
	Num(a,b,c);
	return 0;
}
//计算一元二次方程的根 
void Num(float a,float b,float c)
{
	float disc,p,q;     //disc为判别式
	disc=b*b-4*a*c;
	p=-b/(2*a);
	q=sqrt(fabs(disc))/(2*a);
	if(fabs(disc)<=EPS)      //判别式等于0,输出两个相等的实根
	{
		printf("x1=%.3f x2=%.3f",p,p);
	 } 
	else
	{
		if(disc>EPS)    //判别式大于0 
		{
			printf("x1=%.3f x2=%.3f",p+q,p-q);
		}
		else           //判别式小于0 
		{
			printf("x1=%.3f+%.3fi x2=%.3f-%.3fi",p,q,p,q);
		}
	}
}
2023-11-30 13:42:34
#include <stdio.h>
#include <math.h>
double x1, x2;
void function(double a, double b, double c) {
	double data = b * b - 4 * a * c;
	if (data >= 0) {
		x1 = (-b + sqrt(data)) / 2 * a;
		x2 = (-b - sqrt(data)) / 2 * a;
		printf("x1=%.3lf x2=%.3lf", x1, x2);
	} else {
		printf("x1=%.3lf+%.3lfi ", -b / (2 * a), sqrt(-data) / (2 * a));
		printf("x2=%.3lf-%.3lfi", -b / (2 * a), sqrt(-data) / (2 * a));
	}
}
int main() {
	double a, b, c;
	scanf("%lf%lf%lf", &a, &b, &c);
	function(a, b, c);
	return 0;
}
2023-11-28 15:08:05
#include <stdio.h>
#include <math.h>
void save1(int a);
void save2(int m,int n,int a,int b,int c);
void save3(int m,int n,int a,int b,int c);
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    float m,n,k;
    m=b*b;
    n=4*a*c;
    if((m-n)<0) save1(a);
    else
	{
    	if((m-n)==0) save2(m,n,a,b,c);
    	else
    	{
    		save3(m,n,a,b,c);
    	}
    }
    return 0;
}

void save1(int a)
{
	printf("无解"); 
}

void save2(int m,int n,int a,int b,int c)
{
	float x1,x2,p,q;
	p=-b/2*a;
	q=sqrt(m-n)/2*a;
	x1=x2=p+q;
	printf("x1=x2=%f",x1);
}

void save3(int m,int n,int a,int b,int c)
{
2023-11-23 18:09:02
审题有误,没有调用自定义函数
2023-03-11 14:52:35
题解错误 是(2*a)不是2*a
2023-02-14 21:13:02
#include <stdio.h>
#include<math.h>
int main(void)
{
	double a = 0.0, b = 0.0, c = 0.0;
	scanf("%lf %lf %lf", &a, &b, &c);
	double tel = pow(b, 2) - 4 * a * c;
	double x1 = 0.0, x2 = 0.0;
	if (tel > 0)
	{
		x1 = (-b + sqrt(tel)) / (2 * a);
		x2= (-b - sqrt(tel)) / (2 * a);
		printf("x1=%.3lf x2=%.3lf\n", x1, x2);
	}
	else if (tel == 0)
	{
		x1 =( - b )/ (2 * a);
		x2=  ( - b) / (2 * a);
		printf("x1=%.3lf x2=%.3lf\n", x1, x2);

	}
	else
	{
		double m, n;
		m= -b / (2 * a);
		n = sqrt(-tel) / (2 * a);
		printf("x1=%.3lf+%.3lfi x2=%.3lf+%.3lfi\n", m, n, m, n);
	}
	


	return 0;
}
2022-09-27 18:47:17
没有用三个函数,想学习模块化编程的思路啊
2022-08-13 22:59:51
  • «
  • 1
  • »