
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
C++ program to find minimum possible difference of largest and smallest of crackers
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.
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.
Steps
To solve this, we will follow these steps −
if n mod k is same as 0, then: return 0 Otherwise return 1
Example
Let us see the following implementation to get better understanding −
#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; }
Input
7, 3
Output
1
- Related Articles
- 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
- C# program to find Largest, Smallest, Second Largest, Second Smallest in a List
- Python program to find Largest, Smallest, Second Largest, and Second Smallest in a List?
- Program to find minimum possible difference of indices of adjacent elements in Python
- Program to find minimum largest sum of k sublists in C++
- C++ program to find smallest and largest number of children in game before start
- C++ Program to find minimum possible unlancedness of generated string T
- C++ program to find minimum possible number of keyboards are stolen
- Java program to find Largest, Smallest, Second Largest, Second Smallest in an array
- Program to find Smallest and Largest Word in a String in C++
- C++ Program to find minimum possible ugliness we can achieve of towers
- C program to find the second largest and smallest numbers in an array
- Program to find maximum possible value of smallest group in Python
- C++ Program to find maximum possible smallest time gap between two pair of clock readings

Advertisements