How to find the sign of a variable in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>

int main() {
    int n = -893;
    int sign;   

    sign = -(n < 0);  // if v < 0 then -1, else 0. 
    
    printf("%d\n", sign);
    
    return 0;
}



/*
run:

-1

*/

 



answered Jul 24, 2025 by avibootz

Related questions

2 answers 269 views
1 answer 267 views
2 answers 129 views
1 answer 227 views
2 answers 686 views
...