So i wrote a small and basic program where i had to read n, a and b.
In the program i am supposed to find how to write n as a sum of numbers that are equal to a or b.
But the number of a’s should be maximum. Now when i tried to read the numbers n, a and be with cin it kept reading n.(I introduced a number and pressed enter and it was still waiting for a prompt infinitely)
So here is my program:
#include <iostream>
using namespace std;
int n, a, b, nrb;
int main() {
cin >> n;
while(n % a != 0) {
n -= b;
nrb++;
}
for(int i = a; i <= n; i++) {
cout << a << ' ';
}
for(int i = 1; i <= nrb; i++) {
cout << b << ' ';
}
}
Anoni moni is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
7