63 043
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #3753 in C++ for Abilashini nadaraj

Question #3753
10,33," "," ",33," ",29,22," ",11," " ," ",92," ",56," ",51
an algoryihm needs to developed to shift all blank values to the end of the array.
Expert's answer
#include <iostream>

using namespace std;

void main()
{
char a[] = {'1', '2', ' ', '4', ' ', ' ', '7'};
int n = sizeof(a)/sizeof(char);
char tmp;
for (int i = 0; i < n; i++) // looking for the next blank
{
& if (a[i] == ' ')
& {
& for (int j = i; j < n; j++) // looking for the next non-blank to switch
& {
& if (a[j] != ' ')
& {
& // make switch
& tmp = a[j];
& a[j] = a[i];
& a[i] = tmp;
& }
& }

& }
& cout << a[i] << 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

Assignment Expert
03.08.11, 21:49

Welcome!

abilashini nadarj
03.08.11, 10:07

Thank you for responding my question i will soon execute this and let u know whether this is right output i expected .

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions