Academy Online tsinghuax:00740043x C + + Language Programming Fundamentals Chapter II Lab

Source: Internet
Author: User

First question: Simple topic (summation, maximum, minimum value)

Title Description

Any given n integer, the value and the minimum and maximum values of the n integer sequence are obtained.

Enter a description

Enter an integer n, which means to enter an integer number, n<=100, and then enter n integers, integers are represented by an int.

Output description

Outputs the and, minimum, and maximum values of an integer sequence. Space separated by a line

Sample input

2
1 2

Sample output

3 1 2
#include <iostream>using namespacestd;intMain () {intn,a,i,sum=0, min=0, max=0; CIN>>N;  for(i=1; i<=n;i++) {cin>>A; Sum+=A; if(i==1) {Max=a,min=A; }Else        {            if(a>max) {Max=A; }            if(a<min) {min=A; } }} cout<<sum<<" "<<min<<" "<<max<<Endl; return 0;}

Question two: The conversion of the binary

Title Description

A binary number that contains only 0 and 1 is known, and the length is not greater than 10, and it is converted to decimal and output.

Enter a description

Enter a binary integer n, whose length is not greater than 10

Output description

Output converted decimal number, in one row

Sample input

110

Sample output

6

#include <stdio.h>#defineM 50voidBinarytodecimal (intBTD) {    intTmp[m],i=0, c=0;  while(btd!=0) {Tmp[i]=btd%Ten; BTD/=Ten; I++; } I--;  for(; i>=0; i--) C=c*2+Tmp[i]; printf ("%d", c);}intMainintargcConst Char*argv[]) {    intm; scanf ("%d",&m);    Binarytodecimal (m); return 0;}

Title Three: Solid Diamond

Title Description

Print n-Order solid Diamond

Enter a description

Enter an integer n,n<=10

Output description

Output n-order solid diamond, accounting for 2*n-1 line

Sample input

3

Sample output

  *
***
*****
***
*
#include <stdio.h>voidDiamondintN//N represents the top triangle row-half diagonal length{    inti,j; //first output the upper triangle     for(i=1; i<=n;++i)//Output N Rows    {        //Output Line I         for(j=1; j<=n-i;j++)//output n-i Spaces firstprintf" ");  for(j=1; j<=2*i-1; j + +)//and then output 2*i-1 an asterisk, and then this line doesn't matter.printf"*"); printf ("\ n"); }/*ssss*1 sss***2 ss*****3 s*******n-1 *********n space space obviously each line is n-1, * number is 2*i-1 (I starting from 1)*/    //below the output of the triangle, the longest line in the middle has been output above     for(i=1; i<=n-1; i++)//Output n-1 Line    {        //Output Line I         for(j=1; j<=i;j++)//Output I spacesprintf" ");  for(j=1; j<=2* (N-i)-1; j + +)//output (n-i)-1 asterisksprintf"*"); printf ("\ n"); }}/*s*******1 ss*****2 sss***3 ssss*n-1 space space obviously each line is I, * number is (n-i)-1 (I starting from 1)*/intMainintargcConst Char*argv[]) {    intN; scanf ("%d",&N); Diamond (n);}

Academy Online tsinghuax:00740043x C + + Language Programming Fundamentals Chapter II Lab

Related Article

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.