Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How would i make a pascal triangle that keeps adding another star until it hits the end limit

so I have 3 inputs a,b,c

ex 4, 7, 1

++++
+++++
++++++
+++++++

its supposed to look like this, it starts at 4 stars and keeps adding another star c times until it reaches 7
how would I code this Im very confused this is what I have so far

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#include <iostream>
#include <iomanip>

int main(){
    int r,a,b,c;
    std::cin>> a;
    std::cin>>b;
    std::cin>>c;
    for(int i = a; i <= b; i++) {
        for(int j = 1; j <=i; j++){
            std::cout << "*";
        }
        std::cout << "\n" ;
    }

}
    

>Solution :

While a is smaller than b, print "*" a times, then increment by c (step) for next iteration.

int main(){
    int a,b,c;
    std::cin>> a;
    std::cin>>b;
    std::cin>>c;
 while(a < b){
    for (int i =0; i < a;i++){
        cout << "*";
    }
    cout << endl;
    a+=c;
    }
    return 0;
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading