I'm trying to put c code together to convert up to a 5 digit binary to decimal . I keep getting wrong answers : here's my c code so far . Can you please explain throughly as I am a begginer .      #include <stdio.h>   int main()   {     int a1, b1, c1, d1, e1, n1, decimal;     printf( "Enter a five-digit integer in 1's and 0's\n" );     scanf("%d", &n1 );     a1= n1 % 10;     b1= n1 / 10 % 10;     c1= n1 / 100 % 10;     d1= n1 / 1000 % 10;     e1= n1 / 10000;     decimal = a1 + b1 + c1 + d1 + e1;     printf("\nThe decimal equivalent of given binary number %d is: %d\n", n1,decimal);     return 0;   }

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 22SA
icon
Related questions
Question

I'm trying to put c code together to convert up to a 5 digit binary to decimal . I keep getting wrong answers : here's my c code so far . Can you please explain throughly as I am a begginer . 

 

 

#include <stdio.h>

 

int main()

 

{

 

  int a1, b1, c1, d1, e1, n1, decimal;

 

  printf( "Enter a five-digit integer in 1's and 0's\n" );

 

  scanf("%d", &n1 );

 

  a1= n1 % 10;

 

  b1= n1 / 10 % 10;

 

  c1= n1 / 100 % 10;

 

  d1= n1 / 1000 % 10;

 

  e1= n1 / 10000;

 

  decimal = a1 + b1 + c1 + d1 + e1;

 

  printf("\nThe decimal equivalent of given binary number %d is: %d\n", n1,decimal);

 

  return 0;

 

}

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning