Do not call any library functions and use C language Programmers who write embed
ID: 3666544 • Letter: D
Question
Do not call any library functions and use C language
Programmers who write embedded-system code must sometimes avoid using floating-point operations. Hardware floating-point units (FPU) tend to be relatively large and expensive, and many microcontrollers don't have them. We could implement floating-point operations in software, but usually we can write code that is much less costly in terms of time and battery life by restricting ourselves to integer operations. Write a C function that converts an integer representing kilopascal to an integer representing psi. Your program should round its result to the nearest psi. You may not use floating-point arithmetic or C math libraries. The rounding problem is trickier than it may seem at first, because different rules are needed for positive and negative values, and because you may only use integer operations. Function name: kPtoPSI Description: Perform kiloPascal-to-psi conversion, using integer operations only. Input parameters: P, the corresponding value in kiloPascal. Returns: The input value in psi. int kPtoPSI (int P);Explanation / Answer
#include<stdio.h>
long convert(long);
main()
{
long kilo, psi;
scanf("%ld", &kilo);
psi= convert(kilo);
printf("%ld ", psi);
return 0;
}
long convert(long a)
{
long result;
/* 1 Kilopascal = 0.14503773773 Psi */
result = a * 0.14503773773 ;
return result;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.