

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This study guide for Introduction to C++ Programming contains beginner-level programming practice exercises with correct solutions. It covers fundamental C++ concepts such as input and output handling using cin and cout, variable declaration, arithmetic operations (addition, subtraction, multiplication, and division), and conditional logic using if statements for comparisons. The exercises include programs that calculate and display mathematical results between two user inputs, as well as logic to determine the larger number or check if two numbers are equal. The material is structured in a clear code-and-explanation format to support learning core programming logic, strengthen problem-solving skills, and build a strong foundation in C++ syntax and structure.
Typology: Exams
1 / 3
This page cannot be seen from the preview
Don't miss anything!


#include using namespace std; int main() { int num1, num2; // declare variables cout << "Enter two integers: \t"; // prompt user cin >> num >> num2; // read values from keyboard // output the results cout << "The sum is: \t\t" << num1 + num2 << "\n" << "The product is: \t" << num1 * num2 << "\n" << "The difference is: \t" << num1 - num2 << "\n" << "The quotient is: \t" << num1 / num2 << endl; return 0; //indicate successful termination }
#include using namespace std; int main() { int num1, num2; // declare variables cout << "Enter two integers: "; // prompt user cin >> num1 >> num2; // read values from keyboard // Compares if values of "num1" and "num2" are equal if (num1 == num2) // If condition is true, then cout << "These numbers are equal." << endl; if (num1 > num2) // If condition is true, then cout << num1 << " is larger." << endl; if (num2 > num1) // If condition is true, then cout << num2 << " is larger." << endl; return 0; //indicate successful termination }
#includeWWusi ngWnamespaceWstd;WintWmai n()W{ intWnum1,Wnum2,Wnum3,Wsmallest,Wlargest;W//declareWvariablesWcoutW <>Wnum1W>>Wnum2W>>Wnum3;W//readWvaluesWfromWkeyboardWlargestW=Wn um1;W//WassumeW"num1"WisWtheWlargest ifW(num2W>Wlargest)W//isW"num2"WlargerWthanW"largest"?WlargestW=Wnu m2;W//WthenW"num2"WisWtheWlargest ifW(num3W>Wlargest)W//isW"num3"WlargerWthanW"largest"?WlargestW=Wnu m3;W//WthenW"num3"WisWtheWlargest smallestW=Wnum1;W//WassumeW"num1"WisWtheWsmallest ifW(num2Wv usingvnamespacevstd;v intvmain()v {v intvnum;v//vdeclarevvariablev coutv<>vnum;v//vreadvvaluevfromvkeyboardv ifv((numv%v2)v==v0)v//vIfv"num"visveven,vthenv coutv<