SlideShare a Scribd company logo
1 of 3
Download to read offline
I am working on a homework that requires us to write several functions outside of main that will
be called either in main or one of the other functions. I need help with the two functions listed
below. Both should be in C.
5) Write a function “findMode” that takes as an argument an integer array and an integer for the
size of the array. It should return an integer of the mode of that array. If there are multiple
modes, it can return any one of them.
6) Write a function “findMinMax” that takes as an argument an integer array, an integer for the
size of the array, and two integer pointers. The function should print nothing and return nothing
but change the value of the first pointer to the minimum value in the array and change the value
in the second pointer to the max value in the array.
Solution
5)
#include
#include
#include
#include
int N = 20;
int sequence[20];
int mode() {
int maxValue = 0, maxCount = 0, i, j;
for (i = 0; i < N; ++i) {
int count = 0;
for (j = 0; j < N; ++j) {
if (sequence[j] == sequence[i])
++count;
}
if (count > maxCount) {
maxCount = count;
maxValue = sequence[i];
}
}
return maxValue;
}
int main(int argc, char **argv) {
int i;
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
for (i = 0; i < N; i++)
sequence[i] = rand() % (100 - 1 + 1) + 1;
printf("The set of numbers are: ");
for (i = 0; i < N; i++)
printf("%d ", sequence[i]);
printf(" The mode of the set is: %d", mode());
}
6)
#include
#include
#include
int main( void )
{
int i = 0;
int a[11];
int min = a[0];
int max = a[0];
srandom( (unsigned) time(NULL) );
for (i=0;i<11;i++)
{
a[i]=random( ) % 100 ;
printf("%d ", a[i]);
if (a[i] > max)
{
max = a[i];
}
else if (a[i] < min)
{
min = a[i];
}
}
printf("Min: %d ", min);
printf("Max: %d ", max);
return ( 0 ) ;
}

More Related Content

Similar to I am working on a homework that requires us to write several functio.pdf

Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
mallik3000
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
alish sha
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
eugeniadean34240
 

Similar to I am working on a homework that requires us to write several functio.pdf (20)

Modify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdfModify this code to use multiple threads with the same data1.Modif.pdf
Modify this code to use multiple threads with the same data1.Modif.pdf
 
VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2VIT351 Software Development VI Unit2
VIT351 Software Development VI Unit2
 
Arrays and function basic c programming notes
Arrays and function basic c programming notesArrays and function basic c programming notes
Arrays and function basic c programming notes
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
Computer programming subject notes. Quick easy notes for C Programming.Cheat ...
 
programs on arrays.pdf
programs on arrays.pdfprograms on arrays.pdf
programs on arrays.pdf
 
Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7Dam31303 dti2143 lab sheet 7
Dam31303 dti2143 lab sheet 7
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
Pnno
PnnoPnno
Pnno
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
week-21x
week-21xweek-21x
week-21x
 
C programs
C programsC programs
C programs
 
Operating system labs
Operating system labsOperating system labs
Operating system labs
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
UNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptxUNIT 2 LOOP CONTROL.pptx
UNIT 2 LOOP CONTROL.pptx
 
Functions
FunctionsFunctions
Functions
 
design and analysis of algorithm Lab files
design and analysis of algorithm Lab filesdesign and analysis of algorithm Lab files
design and analysis of algorithm Lab files
 
array
arrayarray
array
 
Array
ArrayArray
Array
 

More from info961251

With which portion of an epithelial cell in the stomach would food be.pdf
With which portion of an epithelial cell in the stomach would food be.pdfWith which portion of an epithelial cell in the stomach would food be.pdf
With which portion of an epithelial cell in the stomach would food be.pdf
info961251
 
Which of the following correctly states the functions of the roug.pdf
Which of the following correctly states the functions of the roug.pdfWhich of the following correctly states the functions of the roug.pdf
Which of the following correctly states the functions of the roug.pdf
info961251
 
What is the definition of the words, and state the diffe.pdf
What is the definition of the words, and state the diffe.pdfWhat is the definition of the words, and state the diffe.pdf
What is the definition of the words, and state the diffe.pdf
info961251
 
TB is a major worldwide disease with new cases arising at an alarmin.pdf
TB is a major worldwide disease with new cases arising at an alarmin.pdfTB is a major worldwide disease with new cases arising at an alarmin.pdf
TB is a major worldwide disease with new cases arising at an alarmin.pdf
info961251
 
Question 1Theories of Law Subject__________ is a collaborative.pdf
Question 1Theories of Law Subject__________ is a collaborative.pdfQuestion 1Theories of Law Subject__________ is a collaborative.pdf
Question 1Theories of Law Subject__________ is a collaborative.pdf
info961251
 
Please fix the java code (using eclipse)package hw4p1;import jav.pdf
Please fix the java code (using eclipse)package hw4p1;import jav.pdfPlease fix the java code (using eclipse)package hw4p1;import jav.pdf
Please fix the java code (using eclipse)package hw4p1;import jav.pdf
info961251
 
Overview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdfOverview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdf
info961251
 

More from info961251 (20)

With which portion of an epithelial cell in the stomach would food be.pdf
With which portion of an epithelial cell in the stomach would food be.pdfWith which portion of an epithelial cell in the stomach would food be.pdf
With which portion of an epithelial cell in the stomach would food be.pdf
 
Write the interface (.h file) of a class Accumulator containing A d.pdf
Write the interface (.h file) of a class Accumulator containing  A d.pdfWrite the interface (.h file) of a class Accumulator containing  A d.pdf
Write the interface (.h file) of a class Accumulator containing A d.pdf
 
You are carrying out PCRs in lab. Why do you not need helicase, SSB,.pdf
You are carrying out PCRs in lab. Why do you not need helicase, SSB,.pdfYou are carrying out PCRs in lab. Why do you not need helicase, SSB,.pdf
You are carrying out PCRs in lab. Why do you not need helicase, SSB,.pdf
 
Write your own definition of cloning. No plagarism!SolutionClo.pdf
Write your own definition of cloning. No plagarism!SolutionClo.pdfWrite your own definition of cloning. No plagarism!SolutionClo.pdf
Write your own definition of cloning. No plagarism!SolutionClo.pdf
 
Write appropriate SQL DDL statements (Create Table Statements) for d.pdf
Write appropriate SQL DDL statements (Create Table Statements) for d.pdfWrite appropriate SQL DDL statements (Create Table Statements) for d.pdf
Write appropriate SQL DDL statements (Create Table Statements) for d.pdf
 
Write a class called Student that extends the provided Person class..pdf
Write a class called Student that extends the provided Person class..pdfWrite a class called Student that extends the provided Person class..pdf
Write a class called Student that extends the provided Person class..pdf
 
why NADH and FADH2 are a type of energy currencySolutionEnergy.pdf
why NADH and FADH2 are a type of energy currencySolutionEnergy.pdfwhy NADH and FADH2 are a type of energy currencySolutionEnergy.pdf
why NADH and FADH2 are a type of energy currencySolutionEnergy.pdf
 
Who is D.L ShellSolutionHi friend,Donald L. Shell (March 1,.pdf
Who is D.L ShellSolutionHi friend,Donald L. Shell (March 1,.pdfWho is D.L ShellSolutionHi friend,Donald L. Shell (March 1,.pdf
Who is D.L ShellSolutionHi friend,Donald L. Shell (March 1,.pdf
 
Which of the following correctly states the functions of the roug.pdf
Which of the following correctly states the functions of the roug.pdfWhich of the following correctly states the functions of the roug.pdf
Which of the following correctly states the functions of the roug.pdf
 
What is isomerism How many kinds are there Define each kind and.pdf
What is isomerism How many kinds are there Define each kind and.pdfWhat is isomerism How many kinds are there Define each kind and.pdf
What is isomerism How many kinds are there Define each kind and.pdf
 
What is the definition of the words, and state the diffe.pdf
What is the definition of the words, and state the diffe.pdfWhat is the definition of the words, and state the diffe.pdf
What is the definition of the words, and state the diffe.pdf
 
Two sources of radio waves (call them 1 and 2) are separated by a dis.pdf
Two sources of radio waves (call them 1 and 2) are separated by a dis.pdfTwo sources of radio waves (call them 1 and 2) are separated by a dis.pdf
Two sources of radio waves (call them 1 and 2) are separated by a dis.pdf
 
Use the information in the table to select the image that represents .pdf
Use the information in the table to select the image that represents .pdfUse the information in the table to select the image that represents .pdf
Use the information in the table to select the image that represents .pdf
 
Triggers can only be used to update table values. PLSQL blocks have.pdf
Triggers can only be used to update table values.  PLSQL blocks have.pdfTriggers can only be used to update table values.  PLSQL blocks have.pdf
Triggers can only be used to update table values. PLSQL blocks have.pdf
 
TB is a major worldwide disease with new cases arising at an alarmin.pdf
TB is a major worldwide disease with new cases arising at an alarmin.pdfTB is a major worldwide disease with new cases arising at an alarmin.pdf
TB is a major worldwide disease with new cases arising at an alarmin.pdf
 
7. How did printing technology impact literacy and educationSol.pdf
7. How did printing technology impact literacy and educationSol.pdf7. How did printing technology impact literacy and educationSol.pdf
7. How did printing technology impact literacy and educationSol.pdf
 
Question 1Theories of Law Subject__________ is a collaborative.pdf
Question 1Theories of Law Subject__________ is a collaborative.pdfQuestion 1Theories of Law Subject__________ is a collaborative.pdf
Question 1Theories of Law Subject__________ is a collaborative.pdf
 
Q Describe the 2 types of homologs. (1) Orthologs (2) ParalogsS.pdf
Q Describe the 2 types of homologs. (1) Orthologs (2) ParalogsS.pdfQ Describe the 2 types of homologs. (1) Orthologs (2) ParalogsS.pdf
Q Describe the 2 types of homologs. (1) Orthologs (2) ParalogsS.pdf
 
Please fix the java code (using eclipse)package hw4p1;import jav.pdf
Please fix the java code (using eclipse)package hw4p1;import jav.pdfPlease fix the java code (using eclipse)package hw4p1;import jav.pdf
Please fix the java code (using eclipse)package hw4p1;import jav.pdf
 
Overview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdfOverview You are tasked with writing a program called Social Security.pdf
Overview You are tasked with writing a program called Social Security.pdf
 

Recently uploaded

Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 

I am working on a homework that requires us to write several functio.pdf

  • 1. I am working on a homework that requires us to write several functions outside of main that will be called either in main or one of the other functions. I need help with the two functions listed below. Both should be in C. 5) Write a function “findMode” that takes as an argument an integer array and an integer for the size of the array. It should return an integer of the mode of that array. If there are multiple modes, it can return any one of them. 6) Write a function “findMinMax” that takes as an argument an integer array, an integer for the size of the array, and two integer pointers. The function should print nothing and return nothing but change the value of the first pointer to the minimum value in the array and change the value in the second pointer to the max value in the array. Solution 5) #include #include #include #include int N = 20; int sequence[20]; int mode() { int maxValue = 0, maxCount = 0, i, j; for (i = 0; i < N; ++i) { int count = 0; for (j = 0; j < N; ++j) { if (sequence[j] == sequence[i]) ++count; } if (count > maxCount) { maxCount = count; maxValue = sequence[i]; } } return maxValue; }
  • 2. int main(int argc, char **argv) { int i; time_t seconds; time(&seconds); srand((unsigned int) seconds); for (i = 0; i < N; i++) sequence[i] = rand() % (100 - 1 + 1) + 1; printf("The set of numbers are: "); for (i = 0; i < N; i++) printf("%d ", sequence[i]); printf(" The mode of the set is: %d", mode()); } 6) #include #include #include int main( void ) { int i = 0; int a[11]; int min = a[0]; int max = a[0]; srandom( (unsigned) time(NULL) ); for (i=0;i<11;i++) { a[i]=random( ) % 100 ; printf("%d ", a[i]); if (a[i] > max) { max = a[i]; } else if (a[i] < min) { min = a[i]; } }
  • 3. printf("Min: %d ", min); printf("Max: %d ", max); return ( 0 ) ; }