Thread: if

  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    30

    if

    Code:
     int input;
     scanf("%d",&input);
     if(3%2) // I don't know what this means
     printf("A");
     if(2%2) // I don't know what this means
     printf("B");
    thanks

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    45
    the "%" operator is called the "modulus operator".it gives the remainder after dividing two numbers..
    example ---> 3%2 == 1 ( since remainder is 1)

  3. #3
    Registered User
    Join Date
    Sep 2011
    Posts
    30
    if(3%2) // Is it equal to if(TRUE)
    if(2%2) // Is it equal to if(FALSE)

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    45
    you have to use a condition..like..
    Code:
    if(3%2 == 1)
    {
      printf("A");
    }
    else
    {
     printf("B");
    }
    the above statement prints A because 3%2 == 1 is true..

  5. #5
    Registered User
    Join Date
    Sep 2011
    Posts
    30
    but i read my note which is just if(3%2) i don't know the meaning of this

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    32
    Quote Originally Posted by tommytmh View Post
    if(3%2) // Is it equal to if(TRUE)
    if(2%2) // Is it equal to if(FALSE)
    Code:
    if(condition)
    is a conditional statement. If the condition results in logical 0 then the body of the loop won't be excuted whereas if the condition is logial 1 then the body of the loop will be executed.
    Example:
    Code:
    if(1>2)
    {
    }
    Here the body of the loop wont be executed.
    Code:
    if(2>1)
    {
    }
    Here the body of the loop will be executed.

    In your example '%' is modulus operator. Read more about it you'll know the answer.

  7. #7
    Registered User
    Join Date
    Sep 2011
    Posts
    30
    get it thanks

Popular pages Recent additions subscribe to a feed