C # Summary of basic learning,

Source: Internet
Author: User

C # Summary of basic learning,

1. C # basic Mind Map

Else ---------------------------------------------------------------------------------------------------------------------------------

Bytes ---------------------------------------------------------------------------------------------------------------------------

Through the study of C # basic knowledge, I have a certain understanding of C #, in the process of learning can also use the knowledge to write some simple code programs.

For example, the sum, the quantity of quality, the 9-9 multiplication table, the income calculator, and the array analyzer.

Bytes ---------------------------------------------------------------------------------------------------------------------------

Array Analyzer

Namespace ConsoleApplication27
{
Class Program
{
Static void Main (string [] args)
{
# Region create an array
Console. Write ("Enter the length of the array :");
Int len = int. Parse (Console. ReadLine ());
Int [] numbers = new int [len];
For (int I = 0; I <numbers. Length; I ++)
{
Console. Write ("Enter the number of the array" + (I + 1) + "item :");
Numbers [I] = int. Parse (Console. ReadLine ());
}
# Endregion
Console. Clear ();
# Region sort in ascending order
For (int I = 0; I <numbers. Length-1; I ++)
{
For (int j = I + 1; j <numbers. Length; j ++)
{
If (numbers [I]> numbers [j])
{
Int temp = numbers [I];
Numbers [I] = numbers [j];
Numbers [j] = temp;
}
}
}
# Endregion
# Region output Array
Console. WriteLine ("the numbers you entered are sorted as follows :");
For (int I = 0; I <numbers. Length; I ++)
{
Console. Write (numbers [I] + "");
}
Console. WriteLine ();
# Endregion
# Region Search for odd numbers
Console. WriteLine ("the following numbers are odd :");
For (int I = 0; I <numbers. Length; I ++)
{
If (numbers [I] % 2! = 0)
{
Console. Write (numbers [I] + "");
}

}
Console. WriteLine ();
# Endregion
# Region Finding Prime Numbers
Bool isFind = false;
Console. WriteLine ("the following numbers are prime numbers :");
For (int I = 0; I <numbers. Length; I ++)
{

For (int j = 2; j <numbers [I]; j ++)
{
If (numbers [I] % j = 0)
{
IsFind = true;
Break;
}
}
If (! IsFind)
{
Console. Write (numbers [I] + "");
}
}
# Endregion
Console. ReadLine ();
}}}

This program contains the creation of arrays, the arrangement of arrays, and the search of odd and prime numbers. The knowledge of if judgment and for loop is used,

When we learned the array chapter, this array analyzer contains a very comprehensive question we learned.

Bytes -------------------------------------------------------------------------------------------------------------------------

 

Console calendar

Class Program
{
Static void Main (string [] args)
{
While (true)
{
# Region get the correct year and month
Int year, month;
While (true)
{
Console. Write ("Enter the year (1900-2100 ):");
Year = int. Parse (Console. ReadLine ());
If (year> 2100 | year <1900)
{
Console. Write ("Incorrect year input. Press enter to re-enter ");
Console. ReadLine ();
Console. Clear ();
}
Else
{
Console. Write ("Enter the month (1-12 ):");
Month = int. Parse (Console. ReadLine ());
If (month <1 | month> 12)
{
Console. Write ("Incorrect month input, press the Enter key and then enter again ");
Console. ReadLine ();
Console. Clear ();
}
Else
{
Break;
}
}
}
# Endregion

# Region obtain all the dates of the month of the current year, including the previous blank space, and save it to a string set dates.
List <string> dates = new List <string> ();

# Add blank space to the set
// 1. Calculate the number of days from January 1, 1900 to year-1
Int crossDaysOfYear = 0;
For (int I = 1900; I <year; I ++)
{
// The cyclic variable I represents a year.
If (I % 4 = 0 & I % 100! = 0 | I % 400 = 0)
{
CrossDaysOfYear + = 366;
}
Else
{
CrossDaysOfYear + = 365;
}
}

// 2. Number of days that have elapsed since January to month-august in the year variable
Int crossDaysOfMonth = 0;
For (int I = 1; I <month; I ++)
{
// Cyclic variable I, which is a month
If (I = 2)
{
If (year % 4 = 0 & amp; year % 100! = 0 | year % 400 = 0)
{
CrossDaysOfMonth + = 29; // February
}
Else
{
CrossDaysOfMonth + = 28; // normal month
}
}
Else if (I % 2! = 0 & I <= 7 | I % 2 = 0 & I> = 8)
{
CrossDaysOfMonth + = 31; // large month
}
Else
{
CrossDaysOfMonth + = 30; // small month
}
}

Int crossDays = crossDaysOfYear + crossDaysOfMonth; // The total number of days that have elapsed
Int dayOfWeek = crossDays % 7 + 1; // year-month-1 is the day of the week
Int space = dayOfWeek-1; // number of leading Spaces
For (int I = 0; I <space; I ++)
{
Dates. Add ("");
}
# Endregion

# Region add a date number to the set
Int days;
// Calculate the number of days in the month
If (month = 2)
{
If (year % 4 = 0 & amp; year % 100! = 0 | year % 400 = 0)
{
Days = 29; // February
}
Else
{
Days = 28; // normal month
}
}
Else if (month <= 7 & month % 2! = 0 | month> 7 & month % 2 = 0)
{
Days = 31; // large month
}
Else
{
Days = 30; // small month
}
For (int I = 1; I <= days; I ++)
{
Dates. Add (I. ToString ());
}
# Endregion

# Endregion

# Region output results
Console. writeLine ("************************************* *************");
Console. Write ("one \ t Two \ t three \ t four \ t five \ t six \ t day ");
For (int I = 0; I <dates. Count; I ++)
{
If (I % 7 = 0)
{
Console. WriteLine ();
}
Console. Write (dates [I] + "\ t ");
}
Console. WriteLine ();
Console. writeLine ("************************************* *************");
# Endregion

Console. Write ("press enter to continue ");
Console. ReadLine ();

}
}
} The console calendar not only covers what we have learned in the last few days, but also requires us to think about the topic with strong hands-on ability.

To solve this problem, you must have a clear idea. First, you must draw a flowchart of this question.

The key is to obtain the correct date of the year.

Bytes ------------------------------------------------------------------------------------------------------------------------

 

 



 

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.