64 702
Assignments Done
99,4%
Successfully Done
In September 2018

Answer to Question #8342 in C++ for Jason

Question #8342
Concerning star patterns: I understand how to print a quantity of lines (containing an equivalent quantity of stars (or other characters), however how would I be able to print a selective number of stars in each line? In other words, the program will first ask the user to enter the total number of stars/characters to be displayed, and then it will repeatedly display the above pattern until the exact number is displayed (for example: input '6' as total number, and the program will print:
*
**
***
*
)
Expert's answer
#include "iostream.h"

void main(){
int n;
cout<<"Enter a number: ";
cin>>n;
int k=1;
while (k<=n){
& for (int i=1;i<=k;i++) cout<<"*";
& cout<<"\n";
& k++;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions