# A set of C ++ exercises (including answers) for your reference! Author: yaozheng

Source: Internet
Author: User
 Some of the questions I have helped others do today are representative. I will post all the answers here for your reference. All programs are successfully debugged in the Visual C ++ 6.0 environment. If you have a better solution to a program, you are welcome to share with us. Because of the limited time, no comments are written. If you do not understand any program, you can also share with me.I. multiple choice questions:1. The extension of the C ++ source program file is:A). cpp B). c). dll d). exe2. Assign the lowercase letter N to the character variable one_char. The correct operation is: C.A) one_char = '/N'; B) one_char = "N ";C) one_char = 110; d) one_char = 'n ';3. After I defines the integer variable, the initial value is assigned as B.Int I = 2.8*6;A) 12 B) 16 C) 17 d) 184. Which of the following expressions is false? CA) 1 <3 & 5 <7 B )! (2> 4) c) 3 & 0 & 1 d )! (5 <8) | (2 <8)5. Set int A = 10, B = 11, c = 12; expression (A + B). The value of 10 | x <20 C) x> 10 & x <20 d )! (X <= 10 | x> = 20)9. If the integer variable X = 2, the result of expression x <2 is: dA) 2 B) 4 C) 6 d) 810. If expression a = 1 and B = 2, the values of the expressions (A ++) + B and A ++ B are:A) 3, 3 B) 3, 4 C) 4, 3 d) 42. Fill in the program blank.1. The following program calculates the sum of natural numbers that can be divisible by 3 within 1000.# Include Void main (){Int x = 1, sum;Sum = 0 _______;While (true){If (x> 1000) break;If (X % 3 = 0) sum + = X;X ++;}Cout Void main (){Int A, B, C, X;A = B = C = 0;For (int K = 0; k <10; k ++){CIN> X;Switch (X % 3){Case 0: A + = x; break;Case 1: B + = x; break;Case 2: C ++ = x; break;}}Cout Void main (){Int J, K;For (j = 5; j> 0; j --){For (k = J; k> 0; k --)Cout <"*";Cout # Include Void main (){Cout <"x_width =" Using namespace STD;Void main (){Int A, B, C;For (INT I = 100; I <= 999; I ++){A = I/100;B = I % 100/10;C = I % 10;If (A * a * A + B * B * B + C * c = I)Cout Using namespace STD;Void main (){Int N, S, sum = 0;Cin> N;For (INT I = 1; I <= N; I ++){S = 0;For (Int J = 1; j <= I; j ++)S + = J;Sum + = s;}Cout Using namespace STD;Void main (){Int cost;Double price, D;Cin> cost;If (Cost & gt; 5000)D = 0.8;Switch (Cost/1000){Case 0: D = 1.0; break;Case 1: D = 0.95; break;Case 2: D = 0.9; break;Case 3: Case 4: D = 0.85; break;}Price = Cost * D;Cout Using namespace STD;Void main (){Int A, B, C, Count = 0;For (A = 1; A <100; A ++)For (B = 1; B <100; B ++)For (C = 1; C <100; C ++)If (C * 5 + B * 2 + A = 100){Count ++;Cout <"1 point:" Using namespace STD;Void main (){For (INT I = 1; I <10000; I ++){If (I <10 & I = I * I % 10)Cout

Welcome to programming enthusiast's website
Http://www.programfan.com/

Below are the follow-up posts

# Include <iostream>
Using namespace STD;
Void main ()
{
Int N, S = 0, sum = 0;
Cin> N;
For (INT I = 1; I <= N; I ++)
{
S = S + I;
Sum + = s;
}
Cout <sum <Endl;
}

 # Include Void main (){Int I, N, S, sum, counter;Sum = 0;S = 0;Counter = 1;Printf ("/ninput a number! /N ");Scanf ("% d", & N );For (I = 1; I <= N; I ++){S + = counter;Sum + = s;Counter ++;}Pritnf ("result is: % d/N", sum );}This program is implemented in C language,A loop is missing from the answer,It may be more efficient!

 // 3. Write a program and calculate S = 1 + (1 + 2) + (1 + 2 + 3) +... + (1 + 2 + 3 +... + N) Value// If anyone uses the formula |, ^, <, >>, & and so on, I really admire it!# Include Using namespace STD;Void main (){Int N;Cin> N;Cout <"Result :"<(N * (n + 1) * (N + 2)/6

I just learned C ++. Please give me some advice!

# Include <iostream. h>
Long fun (int)
{
S + =;
Sum + = s;
If (a = 1)
Returm sum;
Else
Returm fun (A-1); // is the call function correct?

}
Void main ()
{
Long fun (int)
Int X, S, sum;
S = 0;
Sum = 0;

Long y;
Cout <"enter an integer :";
Cin> X;
Y = fun (X );
Cout <"sum =" <Y;
Returm;
}

 The younger brother just learned the C language and made some questions about Lo and VE, which is not good. But I want to focus on participation in everything, so I will stick it to it. Mo Xiao:# Include Main (){Int N, S = 0, j = 1, I;Printf ("Please input num:/N ");Scanf ("% d", & N );For (I = N; I> = 0; I --){S + = J * I;J ++;}Printf ("% d", S );}

Lo and VE

The method may be better than I did on the 6th floor! Please ask him to publish his answer.

// The following is a low-efficiency Recursive Implementation.
# Include <iostream>
Using namespace STD;

Long CAL (int n ){
Return (n = 1 )? 1: Cal (n-1) + N * (n + 1)/2;
}
Void main (){
Int I;
Cin> I;
Cout <"Result:" <CAL (I) <Endl;
}

Related Keywords:
Related Article

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.