[ Write in C not C++]
Define a C function int round10(double n) that returns the
closest integer of n which is
divisible by 10. For example, if n = 16.0, the return value is 20
and if n = 32.34, the return
value is 30.
#include <stdio.h> int round10(double n){ int k = n; int n1 = ((k+10)/10)*10; int n2 = (k/10)*10; if((n1-n)<(n-n2)){ return n1; } else{ return n2; } } int main() { printf("%d\n",round10(16.0)); printf("%d\n",round10(32.34)); return 0; }
int round10(double n){ int k = n; int n1 = ((k+10)/10)*10; int n2 = (k/10)*10; if((n1-n)<(n-n2)){ return n1; } else{ return n2; } }
Get Answers For Free
Most questions answered within 1 hours.