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 8160695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:19:56+00:00 2026-06-06T18:19:56+00:00

1 x 2 0 +1 x 2 1 + 1 x 2 2 +

  • 0

1 x 20 +1 x 21 + 1 x 22 + 0 x 23 +1 x 24 = 1 + 2 x (1 + 2 x (1 + 2 x (0 + 2 x 1) ) )

Recall b[0] = 1, b[1] = 1, b[2] = 1,b[3] = 0, b[4] = 1

/* to convert a binary representation to a decimal one*/

int dec, b[5] = {1, 1, 1, 0, 1};
dec = b[4];
for (int i = 3; i >= 0; i--)
{
    dec=2 * dec + b[i];  //horner's scheme
}
cout << dec << endl;

I tried to write this code again in C language, but it’s not working correctly:

#include<stdio.h>

int main()
{
    int B[5];
    int x, s, s1;

    for(int i = 1;i <= 5; i++)
    {
        printf("Enter %d. digit of binary number", i);
        scanf("%d", &B[i]);
    }


    s = B[5];   /*this part for reverse the array*/
    B[5] = B[1];
    B[1] = s;

    s1 = B[4];
    B[4] = B[2];
    B[2] = s1; 

    x = B[4];

    for (int i = 3; i >= 0; i--)
    {
        x = 2 * x + B[i];  
    }

    printf("%d", x);
    scanf("%d");
}
  • 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-06-06T18:19:58+00:00Added an answer on June 6, 2026 at 6:19 pm

    This is your initial loop where you initialise the array B

        int B[5];
        int x,s,s1;
        for(int i=1;i<=5;i++) {
        printf("Enter %d. digit of binary number",i);
        scanf("%d",&B[i]);}
    

    which is bad as you are accessing element B[5] which is outside the bounds of your array anyway, but also you are never initialising B[0] which you use in your second loop

        x=B[4];
        for (int i=3;i>=0;i--)
        {
            x=2*x+B[i];  
        }
    

    try changing your first loop to

        for(int i=0;i<5;i++) {
            printf("Enter %d. digit of binary number",i);
            scanf("%d",&B[i]);
        }
    

    and see if this gives the result you expect.

    Also this code

        s=B[5];   /*this part for reverse the array*/
        B[5]=B[1];
        B[1]=s;
    
        s1=B[4];
        B[4]=B[2];
        B[2]=s1;
    

    has problems, because you declared B as an array of 5 integers and since arrays have zero based indices, the only values for an index that are valid are from 0 to 4. If you want to reverse the array correctly replace your code with

        s=B[4];   /*this part for reverse the array*/
        B[4]=B[0];
        B[0]=s;
    
        s1=B[3];
        B[3]=B[1];
        B[1]=s1;
    

    You must not access B[5] as this is outside the bounds of your array !!!!

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

Sidebar

Related Questions

I recall that there was this one method that could piece together an image,
This should be a simple question, but I just can't recall the relevant API.
I know this is simple, I just can't recall the best way to do
I vaguely recall seeing this before in an answer to another question, but searching
Say two clients machines recall a ticket. If one client makes a change, what
I don't recall this information being immediately accessible. Last month I read In Google's
I feel like this one has been asked before, but I'm unable to find
I recall doing this before but I just can't remember how I did it,
I recall that one should always avoid using recursive method calls in Java .
This relates to a project to convert a 2-way ANOVA program in SAS to

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.