SlideShare a Scribd company logo
1 of 2
Download to read offline
What is wrong with this code? Please fix.
code:
#include
#include
#define ROWS 3
#define COLS 3
void display(double[ROWS][COLS]);
double main(){
double mat[ROWS][COLS] = { {1./2, 1, 0},
{0, 2./3, 0},
{-1./2, -1, 2./3} };
display(mat);
return 0;
}
void display(double nums[ROWS][COLS]) {
double rowNum, colNum;
for (rowNum = 0.; rowNum < ROWS; rowNum++)
{
for (colNum = 0.; colNum < COLS; colNum++)
printf("%1.1s", nums[rowNum][colNum]);
printf(" ");
}
}
Solution
#include
#include
#define ROWS 3
#define COLS 3
void display(double[ROWS][COLS]);
int main(){
double mat[ROWS][COLS] = { {1./2, 1, 0},
{0, 2./3, 0},
{-1./2, -1, 2./3} };
display(mat);
return 0;
}
void display(double nums[][COLS]) {
//problem with declaring array subscripts with double, so changed to int
int rowNum, colNum;
for (rowNum = 0.; rowNum < ROWS; rowNum++)
{
for (colNum = 0.; colNum < COLS; colNum++)
printf("%1.1ft", nums[rowNum][colNum]);
printf(" ");
}
}

More Related Content

Similar to What is wrong with this code Please fix.code#include stdio.h.pdf

Array.pptx
Array.pptxArray.pptx

Similar to What is wrong with this code Please fix.code#include stdio.h.pdf (20)

Oracle
OracleOracle
Oracle
 
SQL -PHP Tutorial
SQL -PHP TutorialSQL -PHP Tutorial
SQL -PHP Tutorial
 
R Language
R LanguageR Language
R Language
 
R programming
R programmingR programming
R programming
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
C++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdfC++ in 10 Hours.pdf.pdf
C++ in 10 Hours.pdf.pdf
 
Unit 2
Unit 2Unit 2
Unit 2
 
CHAPTER 5
CHAPTER 5CHAPTER 5
CHAPTER 5
 
Nesting of for loops using C++
Nesting of for loops using C++Nesting of for loops using C++
Nesting of for loops using C++
 
C operators
C operatorsC operators
C operators
 
Array.pptx
Array.pptxArray.pptx
Array.pptx
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Array in C.pdf
Array in C.pdfArray in C.pdf
Array in C.pdf
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
Arrays
ArraysArrays
Arrays
 
Programming Fundamentals Arrays and Strings
Programming Fundamentals   Arrays and Strings Programming Fundamentals   Arrays and Strings
Programming Fundamentals Arrays and Strings
 
Day 1c access, select ordering copy.pptx
Day 1c   access, select   ordering copy.pptxDay 1c   access, select   ordering copy.pptx
Day 1c access, select ordering copy.pptx
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
FALLSEM2022-23_BCSE202L_TH_VL2022230103292_Reference_Material_I_08-08-2022_C_...
 
Formatted Console I/O Operations in C++
Formatted Console I/O Operations in C++Formatted Console I/O Operations in C++
Formatted Console I/O Operations in C++
 

More from aroraopticals15

Evaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdfEvaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdf
aroraopticals15
 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf
aroraopticals15
 
Write short descriptive answer to the following questions Discuss wh.pdf
Write short descriptive answer to the following questions  Discuss wh.pdfWrite short descriptive answer to the following questions  Discuss wh.pdf
Write short descriptive answer to the following questions Discuss wh.pdf
aroraopticals15
 
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdfWhy do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
aroraopticals15
 
Which of following is not a class of the phylum platyhelminthes Tre.pdf
Which of following is not a class of the phylum platyhelminthes  Tre.pdfWhich of following is not a class of the phylum platyhelminthes  Tre.pdf
Which of following is not a class of the phylum platyhelminthes Tre.pdf
aroraopticals15
 
what is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdfwhat is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdf
aroraopticals15
 
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
Use the following word bank to complete the numbers 51-100.  Acoeloma.pdfUse the following word bank to complete the numbers 51-100.  Acoeloma.pdf
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
aroraopticals15
 
Todopackage hwk6; This class contains the configuration of a t.pdf
Todopackage hwk6; This class contains the configuration of a t.pdfTodopackage hwk6; This class contains the configuration of a t.pdf
Todopackage hwk6; This class contains the configuration of a t.pdf
aroraopticals15
 

More from aroraopticals15 (20)

For a given H0 and level of significance, if you reject the H0 for a.pdf
For a given H0 and level of significance, if you reject the H0 for a.pdfFor a given H0 and level of significance, if you reject the H0 for a.pdf
For a given H0 and level of significance, if you reject the H0 for a.pdf
 
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
Find all elements of our ring R that have norm 1. Show that no elemen.pdfFind all elements of our ring R that have norm 1. Show that no elemen.pdf
Find all elements of our ring R that have norm 1. Show that no elemen.pdf
 
Evaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdfEvaluate the decision to have a computer usage policy and the potent.pdf
Evaluate the decision to have a computer usage policy and the potent.pdf
 
(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf(java) eclipse PleaseDevelop an application that implements a pro.pdf
(java) eclipse PleaseDevelop an application that implements a pro.pdf
 
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdfAt a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
At a sudden contraction in a pipe the diameter changes from D_1 to D_.pdf
 
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
Above is a trace depicting mechanical activity of frog heart. A stud.pdfAbove is a trace depicting mechanical activity of frog heart. A stud.pdf
Above is a trace depicting mechanical activity of frog heart. A stud.pdf
 
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
A gymnosperm, such as Juniperus virginiana, that produces female con.pdfA gymnosperm, such as Juniperus virginiana, that produces female con.pdf
A gymnosperm, such as Juniperus virginiana, that produces female con.pdf
 
Write short descriptive answer to the following questions Discuss wh.pdf
Write short descriptive answer to the following questions  Discuss wh.pdfWrite short descriptive answer to the following questions  Discuss wh.pdf
Write short descriptive answer to the following questions Discuss wh.pdf
 
Why should anyone else care about what I do with my sewage on my own .pdf
Why should anyone else care about what I do with my sewage on my own .pdfWhy should anyone else care about what I do with my sewage on my own .pdf
Why should anyone else care about what I do with my sewage on my own .pdf
 
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdfWhy do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
Why do viral particles, zymosan on fungi, endotoxin (LPS) from gram .pdf
 
Which of the following used historicalcomparative methods in their .pdf
Which of the following used historicalcomparative methods in their .pdfWhich of the following used historicalcomparative methods in their .pdf
Which of the following used historicalcomparative methods in their .pdf
 
Which of following is not a class of the phylum platyhelminthes Tre.pdf
Which of following is not a class of the phylum platyhelminthes  Tre.pdfWhich of following is not a class of the phylum platyhelminthes  Tre.pdf
Which of following is not a class of the phylum platyhelminthes Tre.pdf
 
What are two ways that meiosis could produce gametes that contai.pdf
What are two ways that meiosis could produce gametes that contai.pdfWhat are two ways that meiosis could produce gametes that contai.pdf
What are two ways that meiosis could produce gametes that contai.pdf
 
what is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdfwhat is the process in society that made this change to advertising .pdf
what is the process in society that made this change to advertising .pdf
 
What is the best way to go about designing an Android AppSoluti.pdf
What is the best way to go about designing an Android AppSoluti.pdfWhat is the best way to go about designing an Android AppSoluti.pdf
What is the best way to go about designing an Android AppSoluti.pdf
 
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
Use the following word bank to complete the numbers 51-100.  Acoeloma.pdfUse the following word bank to complete the numbers 51-100.  Acoeloma.pdf
Use the following word bank to complete the numbers 51-100. Acoeloma.pdf
 
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
Two cards are randomly selected from a 52-card deck. What is the pro.pdfTwo cards are randomly selected from a 52-card deck. What is the pro.pdf
Two cards are randomly selected from a 52-card deck. What is the pro.pdf
 
Two labs are being compared to determine if they are providing the sa.pdf
Two labs are being compared to determine if they are providing the sa.pdfTwo labs are being compared to determine if they are providing the sa.pdf
Two labs are being compared to determine if they are providing the sa.pdf
 
Todopackage hwk6; This class contains the configuration of a t.pdf
Todopackage hwk6; This class contains the configuration of a t.pdfTodopackage hwk6; This class contains the configuration of a t.pdf
Todopackage hwk6; This class contains the configuration of a t.pdf
 
This question refers to the ABO blood type locus. Remember that the A.pdf
This question refers to the ABO blood type locus. Remember that the A.pdfThis question refers to the ABO blood type locus. Remember that the A.pdf
This question refers to the ABO blood type locus. Remember that the A.pdf
 

Recently uploaded

QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
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)

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
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
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
 
What is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptxWhat is 3 Way Matching Process in Odoo 17.pptx
What is 3 Way Matching Process in Odoo 17.pptx
 
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...
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
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
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 

What is wrong with this code Please fix.code#include stdio.h.pdf

  • 1. What is wrong with this code? Please fix. code: #include #include #define ROWS 3 #define COLS 3 void display(double[ROWS][COLS]); double main(){ double mat[ROWS][COLS] = { {1./2, 1, 0}, {0, 2./3, 0}, {-1./2, -1, 2./3} }; display(mat); return 0; } void display(double nums[ROWS][COLS]) { double rowNum, colNum; for (rowNum = 0.; rowNum < ROWS; rowNum++) { for (colNum = 0.; colNum < COLS; colNum++) printf("%1.1s", nums[rowNum][colNum]); printf(" "); } } Solution #include #include #define ROWS 3 #define COLS 3 void display(double[ROWS][COLS]); int main(){ double mat[ROWS][COLS] = { {1./2, 1, 0}, {0, 2./3, 0}, {-1./2, -1, 2./3} };
  • 2. display(mat); return 0; } void display(double nums[][COLS]) { //problem with declaring array subscripts with double, so changed to int int rowNum, colNum; for (rowNum = 0.; rowNum < ROWS; rowNum++) { for (colNum = 0.; colNum < COLS; colNum++) printf("%1.1ft", nums[rowNum][colNum]); printf(" "); } }