"thank you . while changing the name of the variables in my program. i came to know that i used a variable name in two different context. now i got the output. thank you.
and can you give any other idea to code this program in easy way"
Seriously, start by getting the indentation right. Which is easier to read:
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
count=1;
if((n-j)>=(noe- 1 ))
{
printf("%d," ,a[i]);
x=j;
sum=a[i];
while(count<noe)
{
count++;
printf("%d," ,copy[x]);
sum+=copy[x];
x++;
}
printf("- - -%d" ,sum);
if(sum>max)
{
maxarry[0]=a[i];
for(l=1,m=j;m++)
maxarry[l]=c[m];
max=sub;
}
printf("\n" );
} }
}
k++;
}
Or
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
count=1;
if((n-j)>=(noe- 1 ))
{
printf("%d," ,a[i]);
x=j;
sum=a[i];
while(count<noe)
{
count++;
printf("%d," ,copy[x]);
sum+=copy[x];
x++;
}
printf("- - -%d" ,sum);
if(sum>max)
{
maxarry[0]=a[i];
for(l=1,m=j;m++)
maxarry[l]=c[m];
max=sub;
}
printf("\n" );
}
}
}
k++;
}
With the second one, you can see at a glance what the flow of control is, and that you have three nested loops - you can't see that at all easily from the first one, because you have to spend loads of time matching brackets by hand.
Second, always use descriptive names - "i", "j", "k", and "n" don't mean anything in particular and it is horribly easy to get confused - as you have seen when you tried to change them! :laugh: It's a lot, lot easier to work with "real" names that talk about what the variable is there for from the start, because you don't have to spend time remembering which is which as you go along.
Finally, that's whats called "monolithic code" - it's all one block, and that means it's harder to understand.
Try making separate functions: input, processing, output.
Then break processing into parts: Generate all possible arrays, sort the arrays.
This way the tasks become simpler, and easier to understand and code. It may seem a little overkill for a trivial project like this, but it's a good idea, because it is the way you have to do it in the real world and it really does make it easier to focus on the various tasks, and get each one right before you move on to the next.
Try it: it's not difficult, and it makes life easier. (Backup what you've got, then give it a try - that way if you get horribly confused you've still got something to hand in to your tutor! :laugh: )
[edit]I hate damn markdown! Strikethrough in code? Come on...[/edit]