#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
Code:
#include<iostream>
using namespace std;
int main()
{
int n;//Declaring a variable
printf("Enter a number:");
scanf("%d",&n);//Taking input from the user
printf("A line of length %d :",n);
for(int i=0;i<n;i++)
{
if(i%2==0) printf("a");//Printing a
in place of even positions
else printf("b");//Printing b in
place of odd positions
}
return 0;
}
Ouput:
#include <iostream> using namespace std; int main() {} Write a program that produces a line comprised...
#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
#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 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: * ** *** **** *****
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;
This program illustrates dynamic variables #include <iostream> using namespace std; int main () { int *p1; p1 = new int; // Variables created using the new operator are called dynamic variables cout << "Enter an integer \n"; cin >> *p1; *p1 = *p1 + 7; cout << << "Your input + 7 = " << *p1 << endl; delete p1; // Delete the dynamic variable p1 and return the memory occupied by p1 to...
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; }
Consider the following C++ program: #include <iostream> #include <cstdlib> using namespace std; int main int n =0; int i = 0; cout << "Please enter a strictly positive number:"; cin >> n if (n <= 0) exit(EXIT_FAILURE) while (n > 1) n-n/2; i << endl; cout"Output:" return 0; Answer the following questions: What is the output of the program for each of the following values of n: -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9? What does...
What is the output of this program? #include<iostream> using namespace std; int main() { int x=4, y=4, z=4; x += 2; y = z++; z = ++x + y; cout<<x<<" "<<y<<" "<<z<<endl; return 0; } Group of answer choices 4 4 4 7 4 11 7 5 12 6 5 11
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?
Add comments on this Fibonacci C++ program in detail. #include <iostream> using namespace std; int fib(int n){ int a = 0,b = 1,c; if(n == 0 || n == 1){ return n; } while(n>2){ c = b + a; a = b; b = c; n--; } return c; } int main(){ int n; cout<<"Enter n: "; cin>>n; int result = fib(n); cout<<"Fib("<<n<<") = "<<result<<endl; return 0; }