Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

logical operators in C

Name: Roberto Pastrana 2009-04-24 0:12

Hi /prog/
I need to do this exact thing, but only using logical operators

it prints "OP is a faggot" when one of the numbers is negative and the other is 0 or positive
-----------------------------------------
#include <stdio.h>

int main ()

{
    int a;
    int b;

    puts("Ingrese un valor.\n");
    scanf("%d", a)
    puts("Ingrese otro valor.\n");
    scanf("%d", b)

    if (a<0)
    {
        if (b>=0)
        {
            puts "OP is a faggot"
        }
    } else {
        if (b<0)
        {
            puts "OP is a faggot"   
        }
    }
}
-----------------------------------------

Name: Anonymous 2009-04-24 17:45

Simplifying by exhaustive evaluation:

let P = a<0
let Q = b>=0
let X = (P & Q) | !Q

P Q X (P|!Q)
T T T   T
T F T   T
F T F   F
F F T   F[code]

thus

[code]if (a<0 || b<0){
        puts "OP es un homosexual"
    }

Name: Anonymous 2009-04-24 17:48

BBCode failure

P Q X (P|!Q)
T T T   T
T F T   T
F T F   F
F F T   [b][i]T[/i][/b]


thus

if (a<0 || b<0){
        puts "OP es un homosexual"
    }

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List