It seems you mean the following
int number;
char *sum;
printf("enter your number ");
scanf("%d",&number);
sum = (number > 0)? "positive" : "negative";
printf("your number is %s\n", sum);
That is the variable number should have the type int
instead of char
. Otherwise this call
scanf("%d",&number);
can invoke undefined behavior.
The variable sum
should have the type char *
instead of char
because it is initialized by a string literal.
Pay attention to that if number
is not greater than 0 it does not mean that it is a negative number. It can be equal to 0.:)
So this statement
sum = (number > 0)? "positive" : "negative";
has a logical error. You could write at least like
sum = (number > 0)? "positive" : "non-positive";
or use a more compound expression something like
sum = (number > 0) ? "positive" : ( number == 0 ? "zero" : "negative" );