Thread: help with c.. i know nothing

  1. #1
    Registered User
    Join Date
    Aug 2002
    Posts
    51

    Question help with c.. i know nothing

    i = i + i - i * i / i % i; where in this statement do i put the parenthesis?

    z = x > y ? x : y; And can you please tell me in words what this statement is doing?

    Also, how do i write this loop as a while loop:

    for (i = 10; i > 0; i--){
    printf("%d\n", i);
    }



    and last but not least, how do i rewrite this multi-branching if statement using a switch?

    if (i == 1) {
    printf("alpha\n");
    }
    else if (i ==4) {
    printf("beta\n");
    }
    else if (i == 2) {
    printf("gamma\n");
    }
    else{
    printf("delta\n");
    }


    Thanx for your help.

  2. #2
    Unregistered
    Guest
    i = i + i - i * i / i % i; where in this statement do i put the parenthesis?
    Wherever you want, whatever operation you want to take "precendence"

    z = x > y ? x : y; And can you please tell me in words what this statement is doing?
    IF 'Z' is GREATER THAN 'Y' THEN 'Z' = 'X'
    ELSE 'Z' = 'Y'

    it's just like an if statement. If the condition is satisfied(ie: x IS greater than y, then assign the value of x to z)


    and last but not least, how do i rewrite this multi-branching if statement using a switch?

    if (i == 1) {
    printf("alpha\n");
    }
    else if (i ==4) {
    printf("beta\n");
    }
    else if (i == 2) {
    printf("gamma\n");
    }
    else{
    printf("delta\n");
    }
    Code:
    switch (i) {
        case 1:
          printf("i is 1");
          break;
        case 2:
          printf("i is 2\n"0);
          break;
        default:
          printf("delta case\n");
          break;
    }

  3. #3
    Unregistered
    Guest
    printf("i is 2\n"0);
    change to printf("i is 2\n"); .. typo, can't edit because I forgot to sign in.. argh.. :>

Popular pages Recent additions subscribe to a feed