#include<iostream>
using namespace std;
void calcSumAndDiff(int ,int, int &, int &);
void calcSumAndDiff(int n1,int n2, int &sum, int &diff){
sum = n1 + n2;
diff = n1 - n2;
}
int main()
{
int n1,n2,sum,diff;
n1=30;n2=10;
calcSumAndDiff(n1,n2,sum,diff);
cout<<"Sum is
:"<<sum<<endl;
cout<<"Diff is:"<<diff<<endl;
system("pause");
}
#include<iostream>
using namespace std;
void calcSumAndDiff(int ,int, int &, int &);
void calcSumAndDiff(int n1,int n2, int &sum, int
&diff){
sum = n1 + n2;
diff = n1 - n2;
}
int main()
{
int n1,n2,sum,diff;
n1=30;n2=10;
calcSumAndDiff(n1,n2,sum,diff);
cout<<"Sum is :"<<sum<<endl;
cout<<"Diff is:"<<diff<<endl;
}
#include<iostream> using namespace std; void calcSumAndDiff(int ,int, int &, int &); void calcSumAndDiff(int n1,int n2, int...
C++ question #include <iostream> using namespace std; void printReverse(int); int main() { int number = 12345; cout << "Original : " << number << endl; cout << "Reversed : "; printReverse(number); } void printReverse(int x) { if (x == 0) return; cout << x % 10; printReverse(x /= 10); } Modify the above recursive program to output the number in the same order. Note that the program still should break up the number and then output it in the...
What is the difference between these two programs? #include <iostream> using namespace std; int DontPanic(int & x); int z = 10; void main() { char x = 'y'; int y = 5; int z = 100; y = DontPanic(z); cout << x << " " << y << " " << z << endl; } int DontPanic(int & x) { int * p; p = & z; x = (*p)++ + 1; cout << x << " " << *p...
Consider the following C++ program: #include <iostream> using namespace std; void f1(int); void f2(int); void f3(int); int main() { f1(10); return 0; } void f1(int n) { f2(n + 5); } void f2(int n) { f3(n - 2); } void f3(int n) { cout << n << endl; // LINE 1 } Just before the program statement marked with the comment "LINE 1" is executed, how many stack frames will be on the program call stack?
16 Points) Question 3 Write down the outputs of the following program into the provided table include <iostream> using namespace std; void fun I(int a); int fun2(int a, int b); int x-3: int main) int x-1,y 0,z-2; x-fun2(y,z); cout sx fun 1 (z); cout (#xtytz(endl; y-fun2(x,x); cout <exty+zscendl; system("pause"); void fun 1 (int a) int fun2(int a, int b) int static c2; return atx; 16 Points) Question 3 Write down the outputs of the following program into the provided table...
#include <iostream> #include <string> using namespace std; int main() { int number; int sum = 0; while(true) { cout << "Please enter a number between 1 and 11: "; cin >> number; if (number >= 1 && number <= 11) { cout << number << endl; sum = sum + number; //only add the sum when number is in range: 1-11, so add wthin this if case } else { cout << number << endl; cout << "Out of range;...
#include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){ int number; int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl; displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl; return 0; } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...
what is the output for the following code? explain the steps. /*#include <iostream> using namespace std; int f(int &i) { i = 10; return(5 * i); } int main() { int n = 5; f(n); cout << n << "\n"; return 0; } #include <iostream> using namespace std; int sub1(int n) { n--; return n; } int main() { int m = 10; for(int j = 0; j < 10; j++) m -= sub1(j); cout << m << "\n"; return...
4) What is the output if the input istom - Sawyer? #include <iostream> using namespace std; int main() { string playerName; cout << "Enter name"; cin >> playerName; cout << endl « playerName; return 0; } a. Tom - Sawyer b. Tom Sawyer c. Tom d. Sawyer 5) Which XXX generates "Adam is 30 years old." as the output? #include <iostream> using namespace std; int main() { string name = "Adam"; int age = 30; XXX return 0; } a....
Write the missing statements for the following program. #include <iostream> using namespace std; int main(void) { int Num1; cout << "Enter 2 numbers: "; cin >> Num2; if (Num1 < Num2) cout << "Smallest number is " << Num1; else cout << "Smallest number is " << Num2; return 0; }
#include using namespace std; void test(); int x = 0; int main(){ cout << x << endl; test(); cout << x << endl; } void test(){ int x = 100; cout << x << endl; for(int x = 0; x < 5; x++){ cout << x << endl; } } how many separate variables named ‘x’ are created?