| |

VerySource

 Forgot password?
 Register
Search
View: 782|Reply: 4

Algorithm for finding a graph.

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-16 09:40:01
| Show all posts |Read mode
*****
                           * *
                          * *
                         * *
                        ***************
                          
                     Print an isosceles trapezoid with a height and an upper base of 5,
        
               Who can help me talk about the algorithm. Thank you
Reply

Use magic Report

0

Threads

9

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 Vietnam

Post time: 2020-2-5 08:45:01
| Show all posts
Output 5 *, and wrap
Cycle 5-K lines
   Back i box output a *
   Output 5 + 2 * i-2 spaces
   Output a *
   Output newline
   // The above can also generate the entire string before outputting
cycle
Output 5 + 2 * K *
Reply

Use magic Report

0

Threads

9

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-7-4 10:15:01
| Show all posts
Take a look at the following program to count triangles, which should help you:

#include<iostream.h>

void main()
{
const int position = 30; // Specify the position of the triangle vertex
const int lines = 6; // Specify the number of lines to be printed
    // Front lines-1 line
for( int i=0; i<lines-1; ++i)
{
for(int stars=0; stars<=80; ++stars)
{
if ((stars==position-i) || (stars==position+i))
cout <<'*';
else
cout << '';
}
cout << endl;
}
    // the last line
for(int stars=0; stars<=80; ++stars)
{
if ((stars>=position-i)&&(stars<=position+i))
cout <<'*';
else
cout << '';
}
}
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-2 21:15:01
| Show all posts
cout<<" *****"<<endle;
for(int i=1;i<=3;i++){
   for(int j=5-i;j>0;j--)
     cout<<'';
     cout<<'*';
   for(int k=5;k<=9;k+2)
     cout<<'';
     cout<<'*'<<endle;}
cout<<"*********"<<endle;
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-2 22:15:01
| Show all posts
There was a small mistake just now. Let’s take a look at this one
#include <iostream.h>

void main(){
cout<<" ***"<<endl;
for(int i=1;i<=3;i++){
   for(int j=5-i;j>0;j--)
     cout<<'';
     cout<<'*';
   for(int k=4;k<=4+2*i;k++)
     cout<<'';
     cout<<'*'<<endl;}
cout<<" *********"<<endl;
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list