SlideShare a Scribd company logo
1 of 4
I am having issues writing the loop language that i am using is
C Function: same_contents * Description: determines if
arrays a[] and b[] contain * exactly the same values,
but not necessarily * in the same order. *
returns 1 if they do have the same contents * returns 0
otherwise. * Note: if there are multiple occurrences of
the * same value, both arrays must contain the same *
number of such occurrences to be considered * to have
the same contents. * * Assumptions: parameter n
specifies the length of both a[] and * b[] * *
Restrictions: the arrays a[] and b[] may not be modified. */ int
same_contents(int a[], int b[], int n)
Solution
compare.c
#include <stdio.h>
int same_contents(int a[], int b[], int n);
int main()
{
int a[] = {1 , 2,4 ,2 ,5, 3,3};
int b[] = {1 , 4,5 ,3, 2, 2, 3};
int n = 7;
int value;
value = same_contents(a, b, n);
printf(" The return value is %d ", value);
return 0;
}
int same_contents(int a[], int b[], int n){
int i, j;
int count = 0, temp;
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (a[i] > a[j])
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
printf("Array a elements after sorting:  ");
for(i=0; i<n; i++){
printf("%d ",a[i]);
}
printf(" ");
printf(" ");
for (i = 0; i < n; ++i)
{
for (j = i + 1; j < n; ++j)
{
if (b[i] > b[j])
{
temp = b[i];
b[i] = b[j];
b[j] = temp;
}
}
}
printf("Array b elements after sorting:  ");
for(i=0; i<n; i++){
printf("%d ",b[i]);
}
for(i=0; i<n; i++){
for(j=0; j<n; j++){
if(a[i] != b[i]){
count = 1;
}
}
}
if(count == 0){
return 1;
}
else
return 0;
}
Output:
Array a elements after sorting:
1 2 2 3 3 4 5
Array b elements after sorting:
1 2 2 3 3 4 5
The return value is 1

More Related Content

Similar to I am having issues writing the loop language that i am using is C .docx

Similar to I am having issues writing the loop language that i am using is C .docx (20)

Introduction to c part 2
Introduction to c   part  2Introduction to c   part  2
Introduction to c part 2
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
C++ Programming Homework Help
C++ Programming Homework HelpC++ Programming Homework Help
C++ Programming Homework Help
 
Array
ArrayArray
Array
 
Array
ArrayArray
Array
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
Lecture 1 mte 407
Lecture 1 mte 407Lecture 1 mte 407
Lecture 1 mte 407
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
 
Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01
 
Lecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptxLecture 5Arrays on c++ for Beginner.pptx
Lecture 5Arrays on c++ for Beginner.pptx
 
Java căn bản - Chapter10
Java căn bản - Chapter10Java căn bản - Chapter10
Java căn bản - Chapter10
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Imugi: Compiler made with Python
Imugi: Compiler made with PythonImugi: Compiler made with Python
Imugi: Compiler made with Python
 
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : NotesCUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
CUDA First Programs: Computer Architecture CSE448 : UAA Alaska : Notes
 
Python programming workshop
Python programming workshopPython programming workshop
Python programming workshop
 
C interview question answer 2
C interview question answer 2C interview question answer 2
C interview question answer 2
 
unit-2-dsa.pptx
unit-2-dsa.pptxunit-2-dsa.pptx
unit-2-dsa.pptx
 
CSE240 Pointers
CSE240 PointersCSE240 Pointers
CSE240 Pointers
 
Embedded C - Day 2
Embedded C - Day 2Embedded C - Day 2
Embedded C - Day 2
 

More from Abdulrahman890100

game.c Written by Peter Sutton. Game board da.docx
  game.c   Written by Peter Sutton.   Game board da.docx  game.c   Written by Peter Sutton.   Game board da.docx
game.c Written by Peter Sutton. Game board da.docxAbdulrahman890100
 
I have two classes One is Carnivore and the other is Herbivore. .docx
  I have two classes One is Carnivore and the other is Herbivore. .docx  I have two classes One is Carnivore and the other is Herbivore. .docx
I have two classes One is Carnivore and the other is Herbivore. .docxAbdulrahman890100
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docxAbdulrahman890100
 
Complete the C++ program and implement the routines that are not .docx
  Complete the C++ program and implement the routines that are not .docx  Complete the C++ program and implement the routines that are not .docx
Complete the C++ program and implement the routines that are not .docxAbdulrahman890100
 
Create an application that calculates the total cost of a hospit.docx
  Create an application that calculates the total cost of a hospit.docx  Create an application that calculates the total cost of a hospit.docx
Create an application that calculates the total cost of a hospit.docxAbdulrahman890100
 
Complete the C++ program and implement the routines that are n.docx
    Complete the C++ program and implement the routines that are n.docx    Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docxAbdulrahman890100
 

More from Abdulrahman890100 (6)

game.c Written by Peter Sutton. Game board da.docx
  game.c   Written by Peter Sutton.   Game board da.docx  game.c   Written by Peter Sutton.   Game board da.docx
game.c Written by Peter Sutton. Game board da.docx
 
I have two classes One is Carnivore and the other is Herbivore. .docx
  I have two classes One is Carnivore and the other is Herbivore. .docx  I have two classes One is Carnivore and the other is Herbivore. .docx
I have two classes One is Carnivore and the other is Herbivore. .docx
 
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx  Find an LCS of X =  and Y =   Show the c and b table.  Attach File  .docx
Find an LCS of X = and Y = Show the c and b table. Attach File .docx
 
Complete the C++ program and implement the routines that are not .docx
  Complete the C++ program and implement the routines that are not .docx  Complete the C++ program and implement the routines that are not .docx
Complete the C++ program and implement the routines that are not .docx
 
Create an application that calculates the total cost of a hospit.docx
  Create an application that calculates the total cost of a hospit.docx  Create an application that calculates the total cost of a hospit.docx
Create an application that calculates the total cost of a hospit.docx
 
Complete the C++ program and implement the routines that are n.docx
    Complete the C++ program and implement the routines that are n.docx    Complete the C++ program and implement the routines that are n.docx
Complete the C++ program and implement the routines that are n.docx
 

Recently uploaded

Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
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
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
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
 

Recently uploaded (20)

Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
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 ...
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
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
 

I am having issues writing the loop language that i am using is C .docx

  • 1. I am having issues writing the loop language that i am using is C Function: same_contents * Description: determines if arrays a[] and b[] contain * exactly the same values, but not necessarily * in the same order. * returns 1 if they do have the same contents * returns 0 otherwise. * Note: if there are multiple occurrences of the * same value, both arrays must contain the same * number of such occurrences to be considered * to have the same contents. * * Assumptions: parameter n specifies the length of both a[] and * b[] * * Restrictions: the arrays a[] and b[] may not be modified. */ int same_contents(int a[], int b[], int n) Solution compare.c #include <stdio.h> int same_contents(int a[], int b[], int n); int main() { int a[] = {1 , 2,4 ,2 ,5, 3,3}; int b[] = {1 , 4,5 ,3, 2, 2, 3}; int n = 7; int value;
  • 2. value = same_contents(a, b, n); printf(" The return value is %d ", value); return 0; } int same_contents(int a[], int b[], int n){ int i, j; int count = 0, temp; for (i = 0; i < n; ++i) { for (j = i + 1; j < n; ++j) { if (a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } } printf("Array a elements after sorting: "); for(i=0; i<n; i++){ printf("%d ",a[i]); } printf(" ");
  • 3. printf(" "); for (i = 0; i < n; ++i) { for (j = i + 1; j < n; ++j) { if (b[i] > b[j]) { temp = b[i]; b[i] = b[j]; b[j] = temp; } } } printf("Array b elements after sorting: "); for(i=0; i<n; i++){ printf("%d ",b[i]); } for(i=0; i<n; i++){ for(j=0; j<n; j++){ if(a[i] != b[i]){ count = 1; } } }
  • 4. if(count == 0){ return 1; } else return 0; } Output: Array a elements after sorting: 1 2 2 3 3 4 5 Array b elements after sorting: 1 2 2 3 3 4 5 The return value is 1