## NPTEL An Introduction To Programming Through C++ Assignment 3 Answers (Week 3)

int count=0;

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

for (int j=1; j<=5; j+=i) {

for (int k=1; k<=5; k+=j) {

count++;

}

}

}

**Q1. What is the value of variable count at the end of execution?**

**Answer:** 39

A certain government levies taxes on a person’s total annual income. The taxes are calculated in the given manner. If a person earns an amount of less than or equal to Rs. 1,00,000 annually, the person doesn’t pay any tax.If a person earns an amount of more than Rs. 1,00,000 and less than or equal to Rs. 5,00,000, then the person is charged 5% on the amount.If a person earns an amount of more than Rs. 5,00,000, the person is charged with 5% of Rs. 5,00,000 and 10% of the remaining amount.

The following code snippet computes the total tax to be paid by a person given their annual income. You are to fill in the blanks so that the code computes the tax correctly.

int income;

cin>>income;

double tax;

if(income<=blank1) {

tax=0;

}

else if (income<blank2) {

tax=blank3*income

}

else {

tax=0.05*500000+0.10*(blank4)

}

cout<<tax<<end1;

**Q2. What should be filled in blank1?**

a. 0

b. 100000

c. 500000

d. 1000000

**Answer:** b. 100000

**Q3. What should be filled in blank2?**

a. 0

b. 100000

c. 500000

d. 1000000

**Answer:** c. 500000

**Q4.** **What should be filled in blank**3?

a. 0

b. 0.05

c. 0.1

d. 0.5

**Answer:** b. 0.05

**Q5. What should be filled in blank4?**

a. income

b. income-100000

c. income-500000

d. Income+100000

**Answer:** c. income-500000

Given below is a program fragment that is meant to calculate the average of all odd numbers given in the input. You are to fill in the blanks so that the code computes the average correctly.

int sum=0;

int count=0;

for(int i=0; i<n; i++){

int num;

cin>>num;

if(num%2==0) {

blank5;

}

blank6;

blank7;

}

cout<<sum/count<<endl;

**Q6. What should be filled in blank5?**

a. break

b. continue

c. sum+=num

d. return 0

**Answer:** b. continue

**Q7. What should be filled in blank6?**

a. continue

b. break

c. sum+=num

d. sum*=num

**Answer:** c. sum+=num

**Q8. What should be filled in blank7?**

a. count+=1

b. count-=1

c. count+=num

d. count+=2

**Answer:** a. count+=1

int last SeqLength=0: // stores the current length of sequence which is continuously increasing

int last=-1;

while(true) {

int num;

cin>>num;

if(num>last) {

blank 8;

}

else{

blank9;

}

last=num;

cout<<last SeqLength<<end1;

}

**Q9. What should be filled in blank8?**

a. lastSeqLength=0

b. lastSeqLength=1

c. lastSeqLength+=1

d. lastSeqLength-=1

**Answer:** c. lastSeqLength+=1

**Q10. What should be filled in blank9?**

a. lastSeqLength=1

b. lastSeqLength=0

c. lastSeqLength+=1

d. lastSeqLength-=1

**Answer:** a. lastSeqLength=1

**Disclaimer:** These answers are provided only for the purpose to help students to take references. This website does not claim any surety of 100% correct answers. So, this website urges you to complete your assignment yourself.

**Also Available:**

An Introduction to Programming Through C++ NPTEL Assignment 1 Answers

## Leave a comment