#include<stdio.h> #include<math.h> void solve1(double a,double b,double c) { printf("x1=%.3lf ",-b/(2*a)); printf("x2=%.3lf ",-b/(2*a)); printf("\n"); } void solve2(double a,double b,double c) { printf("x1=%.3lf+%.3lfi ",-b/(2*a),sqrt(4*a*c-b*b)/(2*a)); printf("x2=%.3lf-%.3lfi",-b/(2*a),sqrt(4*a*c-b*b)/(2*a)); printf("\n"); } void solve3(double a,double b,double c) { printf("x1=%.3lf ",(-b+sqrt(b*b-4*a*c))/(2*a)); printf("x2=%.3lf",(-b-sqrt(b*b-4*a*c))/(2*a)); printf("\n"); } int main() { double a,b,c,d; scanf("%lf%lf%lf",&a,&b,&c); d=b*b-4*a*c; if(d==0) solve1(a,b,c); if(d<0) solve2(a,b,c); if(d>0) solve3(a,b,c); return 0; }
0.0分
33 人评分
请大佬帮我看看哪里有问题,老是错。 #include <stdio.h> #include <math.h> int main() { double a,b,c,x1,x2,x; scanf("%lf %lf %lf",&a,&b,&c); x=b*b-4*a*c; if(x>0) { x1=(-b+sqrt(x))/(2*a); x2=(-b-sqrt(x))/(2*a); printf("x1=%.3lf x2=%.3lf",x1,x2); } else if(x==0) { x1=-b/(2*a); x2=x1; printf("x1=%.3lf x2=%.3lf",x1,x2); } else { x=sqrt(-x); printf("x1=%.3lf+%.3lf*i x2=%.3lf-%.3lf*i",-b/(2*a),x/(2*a),-b/(2*a),x/(2*a)); } return 0; }
#include<stdio.h> #include<math.h> main() { double a,b,c,d; scanf("%lf %lf %lf",&a,&b,&c); d=b*b-4*a*c; if(d==0) { printf("x1=%.3lf ",-b/(2*a)); printf("x2=%.3lf\n",-b/(2*a)); } if(d<0) { printf("x1=%.3lf+%.3lfi ",-b/(2*a),sqrt(4*a*c-b*b)/(2*a)); printf("x2=%.3lf-%.3lfi\n",-b/(2*a),sqrt(4*a*c-b*b)/(2*a)); } if(d>0) { printf("x1=%.3lf ",(-b+sqrt(b*b-4*a*c))/(2*a)); printf("x2=%.3lf\n",(-b-sqrt(b*b-4*a*c))/(2*a)); } return 0; }
阿斯嘉德人民 2021-05-12 15:27:46 |
beauty
一个函数调用 #include <stdio.h> #include "math.h" void root(double a,double b,double c); int main() { double a,b,c; scanf("%lf %lf %lf",&a,&b,&c); double r1,r2; root(a,b,c); return 0; } void root(double a,double b,double c) { double r1,r2; double t=b*b-4*a*c; if( t>0 ){ r1=(-b+sqrt(t))/2; r2=(-b-sqrt(t))/2; printf("r1=%.3f,r2=%.3f",r1,r2); }else if( t==0 ){ r1=-b/2; printf("r1=r2=%.3f",r1); }else { printf("r1=%.3f+%.3fi r2=%.3f%.3fi",-b/2,sqrt(-t)/2,-b/2,-sqrt(-t)/2); } }
踏上星辰 2020-07-12 21:25:31 |
妙啊
IP判断 (C语言代码)浏览:992 |
C语言训练-求PI* (C语言代码)(正确结果竟然是谜一样的3.141591)浏览:1338 |
点我有惊喜!你懂得!浏览:1439 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:559 |
C语言训练-斐波纳契数列 (C语言代码)浏览:1271 |
2003年秋浙江省计算机等级考试二级C 编程题(1) (C语言代码)浏览:633 |
C语言程序设计教程(第三版)课后习题8.1 (C语言代码)浏览:573 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:1261 |
WU-格式化数据输出 (C语言代码)浏览:1818 |