Answer to Question #266060 in C++ for chitti

Question #266060

Given a three-digit integer N and an integer K, returns the maximum possible three-digit value that can be obtained by performing at most K increases by 1 of any digit in N.

1
Expert's answer
2021-11-15T00:23:29-0500
#include<iostream>
#include<string>
#include <sstream>
using namespace std;


int maximum(int N, int k){
	string str = to_string(N);
	int a = str[0]- 48;
	for(int i=1; i<=k; i++){
		a = a + 1;
	}
	
	int b = str[1] - 48;
	int c = str[2] - 48;
	
	string res = to_string(a) +""+to_string(b)+""+to_string(c);
	
	stringstream answer(res);
	 int x = 0;
    answer >> x;
    
    return x;
	
}
int main(){
int n = 445;
cout<<"The maximum possible value is: "<<maximum(n,4)<<endl;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS