0% found this document useful (0 votes)
2 views

Problems Week 2

The document presents four programming problems: debugging a code snippet with errors, completing code to calculate the sum of two numbers, optimizing code to eliminate unnecessary variables, and writing a program to perform arithmetic operations on a variable. Each problem requires the reader to identify issues or complete tasks related to C++ programming. The problems cover fundamental concepts such as variable initialization, arithmetic operations, and code efficiency.

Uploaded by

gamingdop30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Problems Week 2

The document presents four programming problems: debugging a code snippet with errors, completing code to calculate the sum of two numbers, optimizing code to eliminate unnecessary variables, and writing a program to perform arithmetic operations on a variable. Each problem requires the reader to identify issues or complete tasks related to C++ programming. The problems cover fundamental concepts such as variable initialization, arithmetic operations, and code efficiency.

Uploaded by

gamingdop30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

PRACTICE QUESTIONS

PROBLEM 1 : Debugging

Identify the error in the following code:

#include <iostream>
Using namespace std ;
int main() {

int x = 5

cout << "Result: " << z ;

return 0;

PROBLEM 2: Code Completion

Complete the code to print the sum of two numbers:

#include <iostream>

Using namespace std ;


int main() {

int num1 = 10;

int num2 = 20;

// Write code to print sum

return 0;

PROBLEM 3 : Code Optimization


Optimize the following code to reduce unnecessary variables:

#include <iostream>

Using namespace std ;


int main() {
int x = 5;

int y = x + 2;

int z = y * 2;

cout << "Result: " << z l;

return 0;

PROBLEM 4 : Solve

Write a program that initializes a variable a with a value of 10. Then, subtract 3 from a, multiply the result
by 4, and print the final result.

You might also like