Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #12431

Re: Using ternary and summing array

Message-ID <4EAFBDCD.7264@mindspring.com> (permalink)
Date 2011-11-01 04:37 -0500
From pete <pfiland@mindspring.com>
Organization PF
Newsgroups comp.lang.c
Subject Re: Using ternary and summing array
References <26bf4806-b232-4878-810b-55f3d3926c9f@p20g2000prm.googlegroups.com> <6615b0de-8283-486e-acaf-fa21560ff96d@p14g2000pra.googlegroups.com>

Show all headers | View raw


flebber wrote:
 
> I created a working solution with an if statement but I would still
> really love to know if I could use the "?" to acheive the same result.

>    if ((i % 3 == 0)||(i % 5 == 0)){
>      sum += i;
>     }

If that is truly your goal:

sum += ((i % 3 == 0)||(i % 5 == 0)) ? i : 0;

-- 
pete

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Using ternary and summing array flebber <flebber.crue@gmail.com> - 2011-10-31 03:35 -0700
  Re: Using ternary and summing array flebber <flebber.crue@gmail.com> - 2011-10-31 04:06 -0700
    Re: Using ternary and summing array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-31 15:06 +0000
    Re: Using ternary and summing array pete <pfiland@mindspring.com> - 2011-11-01 04:37 -0500
      Re: Using ternary and summing array Keith Thompson <kst-u@mib.org> - 2011-11-01 16:36 -0700
  Re: Using ternary and summing array flebber <flebber.crue@gmail.com> - 2011-10-31 04:04 -0700
  Re: Using ternary and summing array Jean-Christophe <5.d@free.fr> - 2011-10-31 04:16 -0700
    Re: Using ternary and summing array Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-10-31 15:00 +0000
    Re: Using ternary and summing array flebber <flebber.crue@gmail.com> - 2011-10-31 16:11 -0700
      Re: Using ternary and summing array James Kuyper <jameskuyper@verizon.net> - 2011-10-31 21:49 -0400
    Re: Using ternary and summing array Kenneth Brody <kenbrody@spamcop.net> - 2011-11-03 12:04 -0400
      Re: Using ternary and summing array Kaz Kylheku <kaz@kylheku.com> - 2011-11-03 17:03 +0000
        Re: Using ternary and summing array Kenneth Brody <kenbrody@spamcop.net> - 2011-11-08 13:08 -0500
  Re: Using ternary and summing array James Kuyper <jameskuyper@verizon.net> - 2011-10-31 07:46 -0400
    Re: Using ternary and summing array David Thompson <dave.thompson2@verizon.net> - 2011-11-21 02:39 -0500

csiph-web