#include <iostream>
using namespace std;
void drawRect(int h, int w) {}
int main() {}
Write a program that produces h x w rectangles comprised of alternating columns of 1's and 0's (where h and w all user-specified).
For example:
Enter the desired dimensions for a rectangle: 6 4
Result:
1010
1010
1010
1010
1010
1010
#include <iostream> using namespace std; void drawRect(int h, int w) { int n = 1; for (int i = 0; i < h; ++i) { for (int j = 0; j < w; ++j) { cout << n; n = (n+1)%2; } cout << endl; } } int main() { int h, w; cout << "Enter the desired dimensions for a rectangle: "; cin >> h >> w; drawRect(h, w); return 0; }
#include <iostream> using namespace std; void drawRect(int h, int w) {} int main() {} Write a...
#include <iostream> using namespace std; int main() {} Write a program that produces a line comprised of n alternating a's and b's, where n is user-specified. For example, the console content following a run of the completed program with an input of "5" is as follows: Enter a number: 5 A line of length 5: ababa
#include <iostream> using namespace std; void drawTriangle(int x) {} int main() {} Complete the program so that it produces a right-angle triangle of a user-specified height. For example: Enter a height for the triangle: 5 Result: * ** *** **** *****
#include <iostream> using namespace std; int main() { } Write a program that, given a user-specified integer, prints out the next 10 integers (in increasing order; each on its own line). For example, given an input of 3, the console content following a run of the completed program will look as follows: Enter a number: 3 4 5 6 7 8 9 10 11 12 13
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; }
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...
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?
Write following program using Switch statement. #include <iostream> using namespace std; int main() int number; cout << "Enter an integer cin >> number; if (number > B) cout << You entered a positive integer: " << number << endl; else if (number (8) cout<<"You entered a negative integer: " << number << endl; cout << "You entered e." << endl; cout << "This line is always printed." return 0;
#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; int * newZeroArray(int size) { //your code here } int main() { int size = 10; int * A = newZeroArray(size); for(int i = 0; i < size; i++) cout << A[i] << " "; cout << endl; }Write a function that takes a size, creates a new array of that size with all zeros, and returns the array. If the size is not a valid size for an array, do not return a valid...
#include<iostream> using namespace std; void twodigits(int original, int& first, int& second) { first = original / 10; second = original - first * 10; } int main(){ int original = 95; int first = 0; int second = 0; twodigits(original, first, second); cout << original << " => " << first << " and " << second << endl; return 0; } Write a function that takes two integers, numerator and denominator, as input parameters and output their...