c语言,第一题,c++,大一,求图,坐等,不要超纲

大神,打扰一下,c语言,第一题,c++,大一,求图,坐等,不要超纲
最新回答
宅m

2024-08-02 01:07:34

#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    cout<<"a b c的数值:\n";
    float a,b,c;
    cin>>a>>b>>c;
    float deerta=b*b-4*a*c;
    if(deerta<0)
        cout<<"无解";
    else if(deerta==0)
    {
        float x=(-b+sqrt(deerta))/2*a;
        cout<<"一个根:"<<x;
    }
    else
    {
        float x1=(-b+sqrt(deerta))/2*a;
        float x2=(-b-sqrt(deerta))/2*a;
        cout<<"两个根分别是:"<<x1<<"和"<<x2;
    }
    return 0;
}
追问
朋友,超纲了,能发个简单些的么
追答
哥什么地方超纲了?
追问
iostream
cout
追答

忘了 哥 你用的是C语言 我用的是C++

我给你改成C语言的了!

#include <stdio.h>
#include <math.h>

int main()
{
    printf("a b c的数值:\n");
    float a,b,c;
    scanf("%g%g%g",&a,&b,&c);
    float deerta=b*b-4*a*c;
    if(deerta<0)
        printf("无解");
    else if(deerta==0)
    {
        float x=(-b+sqrt(deerta))/2*a;
        printf("一个根 %g",x);
    }
    else
    {
        float x1=(-b+sqrt(deerta))/2*a;
        float x2=(-b-sqrt(deerta))/2*a;
        printf("两个根 %g 和 %g",x1,x2);
    }
    return 0;
}
追问
好,谢谢
若樱落如烟

2024-08-02 05:41:38

明天发给你