How to round a number to a multiple of 5 in C

1 Answer

0 votes
#include <stdio.h>
#include <math.h>
  
unsigned int roundToMultipleOf(unsigned int number, unsigned int multipleOf) {
    return multipleOf * floor(number / multipleOf);
}
  
int main() {
  printf("%d\n", roundToMultipleOf(9, 5));
  printf("%d\n", roundToMultipleOf(19, 5));
  printf("%d\n", roundToMultipleOf(71, 5));
  
  return 0;
}
  
  
  
/*
run:
  
5
15
70
  
*/

 



answered Jun 8, 2024 by avibootz

Related questions

1 answer 80 views
1 answer 74 views
1 answer 93 views
1 answer 84 views
2 answers 118 views
1 answer 110 views
1 answer 111 views
...