Home > Net >  O answer!
O answer!

Time:09-20

求问这六道题用C#怎么编呢

CodePudding user response:

1. There is no doubt for loop double for
2. A) into a string format is convenient. Instead leng, b) the output of each know figures capture the Substring interception of bai, c). Capture all intercept to the storage array for loop traverse backwards
3. Double the for loop iterates through all of these number is only can be divided exactly by 1 and itself, is add to the array. Output is finished!
4. The formula of binary you know! Constant divided by modulo array, joining together! It is recommended to use the while () loop do {} while () also go
5. Constant comparison method of bubbling over
6. The switch () {case 0: case 1... }
so

CodePudding user response:

A

 
using System;

The namespace Study {
The class ExeC1 {
The static void Main () {

Bool flag=true;

While (flag) {
The Console. Write (" please input layer (2-10), enter 0 exit: ");
String value=(https://bbs.csdn.net/topics/Console.ReadLine);
Int layer;
if (! Int. TryParse (value, the out layer)) {
Console. WriteLine (" please enter a valid number!" );
continue;
}
If (layer==0) {
Flag=false;
continue;
}
If (layer & lt; 2 | | layer & gt; 10) {
Console. WriteLine (" please enter a number 2-10!" );
continue;
}

Triangle (layer);
}

}

The static void Triangle (int n) {
For (int y=1; Y & lt;=n; Y++) {
For (int space=n - y - 1; Space & gt;=0; Space -) {
The Console. Write (" ");
}
For (int star=1; Star & lt;=y * 2-1; Star++) {
The Console. Write (" * ");
}
Console. WriteLine ();
}
}

}
}

CodePudding user response:

Two, the topic request a bit torque, you can write directly to take off pants break wind with arrays, writing is not elegant. Lead to the back of the don't want to write.

 
using System;
using System.Collections.Generic;

The namespace Study {
The class ExeC2 {
The static void Main () {

Bool flag=true;

While (flag) {
The Console. Write (" please enter a positive integer, enter 0 exit: ");
String value=(https://bbs.csdn.net/topics/Console.ReadLine);
Int positiveInteger;
if (! Int. J TryParse (value, out positiveInteger)) {
Console. WriteLine (" please enter a valid number!" );
continue;
}
If (positiveInteger==0) {
Flag=false;
continue;
}
If (positiveInteger & lt; 0 {
Console. WriteLine (" please enter a positive integer!" );
continue;
}

Console. WriteLine (" the first question: ");
Console. WriteLine (Fun1 (positiveInteger));

Console. WriteLine (" the second question: ");
Fun2 (positiveInteger);

Console. WriteLine (" the third (1) : ");
Fun31 (positiveInteger);

Console. WriteLine (" the third (2) : ");
Fun32 (positiveInteger);


}

}

Static int Fun1 (int n) {

Int quotient=n;
int count=0;

While (quotient & gt;=10) {
count++;
Quotient/=10;
}

Return the count + 1;

}

The static void Fun2 (int n) {

Int [] array=PreProcessor (n);
Int count=1;

For (int I=array. The Length - 1; I & gt;=0; I -) {
The Console. Write (" first "+" : "+ count);
count++;
Console. WriteLine (array [I]);
}


}

The static void Fun31 (int n) {

Int [] array=PreProcessor (n);
Int count=1;

for (int i=0; i <=array. The Length - 1; I++) {
The Console. Write (" first "+ (array. The Length - count + 1). The ToString () +" : ");
count++;
Console. WriteLine (array [I]);
}

}

The static void Fun32 (int n) {

Int [] array=PreProcessor (n);
Int count=1;

for (int i=0; i <=array. The Length - 1; I++) {
count++;
The Console. Write (array [I]);
}
Console. WriteLine ();
}

Static int [] PreProcessor (int n) {

List Block=new List (a);

Int quotient=n;

While (quotient & gt;=1) {

Block. The Add (quotient % 10);
Quotient/=10;
}

Return block. ToArray ();

}


}
}

CodePudding user response:

reference 4 floor HZTLTGG response:
2, this topic requires a bit of a torque, you can write directly to take off pants break wind with arrays, writing is not elegant. Lead to the back of the don't want to write.

 
using System;
using System.Collections.Generic;

The namespace Study {
The class ExeC2 {
The static void Main () {

Bool flag=true;

While (flag) {
The Console. Write (" please enter a positive integer, enter 0 exit: ");
String value=(https://bbs.csdn.net/topics/Console.ReadLine);
Int positiveInteger;
if (! Int. J TryParse (value, out positiveInteger)) {
Console. WriteLine (" please enter a valid number!" );
continue;
}
If (positiveInteger==0) {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • C#
  • Related