MY name is ruhul amin

ISLAMIC UNIVERSITY OF KUSHTIA

Friday, April 5, 2013

maximum value of given a seires

#include<stdio.h>
#define min -1000000
#define maxi 1000
int a[maxi],ms;
void maximum(int p,int r)
{
 int i,s,max;
 int left,right,t,c;
 int sum=0;
 int k;
 max=min;
 for(i=r;i>=p;i--)
 {
     sum=sum+a[i];
     if(sum>max)
     {
     max=sum;
     left=r-i;
     right=i;
     }
 }
 s=r-p;
 if(s==1)
 {
     left=p;
     right=r;
 }
 else
 {
 right=left+1;
 left=i+1;
 }
 k=max;
 if(k>ms)
 {
   ms=k;
   t=left;
   c=right;
   left=t;
   right=c;
 }
}
int function(int p,int r)
{
    int q;
    q=(p+r)/2;
    maximum(p,q);
    maximum(q+1,r);
    maximum(p,r);
   printf("The maximum value is %d\nThe lower boundery is %d \nThe upper boundery is %d\n",ms,p,r);
}
int main()
{
 int n;
 int i;
 while(scanf("%d",&n)!=EOF)
 {
     for(i=1;i<=n;i++)
     scanf("%d",&a[i]);
     ms=0;
     function(1,n);
 }
 return 0;
}

No comments:

Post a Comment