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

2. Using the GNU Debugger (gdb) To learn C/C++ program debugging using the GNU D

ID: 3684547 • Letter: 2

Question

2. Using the GNU Debugger (gdb)

To learn C/C++ program debugging using the GNU Debugger (i.e., gdb), we will create the follogin C++ program that calculates and prints the factorial of a number The factorial of a number n is given as 12.. * n, so for example, the factorial of the number 3-1 * 2 * 3 6 However, this program contains some errors in it for our debugging purposes. Line 1: #include Line 2: using namespace std; Line 4: int main( Line 5: Line 6 Line 7: Line 8: int i, num, j c ut num; for (i 1; i

Explanation / Answer

Corrected program is as follows:

#include<iostream>
using namespace std;

int main()
{
   int i, num, j=1;

   cout<<"Enter the number";
   cin>>num;
  
   for(i=1;i<=num;i++)
   {
       j=j*i;
   }

   cout<<"Factorial of "<<num<<" is "<<j<<"."<<endl;

   return 0;
}

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