#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; int main () { } Write a program that converts a numeric score (provided by the user) into a letter grade (A, B, C, D, or F). The point-to-letter conversion rules are as follows: score >= 90: A score >= 80 (but less than 90): B score >= 70 (but less than 80): C score >= 60 (but less than 70): D otherwise: F The completed program should produce console content as follows: Enter your...
#include <iostream> using namespace std; int main() { } Write a program that solicits a user-specified amount of numbers and their values, and then computes the average value, as well as their parity (how many even versus odd). Below is the console content of an example run of the completed program. How many numbers would you like to store? 8 Enter the 8 numbers: 0 7 3 1 5 6 2 3 Average value: 3.125 Parities: 3 even, 5 odd
#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 w) {} int main() {} Complete the program so that it produces a centered, isosceles triangle of a user-specified width. For example: Enter a width: 5 Result: ***** *** *
#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...