|
|
back to boardWhat's wrong with my programm?C++ Posted by Sharing 10 Jan 2009 05:57 #include<iostream.h> #include<math.h> void main() { int n,a[20]; int temp; signed int t; cin>>n; for(int i=0;i<n;i++)cin>>a[i]; for(int k=0;k<n-1;k++){ for(int m=k+1;m<n;m++){ if(a[m]>a[k]){ temp=a[m]; a[m]=a[k]; a[k]=temp; } } } t=a[0]; for(int k1=1;k1<n;k1++){ if(t>0)t-=a[k1]; else t+=a[k1]; } cout<<abs(t)<<endl; } Re: What's wrong with my programm?C++ Posted by OpenGL 10 Jan 2009 17:25 Try this test 7 5 6 8 2 6 7 8 Right answer is 0 (first 4 and last 3) but your program write 2 |
|
|