示例#1
0
int main(){
    
    int count = 0;
        while(1){
                 printf("input number for iterative > ");
                 //scanf("%d",&count);       
                 if(iterative(count)>=0){                   
                     printf("The %d iterative result %d\n",count,iterative(count));
                     count++;
                 }
                 else{
                      printf("The %d iterative result %d,is overflow\n",count,iterative(count));
                      break;
                 }
        }
    system("pause");
        return(0);
    
    
    }
示例#2
0
void solve(int n,int m,int **p){
   printf("Running iterative\n");
   int **b;                   /*Declares a board to store the summary for each number of the board. */
   int i,j,jmax,smax=0;        /*Declares 2 variables for the loops,one for the maximum sum,and one to be used finding the path. */
   b=malloc(n*sizeof(int *));  /*Commiting the "pointer" part of the board */
   if (b==NULL){
        printf("Error,not enough memory available.");
        return;
   }
   for (i=0;i<n;i++){        
       b[i]=malloc(m*sizeof(int));    /*Finish commiting the board. */
       if (b[i]==NULL){
           printf("Error,not enough memory available.");
           return;
       }
       for(j=0;j<m;j++){
           b[i][j]=p[i][j];     /*Initially copying the number board on the summary board to do less loops,not having to touch the last line. */
       }
   }
   for(i=n-2;i>=0;i--){     /*Starts from the bottom upwards,and ,using iterative, fills the summary board. */
       for (j=0;j<m;j++){
           iterative(b,i,j,m);
       }       
   }
   for (j=0;j<m;j++){       /*Finds the maximum summary and it's position using the summary board. */
        if(b[0][j]>smax){
            jmax=j;
            smax=b[0][jmax];
        }
    }
    printf("Max sum is %d.\n",smax);
    pathfinder(p,b,jmax,n,m);/*Calls a function to find and print the path. */
    for (i=0;i<n;i++){     /*Freeing the summary board. */
        free(b[i]);
    }
    free(b);
   
}