一个指针要同时接受三个变量,求指教!打印出来如下图.We know that theroots of a quadratic equation of the formax2 + bx + c = 0 are given by the following equations: x1 = ( -b + square – root ( b2 – 4ac ) )/ 2a ;

来源:学生作业帮助网 编辑:作业帮 时间:2024/08/09 06:06:04
一个指针要同时接受三个变量,求指教!打印出来如下图.We know that theroots of a quadratic equation of the formax2 + bx + c = 0   are given by the following equations:         x1 = ( -b + square – root ( b2 – 4ac ) )/ 2a ;
xV[oG+SP";q3{c UC_PyHQ5Y8kEUM"UT/U"PEgo1#җ;9ٕީ+{O7W7(ݹ{]ҝowgה/ Io=M~ƽt<QIT49"?<DFgT 7f>~~̛&"=P!C< |Pu4h\ffu2E)4y4 fSu>P]? ѥ,9 a)r R B^+WR X@}_ߠ_'@N54;~#7)ydWs">mA8>q b-lDmbR9]a2IaM1]qSda=bWw3{۫W rI?dA i e3)6vI2w-P(XX ryX=sCjW|sz ج$r&g=@G+9=곸X'{"īoe:=^sr+bcź\&cjɘ2GE8[ZzqNVnᠢ`0Ãa,{?` (.ְRd4/"hJǙEkot^JzGi0D^EycЀc!8G7V㲯槾~Tk\Ѥb8tm bC)NO j8xmw֦{bDFxpk'9ǎfMP~PQ=柠=}

一个指针要同时接受三个变量,求指教!打印出来如下图.We know that theroots of a quadratic equation of the formax2 + bx + c = 0 are given by the following equations: x1 = ( -b + square – root ( b2 – 4ac ) )/ 2a ;
一个指针要同时接受三个变量,求指教!打印出来如下图.
We know that theroots of a quadratic equation of the form
ax2 + bx + c = 0   are given by the following equations:
         x1 = ( -b + square – root ( b2 – 4ac ) )/ 2a ;
         x2 = ( -b - square – root ( b2 – 4ac ) )/ 2a ;
Write a function to calculate the roots.The functionmust use two pointer parameters,one to receive the coefficients a,b,and c,and the other to send the roots to the calling function.(Hint:function namesimilary to void answer(int *c,float *root))





一个指针要同时接受三个变量,求指教!打印出来如下图.We know that theroots of a quadratic equation of the formax2 + bx + c = 0 are given by the following equations: x1 = ( -b + square – root ( b2 – 4ac ) )/ 2a ;

你忘了一句话”数组即指针”.

只要把指针指向一个数组,就OK了.

代码如下.

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

void answer(int* c, float* root)
{
    char ch = 'A';
    int k = 0;
    float fTemp;
    for (ch = 'A'; ch < 'D'; ch++)
    {
        printf("Enter the Value of %c : ", ch);
        scanf("%d", &c[ch - 'A']);
    }

    k = c[1] * c[1] - 4 * c[0] * c[2];
    if (k < 0)
    {
        printf("the root is not possible.\n");
    }
    else if (k == 0)
    {
        root[0] = root[1] = (-c[1]) / (2 * c[0]);
        printf("the root is %.2f\n", root[0]);
    }
    else
    {
        fTemp = sqrt((double)k);
        root[0] = (-c[1] + fTemp) / (2 * c[0]);
        root[1] = (-c[1] - fTemp) / (2 * c[0]);
        printf("the roots are %.2f and %.2f\n", root[0], root[1]);
    }
}

void main()
{
    int factor[3] = {0};
    float root[2] = {0};
    answer(factor, root);
}