y = { − 1 ( x < 0 ) 0 ( x = 0 ) 1 ( x > 0 ) y = {−1 (x<0)0 (x=0)1 (x>0) y=⎩ ⎨ ⎧−1 (x<0)0 (x=0)1 (x>0)
#include
#include
#define FORMAT "%d"
typedef int Type;
int main(){
Type x;
int y;
printf("Enter X Value: ");
scanf_s(FORMAT, &x);
if(x < 0){
y = -1;
}
else if(x == 0){
y = 0;
}
else{
y = 1;
}
printf("Y Value = ");
printf(FORMAT, y);
printf("\n");
system("pause");
return 0;
}
#include
#include
#define FORMAT "%d"
typedef int Type;
void input(Type *x){
printf("Enter X Value: ");
scanf_s(FORMAT, x);
}
void output(Type *x){
int y = *x > 0 ? 1 : (*x == 0 ? 0 : -1);
printf("Y Value = ");
printf(FORMAT, y);
printf("\n");
}
int main(){
Type *x = (Type*)malloc(sizeof(Type));
input(x);
output(x);
free(x);
system("pause");
return 0;
}