

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 material for Introduction to C++ Programming provides practice exercises with correct answers designed to support beginner programming learning and exam preparation. Topics include variables, data types, operators, input and output, control structures, loops, functions, arrays, and basic object-oriented programming concepts. Designed to help learners strengthen programming fundamentals, improve problem-solving skills, and build confidence in writing and understanding C++ code.
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(num2Wk usingknamespacekstd;k intkmain()k {k intknum;k//kdeclarekvariablek coutk<>knum;k//kreadkvaluekfromkkeyboardk ifk((numk%k2)k==k0)k//kIfk"num"kiskeven,kthenk coutk<