Click here to Skip to main content
15,889,116 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Using COM in DLL called by .Net application Pin
Richard Deeming26-Oct-16 3:11
mveRichard Deeming26-Oct-16 3:11 
PraiseSOLVED Pin
Leif Simon Goodwin9-Nov-16 5:32
Leif Simon Goodwin9-Nov-16 5:32 
AnswerRe: Using COM in DLL called by .Net application Pin
«_Superman_»26-Oct-16 20:47
professional«_Superman_»26-Oct-16 20:47 
GeneralRe: Using COM in DLL called by .Net application Pin
Leif Simon Goodwin8-Nov-16 20:53
Leif Simon Goodwin8-Nov-16 20:53 
QuestionError in returning array of int as reference Pin
Korowai22-Oct-16 19:35
Korowai22-Oct-16 19:35 
AnswerRe: Error in returning array of int as reference Pin
Graham Breach22-Oct-16 21:46
Graham Breach22-Oct-16 21:46 
GeneralRe: Error in returning array of int as reference Pin
Korowai22-Oct-16 22:41
Korowai22-Oct-16 22:41 
GeneralRe: Error in returning array of int as reference Pin
Midi_Mick22-Oct-16 23:12
professionalMidi_Mick22-Oct-16 23:12 
GeneralRe: Error in returning array of int as reference Pin
Korowai23-Oct-16 2:39
Korowai23-Oct-16 2:39 
GeneralRe: Error in returning array of int as reference Pin
leon de boer23-Oct-16 4:24
leon de boer23-Oct-16 4:24 
GeneralRe: Error in returning array of int as reference Pin
Korowai23-Oct-16 8:11
Korowai23-Oct-16 8:11 
GeneralRe: Error in returning array of int as reference Pin
Korowai23-Oct-16 8:26
Korowai23-Oct-16 8:26 
QuestionRe: Error in returning array of int as reference Pin
David Crow23-Oct-16 15:26
David Crow23-Oct-16 15:26 
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 

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.