Problems Week 2

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy