Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Debug two programs. Please help. Very few errors probably only two. Help me quic

ID: 3568567 • Letter: D

Question

Debug two programs. Please help. Very few errors probably only two. Help me quickly. Thanks.

Prog 1 :

//The program below compiles and runs, but causes run-time check failure at the end.

//Fix the problem please. Note, numbers is an array of 5 integers. Don't change that.

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

    int numbers[5], i;

    for(i = 1; i <=5; i++)

    {

           numbers[i] = i;

           cout << numbers[i] << " ";

    }

   _getch();

   return 0;

}


Prog 2:

//The program below does not compile due to some reason.

//Please fix the problem so it prints 0 1 2 3 4

//Note, only one place needs bechanged. If you need change more than one place, it's wrong.

#include <iostream>

#include <conio.h>

using namespace std;

int SIZE = 5;

int main()

{

    int numbers[SIZE], i;

    for(i = 0; i < SIZE; i++)  

    {

           numbers[i] = i;

           cout << numbers[i] << " ";

    }

    cout << endl;

   _getch();

   return 0;

}

Explanation / Answer

1.

#include <iostream>

#include <conio.h>

using namespace std;

int main()

{

int numbers[5], i;
for(i = 0; i< 5; i++)
//for(i = 1; i <=5; i++)

{

//numbers[i] = i;
numbers[i] = i+1;

cout << numbers[i] << " ";

}

_getch();

return 0;

}

2.

#include <iostream>

#include <conio.h>

using namespace std;

int SIZE = 5;

int main()

{

int numbers[SIZE], i;

for(i = 0; i < SIZE; i++)

{

numbers[i] = i;

cout << numbers[i] << " ";

}

cout << endl;

_getch();

return 0;

}

program no 2 is working completely fine

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote