(1) A triangle of starts (the user supplies the height): * ** *** **** (2) Anoth
ID: 3640743 • Letter: #
Question
(1) A triangle of starts (the user supplies the height):*
**
***
****
(2) Another triangle of stars (the user supplies the height):
*
***
*****
*******
(3) Another triangles of stars (the user supplies the height):
*
**
***
****
***
**
*
(4) A double rectangle of stars (the user supplies the height):
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
(5) A table of power of 2 (user supplies the number)
2 to the power 0 is 1
2 to the power 1 is 2
2 to the power 2 is 4
2 to the power 3 is 8
(6) A table of factorials (user supplies the number)
1! = 1 = 1
2! = 2 x 1 = 2
3! = 3 x 2 x 1 = 6
4! = 4 x 3 x 2 x 1 = 24
5! = 5 x 4 x 3 x 2 x 1 = 120
Explanation / Answer
Please rate...
1.
#include<iostream>
using namespace std;
int main()
{
int i,j,h;
cout<<"Enter the height: ";
cin>>h;
for(i=1;i<=h;i++)
{
for(j=1;j<=i;j++)
{
cout<<'*';
}
cout<<" ";
}
}
2.
#include<iostream>
using namespace std;
int main()
{
int i,j,h;
cout<<"Enter the height: ";
cin>>h;
for(i=0;i<h;i++)
{
for(j=1;j<=(2*i)+1;j++)
{
cout<<'*';
}
cout<<" ";
}
}
3.
#include<iostream>
using namespace std;
int main()
{
int i,j,h;
cout<<"Enter the height: ";
cin>>h;
for(i=1;i<=h/2;i++)
{
for(j=1;j<=i;j++)
{
cout<<'*';
}
cout<<" ";
}
if(h%2!=0)
{
for(j=1;j<=(h/2)+1;j++)
{
cout<<'*';
}
cout<<" ";
}
for(i=1;i<=h/2;i++)
{
for(j=i;j<=h/2;j++)
{
cout<<'*';
}
cout<<" ";
}
}
4.
#include<iostream>
using namespace std;
int main()
{
int i,j,h;
cout<<"Enter the height: ";
cin>>h;
for(i=1;i<=h;i++)
{
if(i%2!=0)
{
for(j=1;j<=h;j++)
{
cout<<'*';
}
cout<<" ";
}
if(i%2==0)
{
for(j=1;j<=h-1;j++)
{
cout<<'*';
}
cout<<" ";
}
}
}
5.
#include<iostream>
using namespace std;
int main()
{
int j,h;
cout<<"Enter the number: ";
cin>>h;
for(j=0;j<=h+1;j++)
{
cout<<" ";
cout<<h<<" to the power "<<j<<" is "<<(j*h);
}
}
6.
#include<iostream>
using namespace std;
int main()
{
int i,j,h,m;
cout<<"Enter the number: ";
cin>>h;
for(i=1;i<=h;i++)
{
m=1;
cout<<i<<"! = ";
for(j=i;j>=2;j--)
{
cout<<j<<" * ";
m=m*j;
}
cout<<"1 = "<<m<<" ";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.