C code blocks Write the complete function that receives a pointer to a single floating point number as an argument and returns that number after subtracting 100 from it. Define your function in the same way as the given function prototype. Take a look at the "For example" below to see how the function is used in the main function and the expected result. (For interest sake, note that this is a pass-by-reference function call.) #include #include void subtractFunc(float *a);int main(){ float num = 357.900; subtractFunc(&num); printf("%.3f", num); return 0; } //Your answer starts here For example: Test Result float num = 357.900; subtractFunc(&num); printf("%.3f", num); 257.900
C code blocks
Write the complete function that receives a pointer to a single floating point number as an argument and returns that number after subtracting 100 from it.
Define your function in the same way as the given function prototype.
Take a look at the "For example" below to see how the function is used in the main function and the expected result.
(For interest sake, note that this is a pass-by-reference function call.)
#include <stdlib.h>void subtractFunc(float *a);int main(){ float num = 357.900;
subtractFunc(&num);
printf("%.3f", num); return 0;
}
//Your answer starts here
For example:
Test | Result |
---|---|
float num = 357.900; subtractFunc(&num); printf("%.3f", num); | 257.900 |
#include <stdio.h>
#include <stdlib.h>
float subtractFunc(float *a); // Declaring float function for subtracting value and returning float value
int main()
{ float num = 357.900, sub; // Declaring sub variable to store value returned by function
sub=subtractFunc(&num); // Passing reference of actual value
printf("%.3f", sub); // Printing value after subtraction
return 0;
}
float subtractFunc(float *a)
{ float sub; // Variable to store value
sub = *a - 100; // Pointer variable have actual value and subtracting 100
return (sub); // return float value
}
I have done some sort of changes in the code to get the correct output. Like void replace to float for getting float value after subtraction.
Step by step
Solved in 2 steps with 1 images