One Moto exam

Source: Internet
Author: User

Print the case. There are 19 rows in total and there can only be one for loop (the question has been provided)
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*****************
***************
*************
***********
*********
*******
*****
***
*
For (I = 0; I <19; I ++)
{

}

I searched for some answers online, as shown below:
1.
# Include <iostream>
# Include <iomanip>
# Include <string>
Using namespace STD;
Int main ()
{
Int A [2] = {-1, 1 };
String STR = "*******************";
Int I = 0, j = 9, T = 1;
For (I = 0; I <19; ++ I)
{
J + = A [I <10];
If (I! = 0) t = T + A [I <10] * 2;
Cout <SETW (j) <right <Str. substr (0, T) <Endl;
}
Return 0;
}

2.
# Include <stdio. h>
# Include <string. h>

Int main ()
{
Char * tempstr = "*******************";
Char * blank = ""; int I = 0;
Char * datastr [20];
Char blankstr [10]; for (I = 0; I <19; I ++)
{
Memset (datastr, 0, 20 );
Memset (blankstr,); if (I <10)
{
Memcpy (blankstr, blank, 9-I );
Memcpy (datastr, tempstr, (I + 1) * 2-1 );
}
Else
{
Memcpy (blankstr, blank, I-9 );
Memcpy (datastr, tempstr, (19-i) * 2-1 );
}
Printf ("% s", blankstr );
Printf ("% s \ n", datastr );
}
Return 0;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.