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; iExplanation / 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;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.