//bool.c
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
char* bool_to_str ( _Bool ) ;
_Bool str_to_bool ( const char* ) ;
int main(){
///variables
_Bool b0,b1 ;
b0 = true ;
b1 = false ;
/**
* Cuerpo
**/
printf ( " A N D n " ) ;
printf( "%d & %d = %d n" , b0 ,b1, b0 & b1 ) ;
printf( "%s & %s = %s n" , bool_to_str( b0 ) , bool_to_str( b1 ) , bool_to_str( b0 & b1 ) ) ;
printf("%d & %d = %d n" , str_to_bool( bool_to_str( b0 ) ) , str_to_bool(bool_to_str( b1 ) ) , str_to_bool( bool_to_str( b0 & b1 ) ) ) ;
printf ( "ORn" ) ;
printf ( "%d | %d = %d n" , b0 , b1 , b0 | b1 ) ;
printf ( "%s | %s = %s n" , bool_to_str( b0 ) , bool_to_str( b1 ) , bool_to_str ( b0 | b1 ) ) ;
printf ( "%d | %d = %d n" , str_to_bool( bool_to_str ( b0 ) ) , str_to_bool ( bool_to_str ( b1 ) ), str_to_bool( bool_to_str( b0 | b1 ) ) ) ;
printf ( "NOTn" ) ;
printf ( "!%d = %d n" , b0 , !b0 ) ;
printf ( "!%s = %s n" , bool_to_str( b0 ) , bool_to_str( !b0 ) ) ;
printf ( "!%d = %d n" , str_to_bool( bool_to_str ( b0 ) ) , str_to_bool ( bool_to_str( !b0 ) ) ) ;
return 0 ;
}
/*Funciones*/
char* bool_to_str( _Bool b )
{
if( b == false ) return "false" ;
return "true" ;
}
_Bool str_to_bool( const char *b )
{
if ( !strcmp ( b , "true" ) ) return true ;
return false;
}
//build
$ cc -o bool bool.c
//run
$ ./bool
//output
AND
1 & 0 = 0
true & false = false
1 & 0 = 0
OR
1 | 0 = 1
true | false = true
1 | 0 = 1
NOT
!1 = 0
!true = false
!1 = 0
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
char* bool_to_str ( _Bool ) ;
_Bool str_to_bool ( const char* ) ;
int main(){
///variables
_Bool b0,b1 ;
b0 = true ;
b1 = false ;
/**
* Cuerpo
**/
printf ( " A N D n " ) ;
printf( "%d & %d = %d n" , b0 ,b1, b0 & b1 ) ;
printf( "%s & %s = %s n" , bool_to_str( b0 ) , bool_to_str( b1 ) , bool_to_str( b0 & b1 ) ) ;
printf("%d & %d = %d n" , str_to_bool( bool_to_str( b0 ) ) , str_to_bool(bool_to_str( b1 ) ) , str_to_bool( bool_to_str( b0 & b1 ) ) ) ;
printf ( "ORn" ) ;
printf ( "%d | %d = %d n" , b0 , b1 , b0 | b1 ) ;
printf ( "%s | %s = %s n" , bool_to_str( b0 ) , bool_to_str( b1 ) , bool_to_str ( b0 | b1 ) ) ;
printf ( "%d | %d = %d n" , str_to_bool( bool_to_str ( b0 ) ) , str_to_bool ( bool_to_str ( b1 ) ), str_to_bool( bool_to_str( b0 | b1 ) ) ) ;
printf ( "NOTn" ) ;
printf ( "!%d = %d n" , b0 , !b0 ) ;
printf ( "!%s = %s n" , bool_to_str( b0 ) , bool_to_str( !b0 ) ) ;
printf ( "!%d = %d n" , str_to_bool( bool_to_str ( b0 ) ) , str_to_bool ( bool_to_str( !b0 ) ) ) ;
return 0 ;
}
/*Funciones*/
char* bool_to_str( _Bool b )
{
if( b == false ) return "false" ;
return "true" ;
}
_Bool str_to_bool( const char *b )
{
if ( !strcmp ( b , "true" ) ) return true ;
return false;
}
//build
$ cc -o bool bool.c
//run
$ ./bool
//output
AND
1 & 0 = 0
true & false = false
1 & 0 = 0
OR
1 | 0 = 1
true | false = true
1 | 0 = 1
NOT
!1 = 0
!true = false
!1 = 0