Monday, August 11, 2008

back to work..

a. void nestedBlock( int x, int y ) {
int i;
scanf( "%d", &i );
{
int x = 2, j;
scanf( "%d", &j );
printf( "%d %d %d", i, i + j, x + j );
}

printf( "%d %d %d", i * j, i * x, i * y );
}

nestedBlock(10,10);

b. #define SIZE 5;

c. #define Min2(x,y) (((x
int main()
{
int x = 5, y = 7;

int min = Min2(5,7); <--------- (((5<7))? (5) : (7))
}

d. int randNumber = rand();


4) Write statements that assign random integers to the variable n in the following ranges:
a. 1 £ n £ 2 rand() % 2;
b. 1 £ n £ 100 rand() % ...
c. 0 £ n £ 9 rand() % 10;
d. 1000 £ n £ 1112 1000+rand() % 113;
e. –1 £ n £ 1 rand() % .... (missed it)
________________________________


#include
#define SUM(x,y) (x)+(y)

#define PRODUCT(x,y) (x)*(y)

int main()
{
int x=5,y=7;

printf("sum is %d\n", SUM(x,y)); <------------- :sum is 12:

printf("product is %d\n", PRODUCT(x-1,y) <---------- :product is 28:

return 0;
}

1 comment:

Alicia Lai said...

lol...code lagi...@.@