Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- int n,a[100],b[100],i,j,k,x,y,noofodd=0,noofeven=0,ans=0;
- scanf("%d",&n);
- for(i=0;i<n;i++) // find no of odd and evens
- {
- scanf("%d",&a[i]);
- if(a[i]%2==0)
- noofeven++;
- else
- noofodd++;
- }
- for(x=0; x<n; x++) //sort in asc order
- for(y=0; y<n-1; y++)
- if(a[y]>a[y+1])
- {
- int temp = a[y+1];
- a[y+1] = a[y];
- a[y] = temp;
- }
- if(noofeven==n) //if all evens
- ans=0;
- else if(noofodd==n && n%2==0) // if all odd and noofflowers is even
- {
- for(i=1;i<n;i++)
- ans=ans+a[i];
- }
- else if(noofodd==n && n%2!=0) // if all odd and noofflowers is odd
- {
- for(i=0;i<n;i++)
- ans=ans+a[i];
- }
- else //else
- {
- for(i=1;i<n;i++)
- ans=ans + a[i];
- if(ans%2!=0 && a[0]%2!=0)
- {
- ans=ans+0;
- }
- else if(ans%2!=0 && a[0]%2==0)
- {
- ans=ans+a[0];
- }
- else if(ans%2==0 && a[0]%2!=0)
- {
- ans=ans+a[0];
- }
- else if(ans%2==0 && a[0]%2==0)
- {
- ans=ans+a[0];
- for(i=1;i<n;i++)
- if(a[i]%2!=0)
- {ans=ans-a[i];break;}
- }
- }
- printf("%d",ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement