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:
*
**
***
*
)
1
Expert's answer
2012-04-17T09:54:09-0400
#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++; } }
Comments
Leave a comment