1005 stone pile, everything is write but???
Послано
Sashka 3 дек 2006 12:50
I can't get what the mistake in my programme is?
#include <stdio.h>
main (){
int z,d,k,arr[20],i,temp,j,flag,n,a1=0,a2=0;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
for(i = 1; (i <= n) && flag; i++)
{
flag = 0;
for (j=0; j < (n-1); j++)
{
if (arr[j+1] > arr[j])
{
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
flag = 1;
}
}
}
if(n>1){
a1=arr[0];
for(z=1;z<n;z++){
if(a1>=a2){
a2+=arr[z];
continue;
}
if(a1<a2){
a1+=arr[z];
continue;
}
}
if(a1>=a2){
printf("%d",(a1-a2));
}
if(a1<a2){
printf("%d",(a2-a1));
}
}
if(n==1){printf("%d",a1);}
}