Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 6: Write a C++ program to sort all zeroes on right side of an array.

#include<iostream.h>
#include<conio.h>

void zero(int a[], int size)
{
	for( int i=0;i<size;i++)
	{
		int n=0;
		for(int m=0;m<i; m++)
		{
			if(a[m]==0)
			{
				for(int j=m;j<size-n-1;j++)
				{
					a[j]=a[j+1];
				}
				a[size-(n+1)]=0;
				n++;
			}
		}
	}

	cout<<"\nNew array :\n";
	for(i=0;i<size;i++)
	{
		cout<<a[i]<<"\t";
	}
}

void main()
{
	clrscr();
	int arr[10];
	cout<<"\nenter the elements of array:";

	for(int i=0; i<10;i++)
	{
		cin>>arr[i];
	}

	zero(arr,10);
	getch();
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.