[ create a new paste ] login | about

Link: http://codepad.org/rSb0ZGDD    [ raw code | output | fork ]

C, pasted on Dec 6:
#include <stdio.h>

float F(float a, float b, float c, float x);

int main(){
    float xn = -1.0f;
    float xk = 2.3f;
    float dx = 0.1f;
    float x  = 0.0f;
    float y =  0.0f;
    float a = 3.0f;
    float b = -0.3f;
    float c = 1.5f;
    int  Ac = (int)a;
    int  Bc = (int)b;
    int  Cc = (int)c;
    int flag= (Ac ^ Bc % 2) & ~(Ac | Cc);
	xk = xk + dx;
    for( x = xn; x < xk; x = x + dx )
    {
        
        if( flag )
        {
            y = F(a, b, c, x);
        }
        else
        {
            y = F(Ac, Bc, Cc, x);
        }
        printf("x = %.3f\ty = %.3f\n", x, y);
    }
    return 0;
}

float F(float a, float b, float c, float x){
    float y = 0.0f;
    if( x )
        y = a + x / c;
    else
    if( b )
        y = a*(x + c)*(x + c) - b;
    else
        y = (x - a) / -c;
    return y; 
}


Output:
x = -1.000	y = 2.000
x = -0.900	y = 2.100
x = -0.800	y = 2.200
x = -0.700	y = 2.300
x = -0.600	y = 2.400
x = -0.500	y = 2.500
x = -0.400	y = 2.600
x = -0.300	y = 2.700
x = -0.200	y = 2.800
x = -0.100	y = 2.900
x = 0.000	y = 3.000
x = 0.100	y = 3.100
x = 0.200	y = 3.200
x = 0.300	y = 3.300
x = 0.400	y = 3.400
x = 0.500	y = 3.500
x = 0.600	y = 3.600
x = 0.700	y = 3.700
x = 0.800	y = 3.800
x = 0.900	y = 3.900
x = 1.000	y = 4.000
x = 1.100	y = 4.100
x = 1.200	y = 4.200
x = 1.300	y = 4.300
x = 1.400	y = 4.400
x = 1.500	y = 4.500
x = 1.600	y = 4.600
x = 1.700	y = 4.700
x = 1.800	y = 4.800
x = 1.900	y = 4.900
x = 2.000	y = 5.000
x = 2.100	y = 5.100
x = 2.200	y = 5.200
x = 2.300	y = 5.300


Create a new paste based on this one


Comments: