SlideShare a Scribd company logo
1 of 3
Download to read offline
I came upon this and I would love to know how this works :-)
The majority of your development may take place in the function task2().
1. You need to implement code to output the following line to the screen:
–- Task 2 –-
2.Declare an int array named numbers and initialise it with the following values: 1 4 9 16 9 7 4 9
11 (2 marks)
3. Declare a second array of the same size and using a loop populate it with random numbers in
the range of 1 – 25 inclusive.
4. Use a loop to compute the ‘total’ of the numbers based on the following rule: If the number
being considered is odd then add this to the total, however if the number to be added is even then
subtract this from the total. For example for the initialised array it would compute: 1 4 + 9 16 +
9 + 7 4 + 9 + 11 = 22
5. Print both of the arrays and the results of the ‘total’ operation. For example for the initialised
array the output could resemble: [ 1, 4, 9, 16, 9, 7, 4, 9, 11 ] the total is RESULT Where
RESULT is the calculated value from the ‘total’ operation. Notice that the lists should be comma
space separated and that the final element in the list is not terminated with a comma but with a
space followed by a square bracket. Also note that each line should begin with a left square
bracket followed by a space.
Solution
// C++ code
#include
#include
#include
using namespace std;
int main ()
{
int array1[] = {1,4,9,16,9,7,4,9,11};
int size = sizeof(array1)/sizeof(array1[0]);
int array2[size];
for (int i = 0; i < size; ++i)
{
// random numbers in the range of 1 – 25 inclusive.aa
array2[i] = rand() % 25 + 1;
}
int total1 = 0;
int total2 = 0;
for (int i = 0; i < size; ++i)
{
if(array1[i]%2 == 0)
total1 = total1 - array1[i];
else
total1 = total1 + array1[i];
if(array2[i]%2 == 0)
total2 = total2 - array2[i];
else
total2 = total2 + array2[i];
}
cout << " [ ";
for (int i = 0; i < size-1; ++i)
{
cout << array1[i] << ", ";
}
cout << array1[size-1] << " ] the total is " << total1 << endl;
cout << " [ ";
for (int i = 0; i < size-1; ++i)
{
cout << array2[i] << ", ";
}
cout << array2[size-1] << " ] the total is " << total2 << endl;
return 0;
}
/*
output:
[ 1, 4, 9, 16, 9, 7, 4, 9, 11 ] the total is 22
[ 9, 12, 3, 16, 19, 11, 12, 18, 25 ] the total is 9
*/

More Related Content

Similar to I came upon this and I would love to know how this works -)The ma.pdf

Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptxMrhaider4
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docxjosies1
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmEhsan Ehrari
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2Mohamed Ahmed
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to ArraysTareq Hasan
 
Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3Synapseindiappsdevelopment
 
ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptMahyuddin8
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdfYashMirge2
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfUmarMustafa13
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelizationAlbert DeFusco
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysMaulen Bale
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 

Similar to I came upon this and I would love to know how this works -)The ma.pdf (20)

Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
Insersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in AlgoritmInsersion & Bubble Sort in Algoritm
Insersion & Bubble Sort in Algoritm
 
C++ Course - Lesson 2
C++ Course - Lesson 2C++ Course - Lesson 2
C++ Course - Lesson 2
 
A01
A01A01
A01
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
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 sharp chap6
C sharp chap6C sharp chap6
C sharp chap6
 
Java: Introduction to Arrays
Java: Introduction to ArraysJava: Introduction to Arrays
Java: Introduction to Arrays
 
Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3Synapse india dotnet development overloading operater part 3
Synapse india dotnet development overloading operater part 3
 
ch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.pptch05-program-logic-indefinite-loops.ppt
ch05-program-logic-indefinite-loops.ppt
 
Sample Program file class 11.pdf
Sample Program file class 11.pdfSample Program file class 11.pdf
Sample Program file class 11.pdf
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 
algorithm
algorithmalgorithm
algorithm
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelization
 
Data Structure Midterm Lesson Arrays
Data Structure Midterm Lesson ArraysData Structure Midterm Lesson Arrays
Data Structure Midterm Lesson Arrays
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 

More from sales96

Write a small program in ARM to Store these values into an array 0.pdf
Write a small program in ARM to  Store these values into an array 0.pdfWrite a small program in ARM to  Store these values into an array 0.pdf
Write a small program in ARM to Store these values into an array 0.pdfsales96
 
Why that partial derivative is zero Why that partial derivative is .pdf
Why that partial derivative is zero Why that partial derivative is .pdfWhy that partial derivative is zero Why that partial derivative is .pdf
Why that partial derivative is zero Why that partial derivative is .pdfsales96
 
Which two gases are the most important for aquatic organisms Wh.pdf
Which two gases are the most important for aquatic organisms Wh.pdfWhich two gases are the most important for aquatic organisms Wh.pdf
Which two gases are the most important for aquatic organisms Wh.pdfsales96
 
Which cells of the pancreas are the endocrine cells How were you ab.pdf
Which cells of the pancreas are the endocrine cells How were you ab.pdfWhich cells of the pancreas are the endocrine cells How were you ab.pdf
Which cells of the pancreas are the endocrine cells How were you ab.pdfsales96
 
What determines how much genetic variation exists in populations A..pdf
What determines how much genetic variation exists in populations A..pdfWhat determines how much genetic variation exists in populations A..pdf
What determines how much genetic variation exists in populations A..pdfsales96
 
What are three types of Why are fossils important to scientists.pdf
What are three types of  Why are fossils important to scientists.pdfWhat are three types of  Why are fossils important to scientists.pdf
What are three types of Why are fossils important to scientists.pdfsales96
 
This is a nursing informatics question...What is “Meaningful Use”,.pdf
This is a nursing informatics question...What is “Meaningful Use”,.pdfThis is a nursing informatics question...What is “Meaningful Use”,.pdf
This is a nursing informatics question...What is “Meaningful Use”,.pdfsales96
 
The population of a southern city follows the exponential law. If th.pdf
The population of a southern city follows the exponential law. If th.pdfThe population of a southern city follows the exponential law. If th.pdf
The population of a southern city follows the exponential law. If th.pdfsales96
 
Suppose the tree diagram below represents all the students in a high .pdf
Suppose the tree diagram below represents all the students in a high .pdfSuppose the tree diagram below represents all the students in a high .pdf
Suppose the tree diagram below represents all the students in a high .pdfsales96
 
Select all the functions below that are the primary responsibilities .pdf
Select all the functions below that are the primary responsibilities .pdfSelect all the functions below that are the primary responsibilities .pdf
Select all the functions below that are the primary responsibilities .pdfsales96
 
QUESTION 1 Prophage is a viral particle that cannot produce phages. O.pdf
QUESTION 1 Prophage is a viral particle that cannot produce phages. O.pdfQUESTION 1 Prophage is a viral particle that cannot produce phages. O.pdf
QUESTION 1 Prophage is a viral particle that cannot produce phages. O.pdfsales96
 
Philosophy questionExplain the principle known as Ockhams Razor..pdf
Philosophy questionExplain the principle known as Ockhams Razor..pdfPhilosophy questionExplain the principle known as Ockhams Razor..pdf
Philosophy questionExplain the principle known as Ockhams Razor..pdfsales96
 
Mycoplasma is a genus of bacteria that do not have a cell wall. Woul.pdf
Mycoplasma is a genus of bacteria that do not have a cell wall. Woul.pdfMycoplasma is a genus of bacteria that do not have a cell wall. Woul.pdf
Mycoplasma is a genus of bacteria that do not have a cell wall. Woul.pdfsales96
 
LinguisticsExercise 1. For each pair of sentences X and Y below, s.pdf
LinguisticsExercise 1. For each pair of sentences X and Y below, s.pdfLinguisticsExercise 1. For each pair of sentences X and Y below, s.pdf
LinguisticsExercise 1. For each pair of sentences X and Y below, s.pdfsales96
 
A department at a university plans to recruit a new faculty member. T.pdf
A department at a university plans to recruit a new faculty member. T.pdfA department at a university plans to recruit a new faculty member. T.pdf
A department at a university plans to recruit a new faculty member. T.pdfsales96
 
Informal financial institutions and its system are important in serv.pdf
Informal financial institutions and its system are important in serv.pdfInformal financial institutions and its system are important in serv.pdf
Informal financial institutions and its system are important in serv.pdfsales96
 
How to get pure culture from mixed sampleHow to get pure culture.pdf
How to get pure culture from mixed sampleHow to get pure culture.pdfHow to get pure culture from mixed sampleHow to get pure culture.pdf
How to get pure culture from mixed sampleHow to get pure culture.pdfsales96
 
How does insulin binding activate the insulin receptor List the ste.pdf
How does insulin binding activate the insulin receptor List the ste.pdfHow does insulin binding activate the insulin receptor List the ste.pdf
How does insulin binding activate the insulin receptor List the ste.pdfsales96
 
Given the tree what morphological characteristics do you expect to b.pdf
Given the tree what morphological characteristics do you expect to b.pdfGiven the tree what morphological characteristics do you expect to b.pdf
Given the tree what morphological characteristics do you expect to b.pdfsales96
 
Explain, in your own words, the concept of cloud computing. Do you b.pdf
Explain, in your own words, the concept of cloud computing. Do you b.pdfExplain, in your own words, the concept of cloud computing. Do you b.pdf
Explain, in your own words, the concept of cloud computing. Do you b.pdfsales96
 

More from sales96 (20)

Write a small program in ARM to Store these values into an array 0.pdf
Write a small program in ARM to  Store these values into an array 0.pdfWrite a small program in ARM to  Store these values into an array 0.pdf
Write a small program in ARM to Store these values into an array 0.pdf
 
Why that partial derivative is zero Why that partial derivative is .pdf
Why that partial derivative is zero Why that partial derivative is .pdfWhy that partial derivative is zero Why that partial derivative is .pdf
Why that partial derivative is zero Why that partial derivative is .pdf
 
Which two gases are the most important for aquatic organisms Wh.pdf
Which two gases are the most important for aquatic organisms Wh.pdfWhich two gases are the most important for aquatic organisms Wh.pdf
Which two gases are the most important for aquatic organisms Wh.pdf
 
Which cells of the pancreas are the endocrine cells How were you ab.pdf
Which cells of the pancreas are the endocrine cells How were you ab.pdfWhich cells of the pancreas are the endocrine cells How were you ab.pdf
Which cells of the pancreas are the endocrine cells How were you ab.pdf
 
What determines how much genetic variation exists in populations A..pdf
What determines how much genetic variation exists in populations A..pdfWhat determines how much genetic variation exists in populations A..pdf
What determines how much genetic variation exists in populations A..pdf
 
What are three types of Why are fossils important to scientists.pdf
What are three types of  Why are fossils important to scientists.pdfWhat are three types of  Why are fossils important to scientists.pdf
What are three types of Why are fossils important to scientists.pdf
 
This is a nursing informatics question...What is “Meaningful Use”,.pdf
This is a nursing informatics question...What is “Meaningful Use”,.pdfThis is a nursing informatics question...What is “Meaningful Use”,.pdf
This is a nursing informatics question...What is “Meaningful Use”,.pdf
 
The population of a southern city follows the exponential law. If th.pdf
The population of a southern city follows the exponential law. If th.pdfThe population of a southern city follows the exponential law. If th.pdf
The population of a southern city follows the exponential law. If th.pdf
 
Suppose the tree diagram below represents all the students in a high .pdf
Suppose the tree diagram below represents all the students in a high .pdfSuppose the tree diagram below represents all the students in a high .pdf
Suppose the tree diagram below represents all the students in a high .pdf
 
Select all the functions below that are the primary responsibilities .pdf
Select all the functions below that are the primary responsibilities .pdfSelect all the functions below that are the primary responsibilities .pdf
Select all the functions below that are the primary responsibilities .pdf
 
QUESTION 1 Prophage is a viral particle that cannot produce phages. O.pdf
QUESTION 1 Prophage is a viral particle that cannot produce phages. O.pdfQUESTION 1 Prophage is a viral particle that cannot produce phages. O.pdf
QUESTION 1 Prophage is a viral particle that cannot produce phages. O.pdf
 
Philosophy questionExplain the principle known as Ockhams Razor..pdf
Philosophy questionExplain the principle known as Ockhams Razor..pdfPhilosophy questionExplain the principle known as Ockhams Razor..pdf
Philosophy questionExplain the principle known as Ockhams Razor..pdf
 
Mycoplasma is a genus of bacteria that do not have a cell wall. Woul.pdf
Mycoplasma is a genus of bacteria that do not have a cell wall. Woul.pdfMycoplasma is a genus of bacteria that do not have a cell wall. Woul.pdf
Mycoplasma is a genus of bacteria that do not have a cell wall. Woul.pdf
 
LinguisticsExercise 1. For each pair of sentences X and Y below, s.pdf
LinguisticsExercise 1. For each pair of sentences X and Y below, s.pdfLinguisticsExercise 1. For each pair of sentences X and Y below, s.pdf
LinguisticsExercise 1. For each pair of sentences X and Y below, s.pdf
 
A department at a university plans to recruit a new faculty member. T.pdf
A department at a university plans to recruit a new faculty member. T.pdfA department at a university plans to recruit a new faculty member. T.pdf
A department at a university plans to recruit a new faculty member. T.pdf
 
Informal financial institutions and its system are important in serv.pdf
Informal financial institutions and its system are important in serv.pdfInformal financial institutions and its system are important in serv.pdf
Informal financial institutions and its system are important in serv.pdf
 
How to get pure culture from mixed sampleHow to get pure culture.pdf
How to get pure culture from mixed sampleHow to get pure culture.pdfHow to get pure culture from mixed sampleHow to get pure culture.pdf
How to get pure culture from mixed sampleHow to get pure culture.pdf
 
How does insulin binding activate the insulin receptor List the ste.pdf
How does insulin binding activate the insulin receptor List the ste.pdfHow does insulin binding activate the insulin receptor List the ste.pdf
How does insulin binding activate the insulin receptor List the ste.pdf
 
Given the tree what morphological characteristics do you expect to b.pdf
Given the tree what morphological characteristics do you expect to b.pdfGiven the tree what morphological characteristics do you expect to b.pdf
Given the tree what morphological characteristics do you expect to b.pdf
 
Explain, in your own words, the concept of cloud computing. Do you b.pdf
Explain, in your own words, the concept of cloud computing. Do you b.pdfExplain, in your own words, the concept of cloud computing. Do you b.pdf
Explain, in your own words, the concept of cloud computing. Do you b.pdf
 

Recently uploaded

AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
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
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 

Recently uploaded (20)

AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
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
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 

I came upon this and I would love to know how this works -)The ma.pdf

  • 1. I came upon this and I would love to know how this works :-) The majority of your development may take place in the function task2(). 1. You need to implement code to output the following line to the screen: –- Task 2 –- 2.Declare an int array named numbers and initialise it with the following values: 1 4 9 16 9 7 4 9 11 (2 marks) 3. Declare a second array of the same size and using a loop populate it with random numbers in the range of 1 – 25 inclusive. 4. Use a loop to compute the ‘total’ of the numbers based on the following rule: If the number being considered is odd then add this to the total, however if the number to be added is even then subtract this from the total. For example for the initialised array it would compute: 1 4 + 9 16 + 9 + 7 4 + 9 + 11 = 22 5. Print both of the arrays and the results of the ‘total’ operation. For example for the initialised array the output could resemble: [ 1, 4, 9, 16, 9, 7, 4, 9, 11 ] the total is RESULT Where RESULT is the calculated value from the ‘total’ operation. Notice that the lists should be comma space separated and that the final element in the list is not terminated with a comma but with a space followed by a square bracket. Also note that each line should begin with a left square bracket followed by a space. Solution // C++ code #include #include #include using namespace std; int main () { int array1[] = {1,4,9,16,9,7,4,9,11}; int size = sizeof(array1)/sizeof(array1[0]); int array2[size]; for (int i = 0; i < size; ++i) { // random numbers in the range of 1 – 25 inclusive.aa
  • 2. array2[i] = rand() % 25 + 1; } int total1 = 0; int total2 = 0; for (int i = 0; i < size; ++i) { if(array1[i]%2 == 0) total1 = total1 - array1[i]; else total1 = total1 + array1[i]; if(array2[i]%2 == 0) total2 = total2 - array2[i]; else total2 = total2 + array2[i]; } cout << " [ "; for (int i = 0; i < size-1; ++i) { cout << array1[i] << ", "; } cout << array1[size-1] << " ] the total is " << total1 << endl; cout << " [ "; for (int i = 0; i < size-1; ++i) { cout << array2[i] << ", "; } cout << array2[size-1] << " ] the total is " << total2 << endl; return 0; } /* output: [ 1, 4, 9, 16, 9, 7, 4, 9, 11 ] the total is 22 [ 9, 12, 3, 16, 19, 11, 12, 18, 25 ] the total is 9
  • 3. */