Sie sind auf Seite 1von 8

Write a user-defined function named Upperr_half() which takes 2D array A, with size N rows and N

columns as argument and prints the lower half of the array

Eg.Input

23150

71531

25781

01501

34915

the output will be

23150

1531

781

01

Ans.

void Upper_half(int a[10][10],int n)

int i,j;

for(i=0;i<n;i++)

{ cout<<endl;

for(j=0;j<n;j++)

if(i<=j)

cout<<a[i][j]<<" ";

else

cout<< ;

Write UDF in C++ which accepts an integer array and its size as arguments/ parameters and assign the
elements into a 2 D array of integers in the following format:
If the array is 1,2,3,4,5.

The resultant 2D array is given below

10000

12000

12300

12340

12345

Ans:

void assign_lower_half(int a[10],int n)

int b[10][10],i,j;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

if(i>=j)

b[i][j]=a[j];

else

b[i][j]=0;

for(i=0;i<n;i++)

{ cout<<endl;

for(j=0;j<n;j++)

cout<<b[i][j]<<" ";

Write function in C++ which accepts an integer array and size as arguments and assign values into a 2D
array of integers in the following format :

If the array is 1, 2, 3, 4, 5, 6

The resultant 2D array is given below


123456

123450

123400

123000

120000

100000

Ans:

void r_upper_half(int a[10],int n)

{ int b[10][10],i,j;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

if(i+j<=n-1)

b[i][j]=a[j];

else

b[i][j]=0;

for(i=0;i<n;i++)

{ cout<<endl;

for(j=0;j<n;j++)

cout<<b[i][j]<<" ";

Write a function in C++ which accepts an integer array and its size as arguments/ parameters and then
assigns the elements into a two dimensional array of integers in the following format:

Ans.

void r_lower_half(int a[10],int n)


{

int b[10][10],i,j,k=n-1;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

if(i+j>=n-1)

b[j][i]=a[k];

else

b[i][j]=0;

k--;

for(i=0;i<n;i++)

{ cout<<endl;

for(j=0;j<n;j++)

cout<<b[i][j]<<" ";

Write a function in C++ which accepts an integer array and its size as arguments/parameters and assigns
the elements into a two dimensional array of integers in the following format.

if the array is 9,8,7,6,5,4 . The resultant 2D array is given below

if the array is 1, 2, 3. The resultant 2D array is given below

Ans:

void r_upper_half(int a[10],int n)

int b[10][10],i,j;

for(i=0;i<n;i++)

{
for(j=0;j<n;j++)

if(i+j<=n-1)

b[i][j]=a[i];

else

b[i][j]=0;

for(i=0;i<n;i++)

{ cout<<endl;

for(j=0;j<n;j++)

cout<<b[i][j]<<" ";

Write a function in C++ which accepts a integer array and its size as an arguments and prints the output
(using nested loops) in following format :

Example : if the array is having1 2 4 5 7. Then the output should be

22

4444

55555

7777777

Ans.

void r_lower_half(int a[10],int n)

int i,j;

for(i=0;i<n;i++)

{ cout<<endl;

for(j=1;j<=a[i];j++)

cout<<a[i]<< " ";

}
}

Write a function in C++ which accepts an integer array and its size as arguments/parameters and assign
the elements into a two dimensional array of integers in the following format (size must be odd)

If the array is 1 2 3 4 5 . The output must be

10005

02040

00300

02040

10005

If the array is 10 15 20. The output must be

10 0 20

0 15 0

10 0 20

Ans:

void diagonal(int a[10],int n)

int b[10][10],i,j,k1=0,k2=n-1;

for(i=0;i<n;i++)

for(j=0;j<n;j++)

if(i==j)

b[i][j]=a[k1];

k1++;

if(i+j==n-1)

b[i][j]=a[k2];

k2--;
}

if(i!=j&&i+j!=n-1)

b[i][j]=0;

for(i=0;i<n;i++)

{ cout<<endl;

for(j=0;j<n;j++)

cout<<b[i][j]<<" "; }

Write a function in c++ which accepts a 2D array of integers, number of rows and number of columns as
arguments and assign the elements which are divisible by 3 or 5 into a one dimensional array of
integers.

If the 2D array is

The resultant 1D arrays is 12 , 3 , 9 , 24 , 25 , 45 , 9 , 5 , 18

Ans.

void assign2dto1d(int a[10][10],int m,int n)

int b[10],i,j,k=0;

for(i=0;i<m;i++)

for(j=0;j<n;j++)

if(a[i][j]%3==0||a[i][j]%5==0)

b[k]=a[i][j];

k++;

cout<<"\nThe resultant 1D array is :";


for(i=0;i<k;i++)

{ cout<<b[i]<<" ";}

Write a function in C++ which accepts a

Das könnte Ihnen auch gefallen