Wednesday, 21 September 2016

Continuous sum equal to key value

CONTINOUS SUM IS EQUAL TO THE GIVEN KEY VALUE

#include<stdio.h>
int main()
{
int n,i,j,key,csum=0;
printf("no of number\n");
scanf("%d",&n);
int a[n];
printf("read array value\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
printf("key\n");
scanf("%d",&key);
for(i=0;i<n;i++)
{
csum=a[i];
for(j=i+1;j<=n;j++)
{
if(csum==key)
{
printf("%d %d",i,j-1);

}
if(csum>key || j==n )
break;
csum = csum+a[j];
}
}
return 0;

}

o/p

no of number
7
read array value
3
3
4
5
6
7
8
key
9
2 3

--------------------------------
Process exited after 15.8 seconds with return value 0
Press any key to continue . . .

No comments:

Post a Comment

Troubleshooting in SQL

1. SSRS Error  Round () need to be done in  SQL itself  2. Default Date In SSRS  Start Date =CDate(Format(DateAdd("d",-50,Now()), ...