C++ program to find minimum possible difference of largest and smallest of crackers

C++Server Side ProgrammingProgramming

<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 &minus;</p><pre class="prettyprint notranslate">if n mod k is same as 0, then: &nbsp; &nbsp;return 0 Otherwise &nbsp; &nbsp;return 1</pre><h2>Example</h2><p>Let us see the following implementation to get better understanding &minus;</p><pre class="demo-code notranslate language-cpp" data-lang="cpp">#include &lt;bits/stdc++.h&gt; using namespace std; int solve(int n, int k){ &nbsp; &nbsp;if (n % k == 0){ &nbsp; &nbsp; &nbsp; return 0; &nbsp; &nbsp;} else{ &nbsp; &nbsp; &nbsp; return 1; &nbsp; &nbsp;} } int main(){ &nbsp; &nbsp;int N = 7; &nbsp; &nbsp;int K = 3; &nbsp; &nbsp;cout &lt;&lt; solve(N, K) &lt;&lt; endl; }</pre><h2>Input</h2><pre class="result notranslate">7, 3</pre><h2>Output</h2><pre class="result notranslate">1</pre>
raja
Updated on 03-Mar-2022 07:13:47

Advertisements