given n=512 and k=10, the function should return 972 . the result can be obtained by increasing the first digit of n four times aand the second digit six times
Answers
Answered by
7
Answer:
def solution(N,K):
res=[int(i) for i in str(N)]
# print(res)
kb = K
new = []
for i in res:
dum = i
while(dum!=9):
if kb == 0:
break;
else:
dum+=1
kb-=1
# print(dum)
new.append(dum)
print(new)
solution(512,10)
Explanation:
Answered by
0
Answer:
#include <iostream>
using namespace std;
int main() {
int i, n=512, k=10, c=1;
int a[3];
for(i=2;i>=0;i--)
{
a[i]= n%10;
n=n/10;
}
while(c<5)
{
a[0]+=1;
}
c=k-c;
while(c<7)
{
a[1]+=1;
}
for(i=0;i<3;i++)
{
cout<<a[i];
}
return 0;
}
Explanation:
- We start by declaring the necessary variables.
- Next, separate the digits of 512 and store them in an array.
- Take the first digit and increment its value four times.
- Then take the second number and increment its value six times.
- Print the new number as the output.
#SPJ3
Similar questions