c语言的编程

1.有3个数a,b,c,要求按大小顺序将它们输出。
2.求方程ax+bx+c=0的根。分别考虑:1).有两个不等的实根;2).有两个相等的实根。
用C语言写出来

#include <stdio.h>
#include <conio.h>
void main()
{
int a,b,c,temp=0;
printf("Please input 3 int:");
scanf("%d%d%d",&a,&b,&c);
if(a<b)
temp=a,a=b,b=temp;
if(a<c)
temp=a,a=c,c=temp;
if(b<c)
temp=b,b=c,c=temp;
printf("\n\n%d>=%d>=%d",a,b,c);
getch();
}
【2】
#include <stdio.h>
#include <conio.h>
#include<stdlib.h>
void main()
{
double a,b,c,x=1;re:
printf("Please input a b c:");
scanf("%lf%lf%lf",&a,&b,&c);
if(!a)goto re;
if((b*b)<(4*a*c))
{printf("方程无实数根!");getch();exit(0);}
if ((b*b)==(4*a*c))
{printf("\n\nx1=x2=%.3lf",-b/a/2);getch();exit(0);}
if(b*b-4*a*c>0)
while((a*x*x+b*x+c)/(2*a*x+b)>=1e-8
||(a*x*x+b*x+c)/(2*a*x+b)<=-1e-8)
x-=(a*x*x+b*x+c)/(2*a*x+b);
printf("\n\nx1=%.3lf\tx2=%.3lf",x,c/a/x);
getch();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-03-19
1
#include<stdio.h>
main()
{
int x,y,z,t;
scanf("%d%d%d",&x,&y,&z);
if (x>y)
{t=x;x=y;y=t;} /*交换x,y的值*/
if(x>z)
{t=z;z=x;x=t;}/*交换x,z的值*/
if(y>z)
{t=y;y=z;z=t;}/*交换z,y的值*/
printf("big to small: %d %d %d\n",z,y,x);
}
2,
#include<stdio.h>
#include<math.h>
void main()
{
float a,b,c,d,x1,x2;
printf("请输入a,b,c的值并用逗号隔开:\n");
scanf("%f,%f,%f",&a,&b,&c);
if(a==0)
{ printf("请重新输入a,b,c的值并用逗号隔开:\n");
scanf("%f,%f,%f",&a,&b,&c);
}
d=b*b-4*a*c;
if(d>0)
{
printf("方程有二个不等实数根:");
printf("x1=%f,x2=%f",(-b+sqrt(d))/(2*a),(-b-sqrt(d))/(2*a));
}
if(d==0)
{
printf("方程有二个相等实数根:");
printf("x1=x2=%f",(-b)/(2*a));
}
if(d<0)
printf("方程没有实数根:");
}
相似回答