C


C programming

C programming.

Function

int main(void)

/* add your value() based on this code */ #include

int main () { int type, width, height, length; scanf ( “%d%d%d%d”, &type, &width, &height, &length ); printf ( “%d”, value ( type, width, height, length ) ); return 0; }

formal parameter

void function( int x)

actual parameter test(3+7);

I/O

scanf( “%d%f%lf”, &int, &float, &double );

n = scanf( “%d/%f/%lf”, &i, &f, &df ); n is number of data read in.

printf(“%d %p %f %f \n”, int, addr,float, double);

printf(“int %d adr %p flt %f dbl %f \n”, i, addr,f, d);

Control

logic ? value1 : value2

return 0;

Control flow

switch n

case {1,2,3}: statement;

default:

###

#include

int gcd ( int a, int b ) { if ( a < b ) return gcd ( b, a );

if ( b == 0 )
	return a;
else
	return gcd ( b, a % b ); }

int value ( int type, int width, int height, int length ) { int u_val;

switch ( type ) {
	case 79:
		u_val = 30;
		break;
	case 47:
		u_val = 10;
		break;
	case 29:
		u_val = 4;
		break;
	case 82:
		u_val = 5;
		break;
	case 26:
		u_val = 3;
		break;
	case 22:
		u_val = 9;
		break;
	default :
		return -1;
}

if ( width <= 0 || height <= 0 || length <= 0 )
	return -2;

int s = gcd ( gcd ( width, height ), gcd ( height, length ) );
int v = s * s * s;
int count = ( width / s ) * ( height / s ) * ( length / s );

return v * v * count * u_val; }