@Raj Jagvanshi: Test 1 : Enter numbers (-1 to stop taking input) 4 1 2 3 4 5 40 41 19 20 -1
Largest sequence is : 40 to 41 40 41 Sum: 81 -------------------------------------- Test 2: Enter numbers (-1 to stop taking input) -5 -4 -3 -1 Largest sequence is : -3 to -3 -3 Sum: -3 ------------------------------------------- Here is my code: #include<stdio.h> int main(){ int arr[100],i,N; int max,smax,emax; int curr,scurr; printf("Enter numbers (-1 to stop taking input)\n\n"); for(i=0 ; i<100 ; i++){ scanf("%d",&arr[i]); // Enter "-1" to stop entering the numbers if(arr[i] == -1){ N=i; break; } } //........ max = arr[0]; curr = arr[0]; smax = emax = scurr = 0; for(i=1 ; i<N ; i++){ if( (arr[i-1]+1 == arr[i]) && (curr < curr + arr[i]) ) { curr = curr + arr[i]; }else{ scurr=i; curr = arr[i]; } if(max < curr){ smax = scurr; emax = i; max = curr; } } // end.... printf("\n\nLargest sequence is : %d to %d \n",arr[smax],arr[emax]); for(i=smax ; i<=emax ; i++){ printf("%d\t",arr[i]); } printf("\nSum: %d\n",max); return 0; } -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@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.