98 718
Assignments Done
98.6%
Successfully Done
In April 2021

# Answer to Question #31529 in C++ for ashish

Question #31529
We are given an array of integer and we have to equalise all the elements in minimum no. Of steps but there are constraint in following steps:
1. We can increase all the elements by 5 except the chosen one
2. We can increase all he elements by 2 except the chosen one
3. We can increase all the elements by 1 except the chosen one
1
2013-06-04T08:37:30-0400
#include <iostream>
#include <conio.h>

using namespace std;

//main function
int main()
{
//array of integer
int arrayofinteger[5];
arrayofinteger[0]=5;
arrayofinteger[1]=10;
arrayofinteger[2]=15;
arrayofinteger[3]=2;
arrayofinteger[4]=3;
//find max number
int max=arrayofinteger[0];
for(int i=0;i<5;i++){
if(arrayofinteger[i]>max){
max=arrayofinteger[i];
}
}

for(int i=0;i<5;i++){
//1. We can increase all the elements by 5 except the chosen one
int diff=max-arrayofinteger[i];
if(diff==5){
arrayofinteger[i]+=5;
}
diff=max-arrayofinteger[i];
//2. We can increase all he elements by 2 except the chosen one
if(diff==2){
arrayofinteger[i]+=2;
}
diff=max-arrayofinteger[i];
//3. We can increase all the elements by 1 except the chosen one
if(diff==1){
arrayofinteger[i]+=1;
}else{
arrayofinteger[i]+=diff;
}
}
//show result
for(int i=0;i<5;i++){
cout<<arrayofinteger[i]<<"
";
}
int k;
cin>>k;
return 0;
}

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!