User
Pass
2FA
 
 

exercitiu c++

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database
Author Message1509
Sharp.

[Dopat. Superantrenat]



Status: Offline
(since 06-03-2016 13:34)
Joined: 06 Oct 2012
Posts: 763, Topics: 63
Location: Iasi

Reputation: 208.4
Votes: 50

   
Post Posted: 03-03-2013, 11:17:25 | Translate post to: ... (Click for more languages)

Se da un sir de numere citite pe rand de la tastatura atata timp cat nu s-a introdus valoarea 0 (care nu face parte din sir). Sa se afiseze acele elemente ale sirului care au proprietatea ca suma cifrelor lor este divizibila cu o valoare p data, precum si numarul respectivelor elemente.

Exemplu: pentru sirul: 45, 25, 147, 9, 111, 1231, 0 si p=3 se va afisa 45, 147, 111, 9, precum si valorea 4 (nr de elemente).

Code:
#include <iostream.h>
#include <conio.h>
int main ()
{int x,p,s=0,aux=1,i=0;
cout<<"p=";
cin>>p;
while(x!=0)
{
   cout<<"x=";
   cin>>x;
   aux=x;
   while(aux!=0)
   {
      s=s+aux%10;
      aux=aux/10;
   }
   if(s%p==0 && x!=0)
   {
      cout<<x<<" ";
      i=i+1;
   }
}
cout<<"Sirul contine "<<i<<" elemente, unde suma cifrelor unui element este divizibila cu "<<p;
return 0;
}
   


nu inteleg de ce mingw calculeaza numai o data, dau prima valoare 45, imi afiseaza, dupa dau urmatoarele valori si nu imi mai afiseaza nimic, un mic ajutor daca se poate -


mzq-: ba da in **** mea daca tot esti asa bun joaca si tu calumea
SHARP: nu mai joc ca lumea
mzq-: cand ai mingea in apropierea careului
mzq-: stii doar sa driblezi
mzq-: tot ce iti iese in cale
mzq-: si intrii cu ea in poarta
0 0
  
Back to top
View user's profile Send private message Yahoo! Messenger ID
Nexflame

[Newb Developer]



Status: Offline
(since 28-12-2022 15:28)
Joined: 19 Apr 2010
Posts: 1316, Topics: 24
Location: Cluj-Napoca

Reputation: 1407.1
Votes: 58

   
Post Posted: 03-03-2013, 22:45:06 | Translate post to: ... (Click for more languages)

Sharp. wrote:
nu inteleg de ce mingw calculeaza numai o data

The compiler is to blame for everything.

Probabil ar trebui sa initializezi s cu 0 de fiecare data cand introduci cate un numar, zic si eu.

0 0
  
Back to top
View user's profile Send private message Yahoo! Messenger ID
Sharp.

[Dopat. Superantrenat]



Status: Offline
(since 06-03-2016 13:34)
Joined: 06 Oct 2012
Posts: 763, Topics: 63
Location: Iasi

Reputation: 208.4
Votes: 50

   
Post Posted: 04-03-2013, 14:55:25 | Translate post to: ... (Click for more languages)

multumesc.

mzq-: ba da in **** mea daca tot esti asa bun joaca si tu calumea
SHARP: nu mai joc ca lumea
mzq-: cand ai mingea in apropierea careului
mzq-: stii doar sa driblezi
mzq-: tot ce iti iese in cale
mzq-: si intrii cu ea in poarta
0 0
  
Back to top
View user's profile Send private message Yahoo! Messenger ID
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Freakz Forum Index -> Trash Bin -> Trash -> Programming / Scripting / Database  


The time now is 02-12-2024, 04:02:16
Copyright info

Based on phpBB ro/com
B

 
 
 







I forgot my password


This message appears only once, so
like us now until it's too late ! :D
x