Answer to Question #16936 in C++ for tirana

Question #16936
how to get this input with c++ language?
1 4 3 2 9 7 18 22 0
2 4 8 10 0
7 5 11 13 1 3 0
-1
when arrive to zero is end line
and when arrive to -1 is end input
1
Expert's answer
2012-10-25T09:51:32-0400
#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{int n,f,a,m,k,c[n];
cout<<"please enter n"<<endl;
& cin>>n;
cout<<endl;
cout<<"please enter masiv"<<endl;
& for(int i = 0; i< n ; i++)
& {cin>>c[i];}
& cout<<"we have masive: ";
& for(int i = 0; i< n ; i++)
& {cout <<c[i]<<" "; }
& cout <<endl<<endl;
& //1
& for(int i = 0; i< n ; i++)
{if ( c[i] ==0)& {k=i+1;break;}}
for(int i = 0; i< k ; i++)
& {cout<<c[i]<<" ";}
& cout<<endl;
& //2
& for(int i = k; i< n ; i++)
{if ( c[i] ==0)& {f=i+1;break;}}
for(int i = k; i< f ; i++)
& {cout<<c[i]<<" ";}
& cout<<endl;
& //3
& for(int i = f; i< n ; i++)
{ if ( c[i] ==0)& {a=i+1;break;}}
for(int i = f; i< a ; i++)
& {cout<<c[i]<<" ";}
& cout<<endl;
& //4
& for(int i = a; i< n ; i++)
{ if ( c[i] ==-1)& {cout<<c[i]<<endl;break ;}}

&
& system("PAUSE");
& return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS