Here is code:
// C++ code to demonstrate star pattern
#include <iostream>
#include <limits>
using namespace std;
void triangle(int n)
{
for (int i = 0; i <= n / 2; i++)
{
int j = 0;
// space
for (j = 0; j < n / 2 - i; j++)
cout << " ";
for (int k = 0; k <= 2 * i; k++)
{
cout << "*";
j++;
}
cout << endl;
}
}
void diamond(int n)
{
int c, k, space = 1;
space = n / 2;
for (k = 1; k <= n / 2 + 1; k++)
{
for (c = 1; c <= space; c++)
cout << " ";
space--;
for (c = 1; c <= 2 * k - 1; c++)
cout << "*";
cout << "\n";
}
space = 1;
for (k = n / 2; k < n; k++)
{
for (c = 0; c < space; c++)
cout << " ";
space++;
for (c = 1; c <= 2 * (n - k) - 3; c++)
cout << "*";
cout << "\n";
}
}
void hill(int n)
{
for (int i = 0; i < n / 2 + 1; i++)
{
for (int j = 0; j <= i; j++)
{
cout << "*";
}
cout << endl;
}
}
int main()
{
int num;
cout << "Enter positive odd number : ";
while (!(cin >> num) || (num < 0 || num % 2 == 0))
{
// flush the cin data
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
cout << "Invalid entry, Try again : ";
}
cout << "Hill:" << endl;
hill(num);
cout << "Triangle:" << endl;
triangle(num);
cout << "Diamond:" << endl;
diamond(num);
return 0;
}
Output:

IN C++ Write a program using for loops to produce the following output. Please read carefully...
Today you are to write a Java program that will prompt for and
read 2 words of equal length entered by the user, and create a new
word which contains the last letter of the 1st word, the last
letter of the 2nd word, followed by the second to last character of
the 1st word, followed by the second to last character of the 2nd
word and so on. Be sure to use the same format and wording as in...
Write a C program that will produce the EXACT output shown below. Write a program to find out the number of words, spaces, vowels, consonants, along with special characters in a sentence. Take the data below as an example. Your C program should take the data in the arrays and produce the output below, neatly formatted as shown Enter a sentence: My cat’s name is Bella. You sentence includes: Number of words: 5 Number of spaces: 4 ...
Use Java program Material Covered : Loops & Methods Question 1: Write a program to calculate rectangle area. Some requirements: 1. User Scanner to collect user input for length & width 2. The formula is area = length * width 3. You must implement methods getLength, getWidth, getArea and displayData ▪ getLength – This method should ask the user to enter the rectangle’s length and then return that value as a double ▪ getWidth – This method should ask the...
1. Write a C++ program to output a framed greeting. The program will produce five lines of output. The first line begins the frame. It is a sequence of * characters as long as the person's name, plus some characters to match the salutation ("Hello, "), plus a space and an * at each end. The line after that will be an appropriate number of spaces with an * at each end. The third line is an *, a space,...
read it carefully C++
Question: Write a program that dynamically allocates an array large enough to hold a user-defined number of test scores. Once all the scores are entered, the array should be passed to a function that sorts them in ascending order. Another function should be called that calculates the average score. The program should display the sorted list of scores and averages with appropriate headings. Use pointer notation rather than array notation whenever possible. Input Validation: Do not...
Using loops, write a C# program that asks the user to enter repeatedly an integer number, it stops when the user enters -1, then the program should display how many numbers were entered, their the sum and their average
Please do this in C++ using only for loops, while loops, and do
while loops. No arrays.
Use for loop, while loop, and do while loops to generate a table of decimal numbers, as well as the binary, octal, and hexadecimal equivalents of the decimal numbers in the range 1-256 Note: See Appendix for number systems The program should print the results to the Console without using any string formats Design Details: The Main program should prompt the user for...
C++
Write a program that prompts the user to enter integers or a sentinel to stop. The program prints the highest and lowest numbers entered, the sum and the average. DO NOT USE ARRAYS, only variables and loops. Write a program the prompts the user to input a positive integer. Keep asking the user until a positive integer is entered. Once a positive integer is entered, print a message if the integer is prime or not. (NOTE: A number is...
C++ any help is appreciated Program Pattern#2: Write a program that uses nested loop or for statements to display Pattern A below, followed by an empty line and then another set of loops that displays Pattern B. Once again no setw implementation is allowed here but you must use nested loop or for statements with proper indentation to generate these patterns. Use meaningful variable identifier names, good prompting messages and appropriate comments for each loop segment as well as other...
In this lab, you will write a C program to encrypt a file. The program prompts the user to enter a key (maximum of 5 bytes), then the program uses the key to encrypt the file. Note that the user might enter more than 5 characters, but only the first 5 are used. If a new line before the five characters, the key is padded with 'a'; Note that the new line is not a part of the key, but...