SlideShare ist ein Scribd-Unternehmen logo
1 von 8
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]<<quot;
 quot;
;<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]<<quot;
 is the extra elementquot;
;<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]<<quot;
 quot;
;<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<<quot;
Sum of row quot;
<<i+1<<quot;
 is -quot;
<<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<<quot;
Sum of column quot;
<<i+1<<quot;
 is ->quot;
<<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<<quot;
Product of row quot;
<<i+1<<quot;
 is ->quot;
<<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<<quot;
Diagonal 1:quot;
;<br />            for(i=0;i<m;i++)<br />            { for(j=0;j<n;j++)<br />            if(i==j)<br />            cout<<a[i][j]<<quot;
 quot;
;<br />            }<br />            cout<<quot;
Diagonal 2:quot;
;<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]<<quot;
 quot;
;}<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<<quot;
Diagonal one :quot;
;<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]<<quot;
,quot;
;}<br />            cout<<quot;
Diagonal two:quot;
;<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]<<quot;
,quot;
;<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<<quot;
Sum of middle row=quot;
<<mrsum; for(i=0;i<m;i++)<br />            mcsum+=a[i][n/2];<br />            cout<<quot;
Sum of middle column=quot;
<<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]<<quot;
 quot;
;<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]<<quot;
 quot;
;<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<<quot;
The resultant 1D array is :quot;
;<br />        for(i=0;i<k;i++)<br />        { cout<<b[i]<<quot;
 quot;
;}<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<<quot;
Result :quot;
;<br />        for(i=0;i<n;i++)<br />        cout<<a[i]<<quot;
 quot;
;<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<<quot;
The array after swappingquot;
;<br />        for(i=0;i<m;i++)<br />        { cout<<endl;<br />        for(j=0;j<n;j++)<br />        cout<<a[i][j]<<quot;
 quot;
;<br />        }<br />        }<br />
Arrays
Arrays
Arrays
Arrays
Arrays
Arrays
Arrays

Weitere ähnliche Inhalte

Was ist angesagt?

Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manualVivek Kumar Sinha
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics labPriya Goyal
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامAram Jamal
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_papervandna123
 
Nonlinear analysis of frame with hinge by hinge method in c programming
Nonlinear analysis of frame with hinge by hinge method in c programmingNonlinear analysis of frame with hinge by hinge method in c programming
Nonlinear analysis of frame with hinge by hinge method in c programmingSalar Delavar Qashqai
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingMeghaj Mallick
 
OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++Allan Sun
 
Gauss in java
Gauss in javaGauss in java
Gauss in javabaxter89
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notationsajinis3
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs fileshubham kanojia
 

Was ist angesagt? (19)

Graphics practical lab manual
Graphics practical lab manualGraphics practical lab manual
Graphics practical lab manual
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Introduction to graphics programming in c
Introduction to graphics programming in cIntroduction to graphics programming in c
Introduction to graphics programming in c
 
Basics of Computer graphics lab
Basics of Computer graphics labBasics of Computer graphics lab
Basics of Computer graphics lab
 
Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)Cg lab cse-v (1) (1)
Cg lab cse-v (1) (1)
 
ماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارامماترێکس به‌ کوردی ئارام
ماترێکس به‌ کوردی ئارام
 
2014 computer science_question_paper
2014 computer science_question_paper2014 computer science_question_paper
2014 computer science_question_paper
 
Chap11alg
Chap11algChap11alg
Chap11alg
 
Computer Practical XII
Computer Practical XIIComputer Practical XII
Computer Practical XII
 
Nonlinear analysis of frame with hinge by hinge method in c programming
Nonlinear analysis of frame with hinge by hinge method in c programmingNonlinear analysis of frame with hinge by hinge method in c programming
Nonlinear analysis of frame with hinge by hinge method in c programming
 
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++OOP 2012 - Hint: Dynamic allocation in c++
OOP 2012 - Hint: Dynamic allocation in c++
 
Gauss in java
Gauss in javaGauss in java
Gauss in java
 
Asymptotic notation
Asymptotic notationAsymptotic notation
Asymptotic notation
 
Python Manuel-R2021.pdf
Python Manuel-R2021.pdfPython Manuel-R2021.pdf
Python Manuel-R2021.pdf
 
C graphics programs file
C graphics programs fileC graphics programs file
C graphics programs file
 
Experement no 6
Experement no 6Experement no 6
Experement no 6
 
Quiz 10 cp_sol
Quiz 10 cp_solQuiz 10 cp_sol
Quiz 10 cp_sol
 

Andere mochten auch

Andere mochten auch (8)

Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)Infix to Prefix (Conversion, Evaluation, Code)
Infix to Prefix (Conversion, Evaluation, Code)
 
Conversion from infix to prefix using stack
Conversion from infix to prefix using stackConversion from infix to prefix using stack
Conversion from infix to prefix using stack
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Queue
QueueQueue
Queue
 
Ppt presentation of queues
Ppt presentation of queuesPpt presentation of queues
Ppt presentation of queues
 
Stack Applications
Stack ApplicationsStack Applications
Stack Applications
 
Stack
StackStack
Stack
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 

Ähnlich wie Arrays

2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
 
Basic_analysis.ppt
Basic_analysis.pptBasic_analysis.ppt
Basic_analysis.pptSoumyaJ3
 
computer Science project.pdf
 computer Science project.pdf computer Science project.pdf
computer Science project.pdfManasviGupta32
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingSaurabh Singh
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.pptebinazer1
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)Aman Deep
 
Answers+of+C+sample+exam.docx
Answers+of+C+sample+exam.docxAnswers+of+C+sample+exam.docx
Answers+of+C+sample+exam.docxismailaboshatra
 
Answers+of+C+sample+exam.docx
Answers+of+C+sample+exam.docxAnswers+of+C+sample+exam.docx
Answers+of+C+sample+exam.docxismailaboshatra
 
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CSAAKASH KUMAR
 

Ähnlich wie Arrays (20)

C programs
C programsC programs
C programs
 
Qno 3 (a)
Qno 3 (a)Qno 3 (a)
Qno 3 (a)
 
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
Basic_analysis.ppt
Basic_analysis.pptBasic_analysis.ppt
Basic_analysis.ppt
 
array2d.ppt
array2d.pptarray2d.ppt
array2d.ppt
 
computer Science project.pdf
 computer Science project.pdf computer Science project.pdf
computer Science project.pdf
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
2D array
2D array2D array
2D array
 
Cpp programs
Cpp programsCpp programs
Cpp programs
 
Gentle Introduction to Functional Programming
Gentle Introduction to Functional ProgrammingGentle Introduction to Functional Programming
Gentle Introduction to Functional Programming
 
chapter1.ppt
chapter1.pptchapter1.ppt
chapter1.ppt
 
Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)Practical Class 12th (c++programs+sql queries and output)
Practical Class 12th (c++programs+sql queries and output)
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Answers+of+C+sample+exam.docx
Answers+of+C+sample+exam.docxAnswers+of+C+sample+exam.docx
Answers+of+C+sample+exam.docx
 
Answers+of+C+sample+exam.docx
Answers+of+C+sample+exam.docxAnswers+of+C+sample+exam.docx
Answers+of+C+sample+exam.docx
 
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
 
Arrays
ArraysArrays
Arrays
 

Mehr von poonamchopra7975 (13)

Positive attitude2551
Positive attitude2551Positive attitude2551
Positive attitude2551
 
Positive attitude
Positive attitudePositive attitude
Positive attitude
 
Notes netbeans
Notes netbeansNotes netbeans
Notes netbeans
 
Constructor
ConstructorConstructor
Constructor
 
Overloading
OverloadingOverloading
Overloading
 
Computer parts
Computer partsComputer parts
Computer parts
 
Computer networking
Computer networkingComputer networking
Computer networking
 
Cna
CnaCna
Cna
 
Oops
OopsOops
Oops
 
Sample Paper I.P
Sample Paper I.PSample Paper I.P
Sample Paper I.P
 
CBSE Sample Paper IP
CBSE Sample Paper IPCBSE Sample Paper IP
CBSE Sample Paper IP
 
Sample paper i.p
Sample paper i.pSample paper i.p
Sample paper i.p
 
Sample paper
Sample paperSample paper
Sample paper
 

Kürzlich hochgeladen

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 

Kürzlich hochgeladen (20)

Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 

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]<<quot; quot; ;<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]<<quot; is the extra elementquot; ;<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]<<quot; quot; ;<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<<quot; Sum of row quot; <<i+1<<quot; is -quot; <<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<<quot; Sum of column quot; <<i+1<<quot; is ->quot; <<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<<quot; Product of row quot; <<i+1<<quot; is ->quot; <<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<<quot; Diagonal 1:quot; ;<br /> for(i=0;i<m;i++)<br /> { for(j=0;j<n;j++)<br /> if(i==j)<br /> cout<<a[i][j]<<quot; quot; ;<br /> }<br /> cout<<quot; Diagonal 2:quot; ;<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]<<quot; quot; ;}<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<<quot; Diagonal one :quot; ;<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]<<quot; ,quot; ;}<br /> cout<<quot; Diagonal two:quot; ;<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]<<quot; ,quot; ;<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<<quot; Sum of middle row=quot; <<mrsum; for(i=0;i<m;i++)<br /> mcsum+=a[i][n/2];<br /> cout<<quot; Sum of middle column=quot; <<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]<<quot; quot; ;<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]<<quot; quot; ;<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<<quot; The resultant 1D array is :quot; ;<br /> for(i=0;i<k;i++)<br /> { cout<<b[i]<<quot; quot; ;}<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<<quot; Result :quot; ;<br /> for(i=0;i<n;i++)<br /> cout<<a[i]<<quot; quot; ;<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<<quot; The array after swappingquot; ;<br /> for(i=0;i<m;i++)<br /> { cout<<endl;<br /> for(j=0;j<n;j++)<br /> cout<<a[i][j]<<quot; quot; ;<br /> }<br /> }<br />