C++,siruri

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
User avatar
GameKiller67
Junior
Junior
Posts: 2
Joined: 15 Dec 2015, 00:17
Judet: Olt

C++,siruri

Post by GameKiller67 » 20 Jan 2016, 22:45

Deci citesc nr naturale pana se citeste 0.Eu trebuie sa arat cate nr parem,respectiv impare (Diferite de 0)sunt.Am reusit sa fac perfect sa imi afiseze nr pare dar m-am blocat la impare uitati aici sintaxa,cu ce am gresit?
#include <iostream>

using namespace std;
int n,k,m;
int main()
{
k=0;
m=0;
cout<<"n=";
cin>>n;
while(n!=0)
{
cout<<"n=";
cin>>n;
if(n%2==0)
k+=1;

}
cout<<"pare: "<<k-1;
while(n!=0)
{
if(n%2!=0)
k+=2;

}
cout<<"impare:"<<k;
return 0;
}
:?: :?: :?:



ninthplanet
Junior
Junior
Posts: 1
Joined: 25 Jan 2016, 11:49
Judet: Cluj

Re: C++,siruri

Post by ninthplanet » 25 Jan 2016, 11:51

#include<iostream>;
using namespace std;

int input,pare,impare;

int main()
{
cout << "introduceti numere ('0' pentru a termina): " << endl;
while(cin >> input && input != 0)
{
if(input%2==0)
++pare;
else
++impare;
}
cout << "pare: " << pare << endl << "impare: " << impare;
return 0;
}

Post Reply