Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. (20 points) Here are four C programs to translate binary to decimal; that is, you run './pb 101 ' and it will print '

image text in transcribed

2. (20 points) Here are four C programs to translate binary to decimal; that is, you run './pb 101 ' and it will print ' 5 '. For each program, indicate whether it works. If it does not, show how to fix it by changing the fewest characters possible. Note that these programs will crash if not given an argument; that's not considered an error per the design spec. Program A Works as is. Needs fixing. \#include \#include \#include int main(int argc,charargv[]) \{ int val=0; // warning: assumes argv[1]! int len =strlen(argv[1]); for (int i=0;i=1; if (argv[1][i]==1, ) val=1; \} printf("d ", val); \} Program B Works as is. Needs fixing. \#include \#include \#include int main(int argc,charargv[]) \{ int val=0; // warning: assumes argv[1]! int len =strlen(argv[1]); for (int i=0;i=0; i--) \{ if (argv[1][i]==1 ', val =1 len - i; \} printf("\%d ", val); \} Program D Works as is. Needs fixing. \#include \#include \#include int main(int argc,charargv[]) \{ int val=0; // warning: assumes argv[1]! int len =strlen(argv[1])1; for (int i=1 len; i>0; i--) \{ val+=(argv[1][i]0 ' )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions