Are you looking for the Answers to **NPTEL An Introduction to Programming Through C++ Assignment 4? **This article will help you with the answer to the **Nation**** al Programme on Technology Enhanced Learning (NPTEL)** Course “

**“**

**NPTEL An Introduction to Programming Through C++ Assignment 4**## What is An Introduction to Programming Through C++?

This course provides an introduction to problem solving and programming using the C++ programming language. The topics include:

- Basic programming notions. Control flow, variables and assignments statements, conditional execution, looping, function calls including recursion. Arrays and structures. Elementary aspects of classes. Heap memory.
- Program design. How human beings solve problems manually. Strategies for translating manual strategies to computer programs. Organizing large programs into units such as functions and classes. Introduction to assertions and invariants.
- Programming applications. Arithmetic on polynomials, matrices. Root finding. Sorting and searching. Design of editors and simulators, including graphical editors. Elementary animation. A rudimentary graphics system will be discussed.
- Standard Library of C++. The string, vector and map classes.

## CRITERIA TO GET A CERTIFICATE

Average assignment score = 25% of the average of best 8 assignments out of the total 12 assignments given in the course.

Exam score = 75% of the proctored certification exam score out of 100

Final score = Average assignment score + Exam score

**YOU WILL BE ELIGIBLE FOR A CERTIFICATE ONLY IF THE AVERAGE ASSIGNMENT SCORE >=10/25 AND EXAM SCORE >= 30/75. If one of the 2 criteria is not met, you will not get the certificate even if the Final score >= 40/100.**

** Below you can find the answers for NPTEL An Introduction to Programming Through C++ Assignment 4**

Assignment No. | Answers |
---|---|

An Intro to Programming C++ Assignment 1 | Click Here |

An Intro to Programming C++ Assignment 2 | Click Here |

An Intro to Programming C++ Assignment 3 | Click Here |

An Intro to Programming C++ Assignment 4 | Click Here |

An Intro to Programming C++ Assignment 5 | Click Here |

An Intro to Programming C++ Assignment 6 | Click Here |

An Intro to Programming C++ Assignment 7 | Click Here |

An Intro to Programming C++ Assignment 8 | Click Here |

## NPTEL An Introduction to Programming Through C++ Assignment 4 Answers:-

Given an integer N >=2, we need to output all its prime factors in increasing order. To do this, we exploit the fact that if N is composite, it has a prime factor that is <= √N. If it is prime, then N itself is the only prime factor of itself.

**Q1.** What would be blank1 (we need to check division by numbers upto what value of x):

**Answer:-** **b**

**Q2.** What would be blank2 (if N is divisible by x, then we print x as a factor and then must remove it from N):

**Answer:-** **c**

**Q3.** What would be blank3 (this case occurs when N is prime):

**Answer:-** **c**

???? **Next Week Answers: Assignment 05** ????

**Q4.** The numerical integration program discussed in the lecture estimates the area under the curve f(x) between p+iw and p+(i+1)w by f(p+iw)*w. Which of these is correct:

**Answer:-** **b**

**Q5.** We know that the roots of the functions f(x) = x² and g(x) = x⁴ are x = 0. However, we decide to employ the Newton-Raphson method to estimate their roots. We begin with x_{0} = 1 for both these functions. Consider the following statements:

**Answer:-** **a**

**Q6.** What does the following program output for any given positive integers ‘a’ and ‘b’?

**Answer:-** **a**

**Q7.** What is the output of the following code snippet?

**Answer:-** **d**

**Q8.** What is the output of the following code snippet?

**Answer:-** **c**

Given below is the code to find the number of digits in the binary representation (base 2)of a given number x, without leading zeros (x>0). Answer the following questions basedon this.

**Q9.** What is BLANK_P (Integer answer)

**Answer:-** **1**

**Q10.** What is BLANK_Q

**Answer:-** **c**

**Q11.** What is BLANK_R (Integer answer)

**Answer:-** **2**

**Q12.** Suppose you are given a 1000 digit number(N) and without storing all the digits of either the number or the quotient we want to find the quotient when N is divided by another given number (small enough to be stored, say p). Which of the following is true?

**Answer:-** **c**

## Programming Assignment

**Q1.** In continuation of the topic of computing mathematical functions explored in the lectures, we see another method to find square roots. Suppose we wish to find the square root of some k > 0. Consider the sequence (a_{0}, a_{1}, a_{2}…) defined by

**Code:-**

```
main_program
{
double k,a1,a2,x;
cin>>k;
a1=k;
a2=(a1+(k/a1))/2;
while ((a1-a2)>=0.00001)
{
a1=a2;
a2=(a1+(k/a1))/2;
}
cout.precision(2);
cout <<fixed <<a2 << endl;
}
```

**Q2.** Write a program to keep track of a match consisting of a series of games between two people: player A and player B, and report the outcome. The input consists of a sequence of letters A or B. If the input is A, it indicates that A has won a game. If it is B, then it indicates B has won a game. The first player to win 5 or more games with a difference of 2 or more games between him and his opponent wins the match. If no player wins the match in 20 games then the match is declared a tie after these 20 games have been played.

**Code:-**

```
main_program
{
char ch;
int A=0,B=0,count=1;
while(count <=20)
{
cin>>ch;
switch(ch)
{
case 'A':
A++;
break;
case 'B':
B++;
break;
}
count++;
}
if(A==B)
cout<<"Tie" <<endl;
else if((A-B) >1)
cout<<"A"<<endl;
else
cout<<"B"<<endl;
}
```

**For other courses answers:- Visit**

**For Internship and job updates:- Visit **

**Disclaimer**:- We do not claim 100% surety of solutions, these solutions are based on our sole expertise, and by using posting these answers we are simply looking to help students as a reference, so we urge do your assignment on your own.