Answer to Question #182282 in C for anonymous456

Question #182282

challenge.h 

#include <stdio.h>

float foo(float F); 

float bar(float F);



main.c 

#include "challenge.h"

float a = 6.8;

int main() {

 float fa = foo(a);

 float ba = bar(a);

 printf(“%.1f\n”, fa + ba);

 return 0;

}


challenge.c

#include "challenge.h"

extern float a;

float foo(float F) {

 a = 2.6;

 return F * a

}


challenge2.c

#include "challenge.h"

static float a;

float bar(float F) {

 a = 5.2;

 return foo(F) * a;

}


Given the source code above and we use "gcc main.c challenge.c challenge2.c -o challenge" to compile it. What's the output when we type ./challenge


1
Expert's answer
2021-04-16T11:59:25-0400

The output is: 52.8


However, there are some mistakes in the code above that need to be fixed to compile that code without receiving an error.


First of all, the semicolon is missing in the end of return statement in challenge.c file. Secondly, it is better to replace double quotation marks (“ ”) in printf function in main.c file like this : printf("%.1f\n", fa + ba); (in order to avoid compile error).


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS