Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 382135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:09:11+00:00 2026-05-12T15:09:11+00:00

Im trying to figure out how i can solve an equation that has been

  • 0

Im trying to figure out how i can solve an equation that has been stored in an array.
I need some guidance on how to conquer such problem.
here is my conditions

  • i have an array int X[30];
  • and in there i have stored my desired equation: 5+6*20/4
  • as well, i couldnt store the operants (+ / – * ) so i used different identifiers for them like ( -1 -2 -3 -4 ) because there should not be a negative value in the equation.

any help would be greatly appreciated

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T15:09:11+00:00Added an answer on May 12, 2026 at 3:09 pm

    Normally, you have to define the priority of each operation and process each of them one by one.

    
    First your expression is:        '`[ 5,-1, 6,-4,20,-2, 4]`'
    Do all '/' first:                '`[ 5,-1, 6,-4, 5,-1, 0]`' <- 20/ 4 =  5+0
    Then, do all '*':                '`[ 5,-1,30,-1, 0,-1, 0]`' <-  6* 5 = 30+0
    Then, do all '-':                '`[ 5,-1,30,-1, 0,-1, 0]`' <-  Nothing
    Then, do all '+' (sum positive): '`[35,-1, 0,-1, 0,-1, 0]`' <-  5+30+0+0 = 35 + 0 + 0
    

    ADDED: Here is the C code.

    void ShowArray(int pX[], int pLength) {
        int i;
        for(i = 0; i < pLength; i++)
            printf("%3d ", pX[i]);
        printf("\n");
    }
     
    void ShiftArray(int pX[], int pIndex, int pSkip, int pLength) {
        int i;
        for(i = pIndex; i < (pLength - pSkip); i++)
            pX[i] = pX[i + pSkip];
     
        for(i = (pLength - pSkip); i < pLength; i++)
            pX[i] = 0;
    }
     
    int main(void) {
        const int OPERCOUNT =  4;
        const int PLUS      = -1;  // -1 Do last
        const int SUBT      = -2;
        const int MULT      = -3;
        const int DIV       = -4;  // -4 Do first
     
        int X[]    = {5, PLUS, 6, MULT, 20, DIV, 4};
        int XCount = 7;
     
        ShowArray(X, XCount);
     
        int i;
        for(i = OPERCOUNT; --i >= 0; ) {
            int OPER = -(i + 1);
    
            int j = 0;
            for(j = 0; j < XCount; j++) {
                int x = X[j];
                if (x == OPER) {
                    if      (x == PLUS) X[j - 1] = X[j - 1] + X[j + 1];
                    else if (x == SUBT) X[j - 1] = X[j - 1] - X[j + 1];
                    else if (x == MULT) X[j - 1] = X[j - 1] * X[j + 1];
                    else if (x == DIV ) X[j - 1] = X[j - 1] / X[j + 1];
                    ShiftArray(X, j, 2, XCount);
                }
            }
     
            ShowArray(X, XCount);
        }
     
        int Sum = 0;
        int j;
        for(j = 0; j < XCount; j++) {
            int x = X[j];
            if (x > 0) Sum += x;
        }
        printf("Result: %d\n", Sum);
    }
    

    And here is the result:

      5  -1   6  -3  20  -4   4 
      5  -1   6  -3   5   0   0 
      5  -1  30   0   0   0   0 
      5  -1  30   0   0   0   0 
     35   0   0   0   0   0   0 
    Result: 35
    

    This should works.

    Enjoy coding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how I can listen to the Cancel button that
I am trying to figure out how I can define an autocmd that influences
I'm having some problems trying to figure out how to solve a problem without
I've been having troubles trying to figure out how to solve a function. I've
Got a really tricky problem that I've been trying to figure out for a
I'm having a hard time trying to figure out how to solve some jQuery
I have been spending the entire day trying to figure out how I can
I am trying to figure out how can I update the petevents table with
Trying to figure out how I can do this properly. The print_r looks like
I trying to figure out how I can delete from multiple tables in SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.