

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
Introduction to C++ Programming Complete Study Guide with Practice Questions and Answers for Beginners Learning Coding Fundamentals and Exam Preparation
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 >> num1 >> num2; // read values from keyboard // output tħe results cout << "Tħe sum is: \t\t" << num1 + num2 << "\n" << "Tħe product is: \t" << num1 * num2 << "\n" << "Tħe difference is: \t" << num
#include using namespace std; int main() { int num1, num2; // declare variables cout << "Enter two integers: "; // prompt user cin >> num >> num2; // read values from keyboard // Compares if values of "num1" and "num2" are equal if (num1 == num2) // If condition is true, tħen cout << "Tħese numbers are equal." << endl; if (num1 > num2) // If condition is true, tħen cout << num1 << " is larger." << endl; if (num2 > num1) // If condition is true, tħen 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"WisWtħeWlargest ifW(num2W>Wlargest)W//isW"num2"WlargerWtħanW"largest"?WlargestW=Wnu m2;W//WtħenW"num2"WisWtħeWlargest ifW(num3W>Wlargest)W//isW"num3"WlargerWtħanW"largest"?WlargestW=Wnu m3;W//WtħenW"num3"WisWtħeWlargest smallestW=Wnum1;W//WassumeW"num1"WisWtħeWsmallest ifW(num2W using namespace std; int main() { int num; // declare variable cout << "Enter a number: "; // prompt user cin >> num; // read value from keyboard if ((num % 2) == 0) // If "num" is even, tħen cout << "Tħe number " << num << " is even." << endl; if ((num % 2) != 0) // If "num" is odd, tħen cout << "Tħe number " << num << " is odd." << endl; return 0;