一元二次方程求根程序_C程序寻找二次方程的根

这篇博客介绍了一个C程序,用于计算二次方程ax^2+bx+c=0的根。当输入值为1,1,1时,程序显示根为复数且为-0.50±0.87i。" 84998234,7343800,实用工具分享:提高效率的神器集合,"['工具分享', '工作效率', '笔记应用', '团队协作', '文件管理']
摘要由CSDN通过智能技术生成

一元二次方程求根程序

Here you will get C program to find roots of quadratic equation ax2+bx+c=0

在这里,您将获得C程序来查找二次方程的根ax2 + bx + c = 0

#include<stdio.h>
#include<math.h>
 
int main()
{
	float root1,root2,a,b,c,d,imaginaryPart,realPart;
	printf("Quadratic Equation is ax^2+bx+c=0");
	printf("\nEnter values of a,b and c:");
	scanf("%f%f%f",&a,&b,&c);
	
	d=(b*b)-(4*a*c);
	if(d>0)
	{
		printf("\nTwo real and distinct roots");
		root1=(-b+sqrt(d))/(2*a);
		root2=(-b-sqrt(d))/(2*a);
		printf("\nRoots are %f and %f",root1,root2);
	}
	else
		if(d==0)
		{
			printf("\nTwo real and equal roots");
			root1=root2=-b/(2*a);
			printf("\nRoots are %f and %f",root1,root2);
		}
		else{
			printf("\nRoots are complex and imaginary");
			realPart = -b/(2*a);
	        imaginaryPart = sqrt(-d)/(2*a);
    	    printf("\nRoots are %.2f+%.2fi and %.2f-%.2fi", realPart, imaginaryPart, realPart, imaginaryPart);
    	}
 
	return 0;			
}

Output

输出量

Quadratic Equation is ax^2+bx+c=0 Enter values of a,b and c:1 1 1

二次方程为ax ^ 2 + bx + c = 0 输入a,b和c的值:1 1 1

Roots are complex and imaginary Roots are -0.50+0.87i and -0.50-0.87i

根是复杂的,假想的 根是-0.50 + 0.87i和-0.50-0.87i

翻译自: https://www.thecrazyprogrammer.com/2013/05/c-program-to-calculate-roots-of-2.html

一元二次方程求根程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值