Hello!
Im writing a program that outputs some triangles and such. And I want to count the written *s. If anyone would help i would really appreciate it.
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char znak;
znak = '*';
int st_vrst = 0;
int ploscina_trikotnika, ploscina_kvadrata, obseg_kvadrata, h;
std::cout << "Vnesite število vrstic: ";
std::cin >> st_vrst;
std::cin.ignore();
// Trikotnik
for(int i=1; i<=st_vrst; i++)
{
int j=0;
int v=1;
j=v++;
h=(j+j)+1;
std::string str(i, znak);
std::cout << str << "\n";
}
cout << h << endl;
std::cout << "\n";
// Kvadrat
for(int i=1; i<=st_vrst; i++)
{
std::string str(st_vrst, znak);
std::cout << str << "\n";
ploscina_kvadrata=st_vrst*st_vrst;
}
std::cout << ploscina_kvadrata << endl;
std::cout << "\n";
// Trikotnika
for(int i=0;i<st_vrst;i++) {
for(int j=i;j<st_vrst;j++)
printf("*");
printf("\n");
}
for(int i=1; i<=st_vrst; i++)
{
std::string str(i, znak);
std::cout << str << "\n";
}
cout << endl;
// Kvadrat
for (int i=1; i<=st_vrst; i++)
cout << "*";
cout << endl;
for (int i=1; i<st_vrst-1; i++)
{
cout << "*";
for (int j=1; j<st_vrst-1; j++)
cout << ".";
cout << "*" << endl;
}
for (int i=1; i<=st_vrst; i++)
cout << "*";
cout << endl;
obseg_kvadrata=st_vrst+(2*st_vrst-2)+(st_vrst-2);
cout << obseg_kvadrata << endl;
std::cin.get();
return 0;
}
Output would be:
*
**
***
****
*****
******
21
******
******
******
******
******
******
36
******
*****
****
***
**
*
*
**
***
****
*****
******
42
******
*....*
*....*
*....*
*....*
******
20
Thanks in advance!