注册 登录
编程论坛 C++教室

大一C++求教

菜鸟BY 发布于 2013-11-27 08:37, 1046 次点击
描述

求一元二次方程ax^2+bx+c=0的根。

输入

方程的三个系数a、b、c的值。

输出

方程的根。

样例输入

4 1 1
1 2 1
1 1 -2

样例输出

x1=-0.125+0.484i x2=-0.125-0.484i
x1=x2=-1.000
x1=1.000 x2=-2.000

15 回复
#2
菜鸟BY2013-11-27 08:37
描述


输入一些整数,计算它们的和并输出。


输入


输入一些整数。


输出


这些整数的和。


样例输入

1
2
4
6
100

样例输出

113

提示

使用:while (  scanf("%d",&x)==1 )  或者使用:while (  scanf("%d",&x)!=EOF )  读取数据

#3
菜鸟BY2013-11-27 08:38
描述


输入3个整数,从小到大排序后输出。将下面的程序填写完整。

#include <stdio.h>

int main()
{     int a,b,c,t;
      while(scanf("%d%d%d",&a,&b,&c)!=EOF)
      {  ........................................

          ........................................
          printf("%d %d %d\n",a,b,c);  
      }
 return 0;
}


输入


包括多组测试数据,每组输入3个整数。


输出


从小到大排序后的3个整数。


样例输入

1 2 3
5 4 6
7 8 2

样例输出

1 2 3
4 5 6
2 7 8

#4
菜鸟BY2013-11-27 08:38
这3个题目都说下源代码,谢谢拉
#5
blueskiner2013-11-27 08:46
无脑求码?
#6
peach54602013-11-27 08:47
木有源码,只有思路
#7
菜鸟BY2013-11-27 09:08
回复 6楼 peach5460
思路也可以
#8
菜鸟BY2013-11-27 09:09
回复 5楼 blueskiner
.....真的一点都不会,
要不你帮我看下这哪错了

#include "stdio.h"
int gcd(inta,intb);
int lcm(inta,intb);
main()
{
    int a,b,m,n;
    m>1;
    n<1000000000;
while(scanf("%d%d",&a,&b)!=EOF)
{
    m=gcd(a,b);
    n=lcm(a,b);
    printf("%d",m);
    printf(" %d\n",n);
}
    return (0);
}
int gcd(int a,int b)
{
    int t;
    do
    {
        t=a%b;
        a=b;
        b=t;
    }
    while(b!=0);
    return (a);
}
int lcm(int a,int b)
{
    int t;
    t=a*b/gcd(a,b);
    return (t);
}
#9
peach54602013-11-27 11:11
1,解二次方程公式都是现成的,照着搬就是了
2,提示基本上思路已经很清晰了
3,两两比较一下,比较三次,排序不就出来了...

这三个题,思路都很简单
语法问题,自己学习...
不至于懒到手指头也懒得动一下吧...
#10
小王子的花2013-11-27 12:53
你用C???
#11
wu27826418032013-11-27 23:01
VC 6.0
#include <stdio.h>
#include <math.h>
int main()
{
   double a,b,c,disc,x1,x2,p,q;
   scanf("%lf%lf%lf",&a,&b,&c);
   disc=b*b-4*a*c;
   p=-b/(2.0*a);
   q=sqrt(disc)/(2.0/a);
   x1=p+q;x2=p-q;
   printf("x1=%7.2f\nx2=%7.2f\n",x1,x2);
   return 0;


}
#12
wu27826418032013-11-27 23:02
回复 楼主 菜鸟BY
VC 6.0
#include <stdio.h>
#include <math.h>
int main()
{
   double a,b,c,disc,x1,x2,p,q;
   scanf("%lf%lf%lf",&a,&b,&c);
   disc=b*b-4*a*c;
   p=-b/(2.0*a);
   q=sqrt(disc)/(2.0/a);
   x1=p+q;x2=p-q;
   printf("x1=%7.2f\nx2=%7.2f\n",x1,x2);
   return 0;


}
#13
ldj340898502013-11-27 23:26
#14
左手拉一只猫2013-11-29 09:56
有点像ACM入门题,不过输入个数好像是有限的。。。
#15
yuccn2013-11-30 05:53
为观
#16
zhijunlail2013-12-02 11:49
楼主是有多懒啊,数学不是有现成的求解公式吗?照着写就行了
1