Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Error in returning array of int as reference Pin
Joe Woodbury24-Oct-16 14:07
professionalJoe Woodbury24-Oct-16 14:07 
QuestionMost efficient way to create a string range in C? Pin
Member 1280348819-Oct-16 10:19
Member 1280348819-Oct-16 10:19 
AnswerRe: Most efficient way to create a string range in C? Pin
leon de boer19-Oct-16 19:33
leon de boer19-Oct-16 19:33 
AnswerRe: Most efficient way to create a string range in C? Pin
leon de boer20-Oct-16 21:14
leon de boer20-Oct-16 21:14 
AnswerRe: Most efficient way to create a string range in C? Pin
Joe Woodbury26-Oct-16 12:16
professionalJoe Woodbury26-Oct-16 12:16 
QuestionHow to invoke Printing Preferences for the given Printer programmatically? Pin
purnachandra505016-Oct-16 17:48
purnachandra505016-Oct-16 17:48 
SuggestionRe: How to invoke invoke Printing Preferences for the given Printer programmatically? Pin
Richard MacCutchan17-Oct-16 5:06
mveRichard MacCutchan17-Oct-16 5:06 
QuestionHelp please Memoized rod cutting in C while showing the length it is cut Pin
Member 1279667016-Oct-16 12:03
Member 1279667016-Oct-16 12:03 
r[1000];
*r = (int *) malloc ((n+ 1) * sizeof(int));
but if I use int *r then also it doesn't passes properly .Should I use structure?
The problem should take input like
division-3
input of price-1,5,8
and give rod cutting whereas there are three iteration which should be one r=0;
and the maximum price for this division should be 8 but the result comes 1677218


C++
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include<limits.h>
int sum=0;

int max(int a, int b)
    {
         return(a>b)?a:b;
    }
int cut_rod_aux(int price[], int n, int r[])
   { int i;
        if(r[n]>=0)
          {
               return r[n];
                printf(" %d\n",r[n]);
          }
        if (n==0)
          {
                sum=0;

          }
        else
         {
              sum =100000;
              for( i=1; i<n;i++)
              {
                         sum=max(sum, price[i]+cut_rod_aux(price, n-i,r));
                         printf("%d \n",sum);
                  }
          }

       r[n]=sum;
       return sum;
   }
   int cut_rod(int price[], int n)
   {    int i,r[1000];
*r = (int *) malloc ((n+ 1) * sizeof(int));
        for( i=0; i<n;i++)              {
                r[i]=100000;
                printf("i=%d\t r=%d \n",i,r[i]);
            }
       return cut_rod_aux(price,n,r);
   }
int main()
{            int arr[100],i, N;
         printf("Enter the number of length that will be divided\n");
         scanf("%d", &N);


            for ( i = 0;i< N; i++) {
            printf("Enter price for  %d length\n", (i+1));
            scanf("%d", &arr[i]);}
            printf("output %d \n",cut_rod(arr, N));

        return 0;
}


modified 17-Oct-16 3:21am.

AnswerRe: Help please Memoized rod cutting in C while showing the length it is cut Pin
leon de boer16-Oct-16 16:12
leon de boer16-Oct-16 16:12 
GeneralRe: Help please Memoized rod cutting in C while showing the length it is cut Pin
Richard MacCutchan17-Oct-16 5:08
mveRichard MacCutchan17-Oct-16 5:08 
AnswerRe: Help please Memoized rod cutting in C while showing the length it is cut Pin
Richard MacCutchan16-Oct-16 21:25
mveRichard MacCutchan16-Oct-16 21:25 
QuestionAssigning pointers from one class to another and Pin
Vaclav_14-Oct-16 6:23
Vaclav_14-Oct-16 6:23 
AnswerRe: Assigning pointers from one class to another and Pin
leon de boer14-Oct-16 17:58
leon de boer14-Oct-16 17:58 
GeneralRe: Assigning pointers from one class to another and Pin
Vaclav_15-Oct-16 2:24
Vaclav_15-Oct-16 2:24 
GeneralRe: Assigning pointers from one class to another and Pin
leon de boer15-Oct-16 4:42
leon de boer15-Oct-16 4:42 
GeneralRe: Assigning pointers from one class to another and Pin
Vaclav_15-Oct-16 6:12
Vaclav_15-Oct-16 6:12 
GeneralRe: Assigning pointers from one class to another and Pin
leon de boer15-Oct-16 17:16
leon de boer15-Oct-16 17:16 
GeneralRe: Assigning pointers from one class to another and Pin
Vaclav_19-Oct-16 4:54
Vaclav_19-Oct-16 4:54 
GeneralRe: Assigning pointers from one class to another and Pin
leon de boer19-Oct-16 7:45
leon de boer19-Oct-16 7:45 
NewsHow to provide a Security to a proprietary software or presemtation. Pin
Member 1278313512-Oct-16 20:03
Member 1278313512-Oct-16 20:03 
GeneralRe: How to provide a Security to a proprietary software or presemtation. Pin
jeron113-Oct-16 4:15
jeron113-Oct-16 4:15 
GeneralRe: How to provide a Security to a proprietary software or presemtation. Pin
leon de boer13-Oct-16 8:17
leon de boer13-Oct-16 8:17 
Questionclass is missing "type" - why ? Pin
Vaclav_12-Oct-16 15:00
Vaclav_12-Oct-16 15:00 
AnswerRe: class is missing "type" - why ? Pin
leon de boer12-Oct-16 17:45
leon de boer12-Oct-16 17:45 
AnswerRe: class is missing "type" - why ? Pin
Graham Breach12-Oct-16 23:11
Graham Breach12-Oct-16 23:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.