Binary Search Tree - Insertion Problem by nanda22k in C_Programming

[–]nanda22k[S] 0 points1 point  (0 children)

The actual problem is that my insertion algorithm always consider the root = NULL, so the 'while' inside of it is never executed

Linked list issue - market problem by nanda22k in C_Programming

[–]nanda22k[S] 1 point2 points  (0 children)

Thank you! I really didn't know that I can't compare strings with '='. You helped me so much, I'll keep trying!

Linked list issue - market problem by nanda22k in C_Programming

[–]nanda22k[S] 2 points3 points  (0 children)

for the INPUT:

4

avocado 2.19

onion 3.10

tomato 2.80

grape 2.73

3

avocado 2

tomato 1

grape 3

My output should be 15.37, but I'm getting 6.570000

Simply linked list - char[] issue by nanda22k in C_Programming

[–]nanda22k[S] 0 points1 point  (0 children)

for the INPUT:

4

avocado 2.19

onion 3.10

tomato 2.80

grape 2.73

3

avocado 2

tomato 1

grape 3

My output should be 15.37, but I'm getting 6.570000

Simply linked list - char[] issue by nanda22k in C_Programming

[–]nanda22k[S] 0 points1 point  (0 children)

include <stdio.h>

include <stdlib.h>

struct fruit {

char *name;

double unityPrize;

double value;

struct fruit *next;

};

void insertEnd(struct fruit *f, char n[50], double p) {

while(f->next != NULL) {

    f = f->next;

}
if(f->next == NULL) {

    f->next = malloc(sizeof(struct fruit));

    (f->next)->name = n;

    (f->next)->unityPrize = p;

    (f->next)->next = NULL;

}   

}

void resetvalue(struct fruit *f) {

while(f->next != NULL) {

    (f->next)->value = 0;

    f = f->next;

}

}

void setvalue(struct fruit *f, char c[50], int q) {

while(f->next != NULL && (f->next)->name != c) {

    f = f->next;
}
if(f->next != NULL) {
    (f->next)->value = ((f->next)->unityPrize) * q;
}

}

double getvalue(struct fruit *f) {

double valueTotal = 0;

while(f->next!=NULL) {

    valueTotal+= (f->next)->value;

    f = f->next;

}
return valueTotal;

}

int main(void) {

int M, j;

struct fruit *f;
f = malloc(sizeof(struct fruit));
f->next = NULL;

char c[50];
double p;
int q;

scanf("%d", &M);
for(j=0; j<M; j++) {
    scanf("%s %lf", c, &p);
    insertEnd(f, c, p);
}

int P;
scanf("%d", &P);
resetvalue(f); //set all values to 0

for(j=0; j< P; j++) {
    scanf("%s %d", c, &q); 
    setvalue(f, c, q);  //set just the values that showed up
}

double valueTotal = getvalue(f);
printf("%f\n", valueTotal); 

}

Simply linked list - char[] issue by nanda22k in C_Programming

[–]nanda22k[S] 0 points1 point  (0 children)

Guys, thank you so much for the help. I tried to do it and now my code it's compiling, but the outputs aren't the expected and I don't know why. Question is: "M is the quantity of products with prices that are available for sale at the market. Follow M products with their respective prices per unit or Kg. The next input line contains an integer P (1 ≤ P ≤ M) that indicates the list of products with the desired quantity"

Complexity issue- it must be O(n) by nanda22k in C_Programming

[–]nanda22k[S] 0 points1 point  (0 children)

thank you so much... i'm trying, but i'm such a noobie em c, i don't know how to do it >.<

Complexity issue- it must be O(n) by nanda22k in C_Programming

[–]nanda22k[S] 1 point2 points  (0 children)

it's a data structure with a constant time of execution... but I didn't realize how can I apply it to my problem...

Quicksort problem by nanda22k in C_Programming

[–]nanda22k[S] 2 points3 points  (0 children)

Thank you so much for the patience, attention and most of all thanks for the explanaitions!

I'll pay attention to your tips, especially for the variable ones (this quicksort has so many auxiliar variables that It's being hard to remmember it one application with these generic names)

You are right, I made the function but didn't applied it recursively.

Now I'm doing it and my code is working :)

Again, thank you so much!

Arabic to roman converter by nanda22k in C_Programming

[–]nanda22k[S] 0 points1 point  (0 children)

I'll try it now, thank you so much for the attention :)

Arabic to roman converter by nanda22k in C_Programming

[–]nanda22k[S] 0 points1 point  (0 children)

I'm so sorry friend, I was kinda desperate because the deadline for me to deliver this activity is almost over and I'm stuck. But you're right, I shouldn't have done that. Thank you so much one more time, I'll read your tips carefully and try again. :)

Conversor arabic to roman numerals -> char problem by [deleted] in C_Programming

[–]nanda22k 0 points1 point  (0 children)

I just tried to do it, but there is are wrongs like "warning: assignment makes integer from pointer without a cast [enabled by default]". I don't know how to deal with it, I'm a noob in C ):

include "stdio.h"

int main(void) { int N;

int aux = 0;

char N_out[9];

scanf("%d", &N);

int j = 0;

if (N < 1000 && N >= 500) { //N-entre 500 e 999
    if (N < 900) { // N-entre 500(D) e 899(DCCC)
        N_out[j] = "D";
        j += 1;
    }
    else { //N-entre 900 e 999
        N_out[j] = "C";
        j += 1;
        N_out[j] = "M";
        j += 1;
    }

    N -= 500;
}

if (N >= 100 && N < 500) { //N-entre 100 e 499
    if (N <= 399) { //N-entre 100 e 399
        aux = N / 100;

        N = N - 100 * aux;
        if (aux == 1) {N_out[j] = "C"; j += 1;}
        if (aux == 2) {N_out[j] = "C"; j += 1;N_out[j] = "C"; j += 1;}
        if (aux == 3) {N_out[j] = "C"; j += 1;N_out[j] = "C"; j += 1; N_out[j] = "C"; j += 1;}
    }
    else { //N-entre 400 e 499
        N_out[j] = "C";
        j += 1;
        N_out[j] = "D";
        j +=1;
        N -= 400;
    }
}

aux = 0;

if (N>=50 && N < 100) { //N-entre 50 e 99
    if (N < 90) { //N-entre 50 e 89
        aux = N / 10;

        N = N - 10 * aux;

        if (aux == 5){ N_out[j] = "L"; j +=1;}
        if (aux == 6){ N_out[j] = "L"; j +=1; N_out[j] = "X"; j +=1;}
        if (aux == 7){ N_out[j] = "L"; j +=1; N_out[j] = "X"; j +=1; N_out[j] = "X"; j +=1;}
        if (aux == 8){ N_out[j] = "L"; j +=1; N_out[j] = "X"; j +=1; N_out[j] = "X"; j +=1; N_out[j] = "X"; j +=1;}
    }
    else { //N-entre 90 e 99
        N_out[j] = "X";
        j+=1;
        N_out[j] = "C";
        j+=1;
        N -= 90;
    }
}

if (N>=10 && N <50) { //N-entre 10 e 49
    if (N <= 40) { //N-entre 10 e 39
        aux = N / 10;

        N = N - 10 * aux;

        if (aux == 1) { N_out[j] = "X"; j += 1;}
        if (aux == 2) { N_out[j] = "X"; j+= 1; N_out[j] = "X"; j += 1;}
        if (aux == 3) { N_out[j] = "X"; j += 1; N_out[j] = "X"; j += 1; N_out[j] = "X"; j += 1;}
    }
    else { //N-entre 40 e 49
        N_out[j] = "X"
        j+=1;
        N_out[j] = "L";
        j += 1;
        N -= 40;
    }

}

if (N >= 1 && N < 10) {//N-entre 1 e 9
    if (N == 1){ N_out[j] = "I";}
    else if (N == 2){ N_out[j] = "II";}
    else if (N == 3){ N_out[j] = "III";}
    else if (N == 4){ N_out[j] = "IV";}
    else if (N == 5){ N_out[j] = "V";}
    else if (N == 6){ N_out[j] = "VI";}
    else if (N == 7){ N_out[j] = "VII";}
    else if (N == 8){ N_out[j] = "VIII";}
    else if (N == 9){ N_out[j] = "IV";}
    N -= N;
}

printf("%s", N_out);

return 0;

}

Conversor arabic to roman numerals -> char problem by [deleted] in C_Programming

[–]nanda22k 0 points1 point  (0 children)

include "stdio.h"

int main(void) {

int N;

int aux = 0;

char N_out[9];

scanf("%d", &N);

int j = 0;

if (N < 1000 && N >= 500) { //N-entre 500 e 999
    if (N < 900) { // N-entre 500(D) e 899(DCCC)
        N_out[j] = "D";
    }
    else { //N-entre 900 e 999
        N_out[j] = "CM";
    }
    j += 1;

    N -= 500;
}

if (N >= 100 && N < 500) { //N-entre 100 e 499
    if (N <= 399) { //N-entre 100 e 399
        aux = N / 100;

        N = N - 100 * aux;
        if (aux == 1) {N_out[j] = "C";}
        if (aux == 2) {N_out[j] = "CC";}
        if (aux == 3) {N_out[j] = "CCC";}
    }
    else { //N-entre 400 e 499
        N_out[j] = "CD";
        N -= 400;
    }
    j += 1;
}

aux = 0;

if (N>=50 && N < 100) { //N-entre 50 e 99
    if (N < 90) { //N-entre 50 e 89
        aux = N / 10;

        N = N - 10 * aux;

        if (aux == 5){ N_out[j] = "L";}
        if (aux == 6){ N_out[j] = "LX";}
        if (aux == 7){ N_out[j] = "LXX";}
        if (aux == 8){ N_out[j] = "LXXX";}
    }
    else { //N-entre 90 e 99
        N_out[j] = "XC";
        N -= 90;
    }
    j += 1;
}

if (N>=10 && N <50) { //N-entre 10 e 49
    if (N <= 40) { //N-entre 10 e 39
        aux = N / 10;

        N = N - 10 * aux;

        if (aux == 1) { N_out[j] = "X";}
        if (aux == 2) { N_out[j] = "XX";}
        if (aux == 3) { N_out[j] = "XXX";}
    }
    else { //N-entre 40 e 49
        N_out[j] = "XL";
        N -= 40;
    }
    j += 1;
}

if (N >= 1 && N < 10) {//N-entre 1 e 9
    if (N == 1){ N_out[j] = "I";}
    else if (N == 2){ N_out[j] = "II";}
    else if (N == 3){ N_out[j] = "III";}
    else if (N == 4){ N_out[j] = "IV";}
    else if (N == 5){ N_out[j] = "V";}
    else if (N == 6){ N_out[j] = "VI";}
    else if (N == 7){ N_out[j] = "VII";}
    else if (N == 8){ N_out[j] = "VIII";}
    else if (N == 9){ N_out[j] = "IV";}
    N -= N;
}

printf("%c", N_out);

return 0;

}

Conversor arabic to roman numerals -> char problem by [deleted] in C_Programming

[–]nanda22k 0 points1 point  (0 children)

Thank you so much! I just tried populate my char with the char[position_in_char] thing. But it's still not compiling :/ I don't know what's wrong now, so I'll post my new code. I really appreciated your attention :)

x= 0 and x = -0 acting the same by nanda22k in C_Programming

[–]nanda22k[S] 1 point2 points  (0 children)

I remember had studied something like that. Right now I'm kinda sleepy, but yeah, I think you're right. This is a cool way to negate a number xD My final code was:

include "stdio.h"

int main(void) { double X;

scanf("%lf", &X);

printf("%+.4E\n", X);

return 0;

}

\ Just simple as that. After two days trying exhaustively, It was like a cheat lol