C ++ cyclic program assignments: Assignments in October 10, 2017 ., Assignments for April 2017

Source: Internet
Author: User

C ++ cyclic program assignments: Assignments in October 10, 2017 ., Assignments for April 2017

Job 1:

Requirement: Output a rectangle composed of * symbols. Each line must have 50 *, and a total of 60 lines are required. Use a dual for loop.

Job 2:

Requirement: Output a triangle composed of * symbols. The first line is required to be a *, the second line is two * The third line is three *, and the last line is 10 *. Use a dual for loop.

Job 3:

Requirement: Output a triangle composed of * symbols, which requires 10 characters in the first line *, 9 in the second line * 8 in the third line *, and 1 in the last line *. Use a dual for loop.

Job 4:

Requirement: Use a double-layer for loop to complete the following triangles

5 4 3 2 1

5 4 3 2

5 4 3

5 4

5

#include <iostream>using namespace std;int main(){    for(int i=1;i<=5;i++){        for(int j=5;j>=i;j--){            cout<<j;        }    cout<<endl;    }    return 0;}

Job 5:

Requirement: Output multiplication tips, which are completed using a dual for Loop

1*1 = 1

1*2 = 2 2*2 = 4

1*3 = 3 2*3 = 6 3*3 = 9

1*4 = 4 2*4 = 8 3*4 = 12 4*4 = 16

1*5 = 5 2*5 = 10 3*5 = 15 4*5 = 20 5*5 = 25

#include <iostream>using namespace std;int main(){for(int i=1;i<=9;i++){for(int j=1;j<=i;j++){cout<<j<<"*"<<i<<"="<<j*i<<"\t";}cout<<endl;}return 0;}

What is the difference between break and continue?

What is the output result of the program?

#include <iostream>using namespace std;int main(){    for(int i=0;i<3;i++){        cout<<"i="<<i;        continue;        }        }    return 0;}

View output results?

#include <iostream>using namespace std;int main(){    for(int i=0;i<3;i++){        if(i==2){            break;        }        cout<<"i="<<i<<endl;        }        return 0;}

What is the output result?

#include <iostream>using namespace std;int main(){    for(int i=0;i<18;i++){        if(i%2==0){            continue;        }        cout<<"i="<<i<<endl;        }        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.