TheFestFever.com

Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 7: Write a C++ program to convert 1D array to 2D array.

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

void change(int a[],int size)
{
	int arr[6][6];
	for(int i=0;i<size;i++)
	{
		for(int j=0;j<size;j++)
		{
			if(j<size-i)
			arr[i][j]=a[j];
			else
			arr[i][j]=0;
		}
	}

	for(i=0;i<size;i++)
	{
		for(int j=0;j<size;j++)
		{
			cout<<arr[i][j]<<"\t";
		}
		cout<<"\n";
	}
}

void main()
{
	clrscr();
	int x[]={1,2,3,4,5,6};
	change(x,6);
	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.