using namespace std;
int main() {int* a=NULL,i,n;cout<<"how many values do you want to enter:"<<endl;cin>>n;a= new int[n];for(i=0;i<n;i++){a[i]=0; }for(i=0;i<n;i++) { cin>>a[i]; if(a[i]==42) break; }n=i;for(i=0;i<n;i++)cout<<a[i]<<endl; return 0;}
what is this supposed to do?ok, i think it's guessing the number 42...
**for(i=0;i<n;i++) a[i]=0; ** <-this part is kinda useless if make this :
for(i=0;i<n;i++) cin>>a[i];
and
instead of int *a=NULL;write only int *a;
int main() {int *a,i,n;cout<<"how many values do you want to enter:"<<endl;cin>>n;a= new int[n];for(i=0;i<n;i++){cin>>a[i];if(a[i]==42)break;}n=i;for(i=0;i<n;i++)cout<<a[i]<<endl;return 0;}i made changes u can see in the code and its still says wrong answer i chose c++(g++ 4.3.2) compiler .thanks much.
which problem ?Can u give a link to the website?
http://www.spoj.com/problems/TEST/
The problem doesn't say how many numbers you will get.So basically you don't know how many.In this case you normally do:int x;while(cin>>x){ //your codes goes here}but...this is an easy task, so probably, you can assume that there will be less than 100 numbers given.There is also a piece of information that there are small numbers, so:
int tab[100];int i=0;while(cin>>tab[i]){if(tab[i]==42) break;i++;}write the rest of the code.