This program dont work.
If there is not even number after odd number,all negative numbers must be printed out from the end to beginning,otherwise positive.
#include<iostream>
using namespace std;
int sk;
int a;
bool skaitli = true;
int main()
{
cout<<"How many integers you want to input?"<<endl;
cin>>sk;
int arr[sk];
for (int i=0;i<sk;i++)
{cout<<"Enter "<<i+1<<". string number "<<endl;
cin>>arr[i];
}
for (int j=0;j<sk;j++)
{ if (arr[j]%2!=0&&arr[j+1]%2==0)
skaitli=true;
else
skaitli=false;
}
if (skaitli)
{
a=sk-1;
for (a;a==0;a--)
if (arr[a]<0) cout<<arr[a];
else
if (arr[a]>0) cout<<arr[a];
}
system("pause");
return 0;
}
Next time, please format your code to make it readable and use the code bbcodes please.
Standard C++ formatting with 3 space tabs.
To get to the point: So there must be a postive number, after a negative number to print all evens else it prints odds? May I ask the purpose of this program without looking at the code?
#include<iostream>
usingnamespace std;
int sk;
int a;
bool skaitli = true;
int main()
{
cout<<"How many integers you want to input?"<<endl;
cin>>sk;
int arr[sk];
for (int i=0;i<sk;i++)
{
cout<<"Enter "<<i+1<<". string number "<<endl;
cin>>arr[i];
}
for (int j=0;j<sk;j++)
{
if (arr[j]%2!=0&&arr[j+1]%2==0)
skaitli=true;
else
skaitli=false;
}
if (skaitli)
{
a=sk-1;
for (a;a==0;a--)
{
if (arr[a]<0)
cout<<arr[a];
elseif (arr[a]>0) cout<<arr[a];
}
}
system("pause");
return 0;
}
Well, one thing that's wrong is on line 11: int arr[sk];
You're not allowed to do that. You need to use either malloc (int* arr = malloc(sk*sizeof(int));) or new (int* arr = newint[sk]). However, you then need to free(arr) (in the case of malloc) or delete[] arr; (in the case of new) to prevent any possible memory leaks.
I haven't run this, though, so I don't know if there's anything else wrong. It's just the first thing I noticed.
if user inputs: 2 -2 3 -5 5 2 69 -63 i have to print out 69 2 5 3 2
if user inputs 2 4 6 8 -10 8 6 -12 i have to print out -12 -10
No matter whether there is positive after negative or negative after positive.
I have to know if there is even after odd.
like this arr[j]%2!=0&&arr[j+1]%2==0
Still no one can help?:( Made a little changes.And have no idea how to make readeble with bbcode.Completily stupid..
#include<iostream>
using namespace std;
int main()
{
int sk;
int *arr;
bool paris = true;
cout<<"Cik skaitlus velies ievadit?"<<endl;
cin>>sk;
arr = new int[sk];
for (int i=0;i<sk;i++)
{cout<<"Ievadi "<<i+1<<". skaitli "<<endl;
cin>>arr[i];
}
for (int j=0;j<sk-1;j++)
{ if ((arr[j]%2!=0)&&(arr[j+1]%2==0))
paris=true;
else
paris=false;
}
if (paris)
{
int a=sk-1;
for (a;a<0;a--)
if (arr[a]<0) cout<<arr[a];
else
if (arr[a]>0) cout<<arr[a];
}
delete[] arr;
cin >> sk;
system("pause");
return 0;
}
#include<iostream>
usingnamespace std;
void keep_window_open(){
char ch;
cout<<"enter any character to continue...";
cin>>ch;
}
int main(){
int sk;
int *arr;
bool paris = true;
cout<<"How many integers you want to input?"<<endl;
cin>>sk;
arr = newint[sk];
for (int i=0;i<sk;i++){
cout<<"Enter "<<i+1<<". string number "<<endl;
cin>>arr[i];
}
for (int j=0;j<sk;j++){
if ((arr[j]%2!=0)&&(arr[j+1]%2==0)){
paris=true;
break;
}
else paris=false;
}
if (!paris){
for (int a=sk-1;a>=0;a--){
if (arr[a]<0)cout<<arr[a]<<' ';
}
}
if (paris){
for (int a=sk-1;a>=0;a--){
if (arr[a]>0)cout<<arr[a]<<' ';
}
}
delete[] arr;
keep_window_open();
return 0;
}