this is the correct working code #define size 8 void main() {
int a[]={16,2,4,10,1,12,5,6}; int sum=0,i,index; for(i=0;i<size-1;) { if(a[i]>a[i+1]) { sum=sum+a[i]; index=i; i=i+2; } else { sum=sum+a[i+1]; index=i; i=i+3; } } if(i-index>1) sum=sum+a[i]; printf("maximum sum is %d",sum); } On Mon, Aug 1, 2011 at 1:39 PM, Abhishek Gupta <gupta.abh...@gmail.com>wrote: > @Kartik > > we cant choose adjacent elements. for ex A={5,2,1,7,9,11} then we will have > 5+7+11 > can any one give any algo for this > thank you > > > On Mon, Aug 1, 2011 at 1:25 PM, kartik sachan <kartik.sac...@gmail.com>wrote: > >> oh......got it i didn't read that statement....:( >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > Abhishek Gupta > MCA > NIT Calicut > Kerela > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.