

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ program to find minimum possible difference of largest and smallest of crackers
<p>Suppose we have two numbers N and K. We want to distribute N crackers to K users. We have to find the minimum possible difference between the largest number of crackers received by a user and smallest number received by a user.</p><p>So, if the input is like N = 7; K = 3, then the output will be 1, because when the users receive two, two and three crackers, respectively, the difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.</p><h2>Steps</h2><p>To solve this, we will follow these steps −</p><pre class="prettyprint notranslate">if n mod k is same as 0, then: return 0 Otherwise return 1</pre><h2>Example</h2><p>Let us see the following implementation to get better understanding −</p><pre class="demo-code notranslate language-cpp" data-lang="cpp">#include <bits/stdc++.h> using namespace std; int solve(int n, int k){ if (n % k == 0){ return 0; } else{ return 1; } } int main(){ int N = 7; int K = 3; cout << solve(N, K) << endl; }</pre><h2>Input</h2><pre class="result notranslate">7, 3</pre><h2>Output</h2><pre class="result notranslate">1</pre>
- Related Questions & Answers
- Program to find minimum difference between largest and smallest value in three moves using Python
- Program to find k-sized list where difference between largest and smallest item is minimum in Python
- Program to find minimum possible difference of indices of adjacent elements in Python
- Python program to find Largest, Smallest, Second Largest, and Second Smallest in a List?
- C# program to find Largest, Smallest, Second Largest, Second Smallest in a List
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array
- Program to find maximum possible value of smallest group in Python
- C++ program to find smallest and largest number of children in game before start
- Program to find minimum largest sum of k sublists in C++
- C++ Program to find minimum possible unlancedness of generated string T
- C++ program to find minimum possible number of keyboards are stolen
- Program to find Smallest and Largest Word in a String in C++
- C++ Program to find minimum possible ugliness we can achieve of towers
- Find the average of all elements of array except the largest and smallest - JavaScript
- Find the difference of largest and the smallest number in an array without sorting it in JavaScript
Advertisements