SlideShare a Scribd company logo
Q1. Define a function shift() to shift all odd elements towards left and even to right without changing order of numbers.<br />Example: If input: 1,5,7,8,9,2,10<br />Output: 1,5,7,9,8,2,10.<br />Ans:<br />void shift(int a[10],int n)<br />{<br />int b[10],i,k=0;<br /> for(i=0;i<n;i++)<br />{<br />if(a[i]%2= =1)<br />{<br />  b[k]=a[i];<br />  k++;<br />  }<br />  }<br />  for(i=0;i<n;i++)<br />  { if(a[i]%2= =0)<br />  { b[k]=a[i];<br />    k++;<br />    }<br />    }<br />   for(i=0;i<n;i++)<br />   cout<<b[i]<<\"
 \"
;<br />     }<br />Q2.  Given two arrays A and B. Array ‘A’ contains all the elements of ‘B’ but one more element extra. Write a c++ function which accepts array A and B and its size as arguments/ parameters and find out the extra element in Array A. (Restriction: array elements are not in order)<br /> Example : - If Array A is {14, 21, 5, 19, 8, 4, 23, 11} and Array B is {23, 8, 19, 4, 14, 11, 5 } Then output will be 21 (extra element in Array A)<br /> Ans:<br />         void extra(int a[10],int m,int b[10],int n)<br />            {<br />            int i,j,flag;<br />            for(i=0;i<m;i++)<br />            { flag=0;<br />            for(j=0;j<n;j++)<br />            if(a[i]==b[j])<br />            { flag=1;<br />            break;<br />            }<br />            if(flag==0)<br />            cout<<a[i]<<\"
 is the extra element\n\"
;<br />            }<br />            }<br />Q3.  Write C++ function to Arrange(int [],int) to arrange all the negative and positive numbers from left to right.<br />        Example : - If an array of 10 elements initially contains { 4,5,6,-7,8,-2,-10,1,13,-20} . Then the function rearrange them in following manner { -20,-10,-7,-2 1,4,5,6,8,13}<br />        Ans:<br />           void arrange(int a[10],int n)<br />            {<br />            int i,j,temp;<br />            for(i=0;i<n;i++)<br />            { for(j=0;j<n-1;j++)<br />            if(a[j]>a[j+1])<br />            { temp=a[j];<br />            a[j]=a[j+1];<br />            a[j+1]=temp;<br />            }<br />            }<br />            for(i=0;i<n;i++)<br />            cout<<a[i]<<\"
 \"
;<br />            }<br />Q4. Write a user defined function in C++ to find and display the row sums of a two dimensional array.<br />        Ans:<br />            void rowsum(int a[10][10],int m,int n)<br />            {<br />            int i,j,rsum;<br />            for(i=0;i<m;i++)<br />            { rsum=0;<br />            for(j=0;j<n;j++)<br />            rsum+=a[i][j];<br />            cout<<\"
\nSum of row \"
<<i+1<<\"
 is -\"
<<rsum;<br />            }<br />            }<br />Q5. Write a user defined function in C++ to find and display the column sums of a two dimensional array.<br />        Ans:<br />            void columnsum(int a[10][10],int m,int n)<br />            {<br />            int i,j,csum;<br />            for(i=0;i<n;i++)<br />            { csum=0;<br />            for(j=0;j<m;j++)<br />            csum+=a[j][i];<br />            cout<<\"
\nSum of column \"
<<i+1<<\"
 is ->\"
<<csum;<br />            }<br />            }<br />Q6. Write a function in C++ to print the product of each row of a two dimensional array passed as the arguments of the function<br />        Ans:<br />            void rowproduct(int a[10][10],int m,int n)<br />            {<br />            int i,j,rp;<br />            for(i=0;i<m;i++)<br />            { rp=1;<br />            for(j=0;j<n;j++)<br />            rp*=a[j][i];<br />            cout<<\"
\nProduct of row \"
<<i+1<<\"
 is ->\"
<<rp;<br />            }<br />            }<br />Q7. Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements which lie on diagonals. [Assuming the 2D Array to be a square matrix with odd dimension i.e. 3×3, 5×5, 7×7 etc.] Example, if the array content is<br />            5 4 3<br />            6 7 8<br />            1 2 9<br />        Output through the function should be: Diagonal 1 : 5 7 9 Diagonal 2 : 3 7 1<br />        Ans:<br />            void diagonal(int a[10][10],int m,int n)<br />            {<br />            int i,j;<br />            cout<<\"
\nDiagonal 1:\"
;<br />            for(i=0;i<m;i++)<br />            { for(j=0;j<n;j++)<br />            if(i==j)<br />            cout<<a[i][j]<<\"
 \"
;<br />            }<br />            cout<<\"
\n\nDiagonal 2:\"
;<br />            for(i=0;i<m;i++)<br />            { for(j=0;j<n;j++)<br />            if(i+j==n-1)<br />            cout<<a[i][j]<<\"
 \"
;}<br />            }<br />Q8.  Write a user defined function in C++ which accepts a squared integer matrix with odd dimensions (3*3, 5*5 …) & display the square of the elements which lie on both diagonals. For ex. :<br />            2 5 7<br />            3 7 2<br />            5 6 9<br />        The output should be :<br />        Diagonal one : 4, 49, 81<br />        Diagonal two : 49, 49, 25<br />        Ans:<br />            void diagonalsquare(int a[10][10],int m,int n)<br />            {<br />            int i,j;<br />            cout<<\"
\nDiagonal one :\"
;<br />            for(i=0;i<m;i++)<br />            { for(j=0;j<n;j++)<br />            if(i==j)<br />            cout<<a[i][j]*a[i][j]<<\"
,\"
;}<br />            cout<<\"
\n\nDiagonal two:\"
;<br />            for(i=0;i<m;i++)<br />            { for(j=0;j<n;j++)<br />            if(i+j==n-1)<br />            cout<<a[i][j]*a[i][j]<<\"
,\"
;<br />            }<br />            }<br />Q9.Write a user defined function in C++ which accepts a squared integer matrix with odd dimensions (3*3, 5*5..) & display the sum of the middle row & middle column elements. For ex. :<br />      <br />            2 5 7<br />            3 7 2<br />            5 6 9<br />        The output should be :<br />        Sum of middle row = 12<br />        Sum of middle column = 18<br />        Ans:<br />            void middlesum(int a[10][10],int m,int n)<br />            {<br />            int i,j,mrsum=0,mcsum=0;<br />            for(i=0;i<n;i++)<br />            mrsum+=a[m/2][i];<br />            cout<<\"
\nSum of middle row=\"
<<mrsum; for(i=0;i<m;i++)<br />            mcsum+=a[i][n/2];<br />            cout<<\"
\nSum of middle column=\"
<<mcsum;<br />            }<br />Q10. Write a user-defined function named Lower_half() which takes 2D array A, with size N rows and N columns as argument and prints the lower half of the array.<br />        Eg. Input<br />            2 3 1 5 0<br />            7 1 5 3 1<br />            2 5 7 8 1<br />            0 1 5 0 1<br />            3 4 9 1 5<br />        the output will be<br />            2<br />            7 1<br />            2 5 7<br />            0 1 5 0<br />            3 4 9 1 5<br />        Ans:<br />            void lower_half(int a[10][10],int n)<br />            {<br />            int i,j;<br />            for(i=0;i<n;i++)<br />            { cout<<endl;<br />            for(j=0;j<n;j++)<br />            if(i>=j)<br />            cout<<a[i][j]<<\"
 \"
;<br />            }<br />            }<br />Q11.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:<br />    Ans.<br />        void r_lower_half(int a[10],int n)<br />        {<br />        int b[10][10],i,j,k=n-1;<br />        for(i=0;i<n;i++)<br />        {<br />        for(j=0;j<n;j++)<br />        if(i+j>=n-1)<br />        b[j][i]=a[k];<br />        else<br />        b[i][j]=0;<br />        k--;<br />        }<br />        for(i=0;i<n;i++)<br />        { cout<<endl;<br />        for(j=0;j<n;j++)<br />        cout<<b[i][j]<<\"
 \"
;<br />        }<br />        }<br />Q12.     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.<br />    If the 2D array is<br />    The resultant 1D arrays is 12 , 3 , 9 , 24 , 25 , 45 , 9 , 5 , 18<br />    Ans.<br />        void assign2dto1d(int a[10][10],int m,int n)<br />        {<br />        int b[10],i,j,k=0;<br />        for(i=0;i<m;i++)<br />        for(j=0;j<n;j++)<br />        {<br />        if(a[i][j]%3==0||a[i][j]%5==0)<br />        {<br />        b[k]=a[i][j];<br />        k++;<br />        }<br />        }<br />        cout<<\"
\nThe resultant 1D array is :\"
;<br />        for(i=0;i<k;i++)<br />        { cout<<b[i]<<\"
 \"
;}<br />        }<br />Q13.     Write a function in C++ to replace the repeating elements in an array by 0  The zeros should be shifted to the end. The order of the array should not change.<br />    Eg : Array : 10 , 20 , 30 , 10 , 40 , 20 , 30<br />    Result : 10 , 20 , 30 , 40 , 0 , 0 , 0<br />    Ans.<br />        void twodigit(int a[10],int n)<br />        { int i,j,temp;<br />        for(i=0;i<n;i++)<br />        for(j=i+1;j<n;j++)<br />        { if(a[i]==a[j])<br />        a[j]=0;<br />        }<br />        for(i=0;i<n-1;i++)<br />        if(a[i]==0)<br />        {<br />        temp=a[i];<br />        a[i]=a[i+1];<br />        a[i+1]=temp;<br />        }<br />        cout<<\"
\nResult :\"
;<br />        for(i=0;i<n;i++)<br />        cout<<a[i]<<\"
 \"
;<br />        }<br />Q14.     Define a function SWAPARR( ) in c++ to swap the first row elements with the last row elements, for a 2d integer array passed as the argument of the function.<br />    Ans.<br />        void SWAPARR(int a[10][10],int m,int n)<br />        {<br />        int i,j,temp;<br />        for(i=0;i<n;i++)<br />        { temp=a[0][i];<br />        a[0][i]=a[m-1][i];<br />        a[m-1][i]=temp;}<br />        cout<<\"
\nThe array after swapping\"
;<br />        for(i=0;i<m;i++)<br />        { cout<<endl;<br />        for(j=0;j<n;j++)<br />        cout<<a[i][j]<<\"
 \"
;<br />        }<br />        }<br />
Arrays
Arrays
Arrays
Arrays
Arrays
Arrays
Arrays

More Related Content

PDF
Computer Graphics Lab
DOC
Practical Class 12th (c++programs+sql queries and output)
DOC
COMPUTER GRAPHICS LAB MANUAL
PDF
Computer graphics lab manual
PDF
Computer graphics lab manual
PDF
Computer graphics practical(jainam)
DOCX
Computer graphics
Computer Graphics Lab
Practical Class 12th (c++programs+sql queries and output)
COMPUTER GRAPHICS LAB MANUAL
Computer graphics lab manual
Computer graphics lab manual
Computer graphics practical(jainam)
Computer graphics

What's hot (19)

DOCX
Graphics practical lab manual
PPTX
Introduction to graphics programming in c
PDF
Basics of Computer graphics lab
PDF
Cg lab cse-v (1) (1)
DOCX
ماترێکس به‌ کوردی ئارام
PDF
2014 computer science_question_paper
PPT
Chap11alg
DOCX
Computer Practical XII
PDF
Nonlinear analysis of frame with hinge by hinge method in c programming
PPTX
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
DOCX
Bijender (1)
PDF
OOP 2012 - Hint: Dynamic allocation in c++
PPTX
Gauss in java
PPTX
Asymptotic notation
PDF
Python Manuel-R2021.pdf
DOCX
C graphics programs file
DOCX
Experement no 6
DOCX
Quiz 10 cp_sol
Graphics practical lab manual
Introduction to graphics programming in c
Basics of Computer graphics lab
Cg lab cse-v (1) (1)
ماترێکس به‌ کوردی ئارام
2014 computer science_question_paper
Chap11alg
Computer Practical XII
Nonlinear analysis of frame with hinge by hinge method in c programming
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Bijender (1)
OOP 2012 - Hint: Dynamic allocation in c++
Gauss in java
Asymptotic notation
Python Manuel-R2021.pdf
C graphics programs file
Experement no 6
Quiz 10 cp_sol
Ad

Viewers also liked (8)

PDF
Infix to Prefix (Conversion, Evaluation, Code)
DOCX
Conversion from infix to prefix using stack
PPTX
Arrays in Java
PPT
PPTX
Ppt presentation of queues
PPSX
PPTX
STACKS IN DATASTRUCTURE
Infix to Prefix (Conversion, Evaluation, Code)
Conversion from infix to prefix using stack
Arrays in Java
Ppt presentation of queues
STACKS IN DATASTRUCTURE
Ad

Similar to Arrays (20)

PDF
C programs
PDF
C++ normal assignments by maharshi_jd.pdf
PPT
PPTX
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
PPT
Basic_analysis.ppt
PPT
array2d.ppt
PDF
computer Science project.pdf
PPT
chapter1.ppt
PPT
chapter1.ppt
PDF
C++ TUTORIAL 5
PDF
2Darrays.pdf. data structure using c programming
PDF
2D array
DOCX
Cpp programs
PDF
Gentle Introduction to Functional Programming
DOC
Experiment 06 psiplclannguage expermient.doc
PPT
chapter1.ppt
DOC
Practical Class 12th (c++programs+sql queries and output)
PDF
C++ ARRAY WITH EXAMPLES
DOCX
.net progrmming part2
DOCX
Answers+of+C+sample+exam.docx
C programs
C++ normal assignments by maharshi_jd.pdf
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
Basic_analysis.ppt
array2d.ppt
computer Science project.pdf
chapter1.ppt
chapter1.ppt
C++ TUTORIAL 5
2Darrays.pdf. data structure using c programming
2D array
Cpp programs
Gentle Introduction to Functional Programming
Experiment 06 psiplclannguage expermient.doc
chapter1.ppt
Practical Class 12th (c++programs+sql queries and output)
C++ ARRAY WITH EXAMPLES
.net progrmming part2
Answers+of+C+sample+exam.docx

More from poonamchopra7975 (13)

PPT
Positive attitude2551
PPT
Positive attitude
PDF
Notes netbeans
PPT
Constructor
PPT
Overloading
PPTX
Computer parts
PPTX
Computer networking
PDF
Sample Paper I.P
PDF
CBSE Sample Paper IP
DOCX
Sample paper i.p
DOCX
Sample paper
Positive attitude2551
Positive attitude
Notes netbeans
Constructor
Overloading
Computer parts
Computer networking
Sample Paper I.P
CBSE Sample Paper IP
Sample paper i.p
Sample paper

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
VCE English Exam - Section C Student Revision Booklet
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Basic Mud Logging Guide for educational purpose
Cell Structure & Organelles in detailed.
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Microbial diseases, their pathogenesis and prophylaxis
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
Final Presentation General Medicine 03-08-2024.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Pharmacology of Heart Failure /Pharmacotherapy of CHF
102 student loan defaulters named and shamed – Is someone you know on the list?
TR - Agricultural Crops Production NC III.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial disease of the cardiovascular and lymphatic systems
VCE English Exam - Section C Student Revision Booklet
human mycosis Human fungal infections are called human mycosis..pptx
Anesthesia in Laparoscopic Surgery in India
Abdominal Access Techniques with Prof. Dr. R K Mishra
2.FourierTransform-ShortQuestionswithAnswers.pdf
Renaissance Architecture: A Journey from Faith to Humanism
STATICS OF THE RIGID BODIES Hibbelers.pdf
Basic Mud Logging Guide for educational purpose

Arrays

  • 1. Q1. Define a function shift() to shift all odd elements towards left and even to right without changing order of numbers.<br />Example: If input: 1,5,7,8,9,2,10<br />Output: 1,5,7,9,8,2,10.<br />Ans:<br />void shift(int a[10],int n)<br />{<br />int b[10],i,k=0;<br /> for(i=0;i<n;i++)<br />{<br />if(a[i]%2= =1)<br />{<br /> b[k]=a[i];<br /> k++;<br /> }<br /> }<br /> for(i=0;i<n;i++)<br /> { if(a[i]%2= =0)<br /> { b[k]=a[i];<br /> k++;<br /> }<br /> }<br /> for(i=0;i<n;i++)<br /> cout<<b[i]<<\" \" ;<br /> }<br />Q2. Given two arrays A and B. Array ‘A’ contains all the elements of ‘B’ but one more element extra. Write a c++ function which accepts array A and B and its size as arguments/ parameters and find out the extra element in Array A. (Restriction: array elements are not in order)<br /> Example : - If Array A is {14, 21, 5, 19, 8, 4, 23, 11} and Array B is {23, 8, 19, 4, 14, 11, 5 } Then output will be 21 (extra element in Array A)<br /> Ans:<br /> void extra(int a[10],int m,int b[10],int n)<br /> {<br /> int i,j,flag;<br /> for(i=0;i<m;i++)<br /> { flag=0;<br /> for(j=0;j<n;j++)<br /> if(a[i]==b[j])<br /> { flag=1;<br /> break;<br /> }<br /> if(flag==0)<br /> cout<<a[i]<<\" is the extra element\n\" ;<br /> }<br /> }<br />Q3. Write C++ function to Arrange(int [],int) to arrange all the negative and positive numbers from left to right.<br /> Example : - If an array of 10 elements initially contains { 4,5,6,-7,8,-2,-10,1,13,-20} . Then the function rearrange them in following manner { -20,-10,-7,-2 1,4,5,6,8,13}<br /> Ans:<br /> void arrange(int a[10],int n)<br /> {<br /> int i,j,temp;<br /> for(i=0;i<n;i++)<br /> { for(j=0;j<n-1;j++)<br /> if(a[j]>a[j+1])<br /> { temp=a[j];<br /> a[j]=a[j+1];<br /> a[j+1]=temp;<br /> }<br /> }<br /> for(i=0;i<n;i++)<br /> cout<<a[i]<<\" \" ;<br /> }<br />Q4. Write a user defined function in C++ to find and display the row sums of a two dimensional array.<br /> Ans:<br /> void rowsum(int a[10][10],int m,int n)<br /> {<br /> int i,j,rsum;<br /> for(i=0;i<m;i++)<br /> { rsum=0;<br /> for(j=0;j<n;j++)<br /> rsum+=a[i][j];<br /> cout<<\" \nSum of row \" <<i+1<<\" is -\" <<rsum;<br /> }<br /> }<br />Q5. Write a user defined function in C++ to find and display the column sums of a two dimensional array.<br /> Ans:<br /> void columnsum(int a[10][10],int m,int n)<br /> {<br /> int i,j,csum;<br /> for(i=0;i<n;i++)<br /> { csum=0;<br /> for(j=0;j<m;j++)<br /> csum+=a[j][i];<br /> cout<<\" \nSum of column \" <<i+1<<\" is ->\" <<csum;<br /> }<br /> }<br />Q6. Write a function in C++ to print the product of each row of a two dimensional array passed as the arguments of the function<br /> Ans:<br /> void rowproduct(int a[10][10],int m,int n)<br /> {<br /> int i,j,rp;<br /> for(i=0;i<m;i++)<br /> { rp=1;<br /> for(j=0;j<n;j++)<br /> rp*=a[j][i];<br /> cout<<\" \nProduct of row \" <<i+1<<\" is ->\" <<rp;<br /> }<br /> }<br />Q7. Write a function in C++ which accepts a 2D array of integers and its size as arguments and displays the elements which lie on diagonals. [Assuming the 2D Array to be a square matrix with odd dimension i.e. 3×3, 5×5, 7×7 etc.] Example, if the array content is<br /> 5 4 3<br /> 6 7 8<br /> 1 2 9<br /> Output through the function should be: Diagonal 1 : 5 7 9 Diagonal 2 : 3 7 1<br /> Ans:<br /> void diagonal(int a[10][10],int m,int n)<br /> {<br /> int i,j;<br /> cout<<\" \nDiagonal 1:\" ;<br /> for(i=0;i<m;i++)<br /> { for(j=0;j<n;j++)<br /> if(i==j)<br /> cout<<a[i][j]<<\" \" ;<br /> }<br /> cout<<\" \n\nDiagonal 2:\" ;<br /> for(i=0;i<m;i++)<br /> { for(j=0;j<n;j++)<br /> if(i+j==n-1)<br /> cout<<a[i][j]<<\" \" ;}<br /> }<br />Q8. Write a user defined function in C++ which accepts a squared integer matrix with odd dimensions (3*3, 5*5 …) & display the square of the elements which lie on both diagonals. For ex. :<br /> 2 5 7<br /> 3 7 2<br /> 5 6 9<br /> The output should be :<br /> Diagonal one : 4, 49, 81<br /> Diagonal two : 49, 49, 25<br /> Ans:<br /> void diagonalsquare(int a[10][10],int m,int n)<br /> {<br /> int i,j;<br /> cout<<\" \nDiagonal one :\" ;<br /> for(i=0;i<m;i++)<br /> { for(j=0;j<n;j++)<br /> if(i==j)<br /> cout<<a[i][j]*a[i][j]<<\" ,\" ;}<br /> cout<<\" \n\nDiagonal two:\" ;<br /> for(i=0;i<m;i++)<br /> { for(j=0;j<n;j++)<br /> if(i+j==n-1)<br /> cout<<a[i][j]*a[i][j]<<\" ,\" ;<br /> }<br /> }<br />Q9.Write a user defined function in C++ which accepts a squared integer matrix with odd dimensions (3*3, 5*5..) & display the sum of the middle row & middle column elements. For ex. :<br /> <br /> 2 5 7<br /> 3 7 2<br /> 5 6 9<br /> The output should be :<br /> Sum of middle row = 12<br /> Sum of middle column = 18<br /> Ans:<br /> void middlesum(int a[10][10],int m,int n)<br /> {<br /> int i,j,mrsum=0,mcsum=0;<br /> for(i=0;i<n;i++)<br /> mrsum+=a[m/2][i];<br /> cout<<\" \nSum of middle row=\" <<mrsum; for(i=0;i<m;i++)<br /> mcsum+=a[i][n/2];<br /> cout<<\" \nSum of middle column=\" <<mcsum;<br /> }<br />Q10. Write a user-defined function named Lower_half() which takes 2D array A, with size N rows and N columns as argument and prints the lower half of the array.<br /> Eg. Input<br /> 2 3 1 5 0<br /> 7 1 5 3 1<br /> 2 5 7 8 1<br /> 0 1 5 0 1<br /> 3 4 9 1 5<br /> the output will be<br /> 2<br /> 7 1<br /> 2 5 7<br /> 0 1 5 0<br /> 3 4 9 1 5<br /> Ans:<br /> void lower_half(int a[10][10],int n)<br /> {<br /> int i,j;<br /> for(i=0;i<n;i++)<br /> { cout<<endl;<br /> for(j=0;j<n;j++)<br /> if(i>=j)<br /> cout<<a[i][j]<<\" \" ;<br /> }<br /> }<br />Q11.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:<br /> Ans.<br /> void r_lower_half(int a[10],int n)<br /> {<br /> int b[10][10],i,j,k=n-1;<br /> for(i=0;i<n;i++)<br /> {<br /> for(j=0;j<n;j++)<br /> if(i+j>=n-1)<br /> b[j][i]=a[k];<br /> else<br /> b[i][j]=0;<br /> k--;<br /> }<br /> for(i=0;i<n;i++)<br /> { cout<<endl;<br /> for(j=0;j<n;j++)<br /> cout<<b[i][j]<<\" \" ;<br /> }<br /> }<br />Q12. 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.<br /> If the 2D array is<br /> The resultant 1D arrays is 12 , 3 , 9 , 24 , 25 , 45 , 9 , 5 , 18<br /> Ans.<br /> void assign2dto1d(int a[10][10],int m,int n)<br /> {<br /> int b[10],i,j,k=0;<br /> for(i=0;i<m;i++)<br /> for(j=0;j<n;j++)<br /> {<br /> if(a[i][j]%3==0||a[i][j]%5==0)<br /> {<br /> b[k]=a[i][j];<br /> k++;<br /> }<br /> }<br /> cout<<\" \nThe resultant 1D array is :\" ;<br /> for(i=0;i<k;i++)<br /> { cout<<b[i]<<\" \" ;}<br /> }<br />Q13. Write a function in C++ to replace the repeating elements in an array by 0 The zeros should be shifted to the end. The order of the array should not change.<br /> Eg : Array : 10 , 20 , 30 , 10 , 40 , 20 , 30<br /> Result : 10 , 20 , 30 , 40 , 0 , 0 , 0<br /> Ans.<br /> void twodigit(int a[10],int n)<br /> { int i,j,temp;<br /> for(i=0;i<n;i++)<br /> for(j=i+1;j<n;j++)<br /> { if(a[i]==a[j])<br /> a[j]=0;<br /> }<br /> for(i=0;i<n-1;i++)<br /> if(a[i]==0)<br /> {<br /> temp=a[i];<br /> a[i]=a[i+1];<br /> a[i+1]=temp;<br /> }<br /> cout<<\" \nResult :\" ;<br /> for(i=0;i<n;i++)<br /> cout<<a[i]<<\" \" ;<br /> }<br />Q14. Define a function SWAPARR( ) in c++ to swap the first row elements with the last row elements, for a 2d integer array passed as the argument of the function.<br /> Ans.<br /> void SWAPARR(int a[10][10],int m,int n)<br /> {<br /> int i,j,temp;<br /> for(i=0;i<n;i++)<br /> { temp=a[0][i];<br /> a[0][i]=a[m-1][i];<br /> a[m-1][i]=temp;}<br /> cout<<\" \nThe array after swapping\" ;<br /> for(i=0;i<m;i++)<br /> { cout<<endl;<br /> for(j=0;j<n;j++)<br /> cout<<a[i][j]<<\" \" ;<br /> }<br /> }<br />