Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,955 questions

51,897 answers

573 users

How to calculate the next multiple of 10 in C++

1 Answer

0 votes
#include <iostream>

int next_multiple_of_10(int n) {
    return (n % 10 == 0) ? n + 10 : n + (10 - n % 10);
}
 
int main() {
    int nums[] = {23, 10, 0, 1841};
    int length = sizeof(nums) / sizeof(nums[0]);
 
    for (int i = 0; i < length; i++) {
        std::cout << next_multiple_of_10(nums[i]) << "\n";
    }
}
  
  
 
/*
run:
 
30
20
10
1850

*/

 



answered Nov 22, 2024 by avibootz
edited Nov 22, 2024 by avibootz

Related questions

1 answer 57 views
1 answer 65 views
1 answer 68 views
1 answer 63 views
1 answer 71 views
1 answer 68 views
1 answer 74 views
...