#include%26lt;iostream.h%26gt;
#define n 8
void disp(int[]);
void main()
{
int a[n]={1,2,3,4,5,6,7,8};
int i, j, k=1;
i=n/2;
j=i;
k=j-1;
int save=a[n-2];
cout%26lt;%26lt;save%26lt;%26lt;" "%26lt;%26lt;a[n-3]%26lt;%26lt;endl;
disp(a);
cout%26lt;%26lt;endl;
cout%26lt;%26lt;save%26lt;%26lt;"a"%26lt;%26lt;endl;//correct value upto his point.
while(i%26gt;0)
{
cout%26lt;%26lt;"**** save *****"%26lt;%26lt;save %26lt;%26lt;endl;
a[i+i]=a[i];
i--;
}
cout%26lt;%26lt;save%26lt;%26lt;"b"%26lt;%26lt;endl;//value changes here. why?
while(j%26lt;n)
{
a[j-k]=a[j];
j++;
k--;
}
cout%26lt;%26lt;save%26lt;%26lt;" "%26lt;%26lt;a[n-3]%26lt;%26lt;endl;
a[n-3]=save;
disp(a);
}
void disp(int a[])
{
for(int i=0; i%26lt;n; i++)
{
cout%26lt;%26lt;a[i];
}
}
Plz point out the problem with the following code in C++?
I have just compiled and executed your program. The value of "save" does not change. So what's your problem exactly?
Reply:the problem that is causing problem is value of n
the alternative to use it is
redefine the disp(a[])function by disp(int a[],int size_of_a)
which will be the size of array a
but it is of quite consideration the value of save is not changing if you could explain what the purpose of program is i may provide better answer
Reply:You will never get what you wants due to bad indentation. Good luck!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment