Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
suma negativnih, savjet!!
Author Message
Dex02 Offline
Novi korisnik
*

Posts: 6
Joined: Dec 2009
Reputation: 0
Post: #1
suma negativnih, savjet!!
Vozdra raja imam mali problem. Trebam napisat program koji ce napisati sumu neparnih brojeva u intervalu od 100 - 1000 (while, petlja). Uradio sam zadatak, ali profa kaze da nije tacan rezultat. Sad neznam gdje grjesim:

int suma = 0, i = 100;
while (suma < 1000)
{
i % 2 == 1;
suma += i;
i++;
}
cout << suma;
}

ili

int suma = 0, i = 100;
while (suma < 1000)
{
suma += i;
i = i + 2;
}
cout << suma;
}
ili ( sa IF )

int suma = 0, i = 100;
while (suma < 1000)
if (i % 2 == 1);
{
suma += i;
i++;
}
cout << suma;
}
(This post was last modified: 24-12-2009 08:54 PM by Dex02.)
24-12-2009 07:26 PM
Find all posts by this user Quote this message in a reply
r0tring Offline
Redoviti posjetitelj
**

Posts: 230
Joined: Apr 2009
Reputation: 10
Post: #2
RE: suma negativnih, savjet!!
Reci ti profi da ne postoji nijedan negativan br. u intervalu od 100 do 1000. Palac-gore
24-12-2009 08:49 PM
Find all posts by this user Quote this message in a reply
Dex02 Offline
Novi korisnik
*

Posts: 6
Joined: Dec 2009
Reputation: 0
Post: #3
RE: suma negativnih, savjet!!
pardon neparnih brojeva!
24-12-2009 08:53 PM
Find all posts by this user Quote this message in a reply
r0tring Offline
Redoviti posjetitelj
**

Posts: 230
Joined: Apr 2009
Reputation: 10
Post: #4
RE: suma negativnih, savjet!!
Code:
int suma=0, i=100;
  while (i<1000)
    {
      if (i%2!=0) //broj "i" je neparan ako ostatak djeljenja broja "i" sa 2 nije jednak 0 (nula)
       {
         suma=suma+i;
       }
     i++;
    }
    
  cout<<suma;
(This post was last modified: 24-12-2009 09:18 PM by r0tring.)
24-12-2009 09:17 PM
Find all posts by this user Quote this message in a reply
Dex02 Offline
Novi korisnik
*

Posts: 6
Joined: Dec 2009
Reputation: 0
Post: #5
RE: suma negativnih, savjet!!
Hvala covjece!
24-12-2009 10:23 PM
Find all posts by this user Quote this message in a reply
Kerber Offline
_
*

Posts: 357
Joined: Dec 2006
Reputation: 1
Post: #6
RE: suma negativnih, savjet!!
scroler Wrote:Reci ti profi da ne postoji nijedan negativan br. u intervalu od 100 do 1000. Palac-gore

hahah He he He he He he

FGD!

Pravila foruma - pročitajte prije nego pitate
25-12-2009 03:13 PM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)