2011年4月23日 星期六

分享

高中生程式解題系統 a006: 一元二次方程式

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


int main(void) 
{
    
    int a,b,c;
    int sum;

    while(scanf("%d %d %d",&a,&b,&c)!=EOF)
    {
        sum = (b * b) - (4 * a * c);
        if( sum > 0 )
        {
            sum = (int)sqrt(sum);
            printf("Two different roots x1=%d , x2=%d\n", (-b+sum)/(2*a),(-b-sum)/(2*a) );
        }
        else if(sum == 0)
            printf("Two same roots x=%d\n",(-b)/(2*a));
        else 
            printf("No real root\n");
                
    }
    
    return 0;
}

沒有留言:

張貼留言