: : : how do I write a code like
: : :
: : : *
: : : **
: : : ***
: : : ****
: : :
: : : and so on? I am beginning to learn C++.
: : :
: : :
: : :
: :
: : In C++
: :
: : #include <cstdio>
: :
: : using namespace std;
: :
: : int main(void)
: : {
: : for (int i = 0; i < 4; ++ i)
: : {
: : for (int j = 0; j < i; ++ i)
: : putchar('*');
: : puts("\n\r");
: : }
: : return 0;
: : }
: :
: : in C:
: :
: :
: : #include <stdio.h>
: :
: : int main(void)
: : {
: : int i, j;
: : for (i = 0; i < 4; ++ i)
: : {
: : for (j = 0; j < i; ++ i)
: : putchar('*');
: : puts("\n\r");
: : }
: : return 0;
: : }
: :
: : Basically, the only real difference between C and C++ in that in C you cannot declare varible within for loops.
: :
:
:
: Please, stop doing other people's homework, we really don't need to encourage them to get more than 10 posts like this per week. Try to give him a point in the right direction, but please don't provide the whole solution without any effort made from the OP's side.
:
Sometimes knowing the solution to a given problem can help one in understanding the process of devising the solution. However, fair enough I shall change the nature of my replys to such problems in the future, unless they give me bribes.