Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - Set the upper right half of a two-dimensional array (5 rows and 5 columns) to zero (the values in the matrix can be entered at will through the keyboard).
Set the upper right half of a two-dimensional array (5 rows and 5 columns) to zero (the values in the matrix can be entered at will through the keyboard).
# contains < iostream >

usingnamespacestd

intmain()

{

inti,j;

inta[5][5];

Printf ("Please enter an integer of 5 * 5, with 5 in the same line separated by spaces, carriage return and line feed: \ n");

for(I = 0; I < 5; i++)

CIN > > a[I][0]> > a[I][ 1]> > a[I][2]> > a[I][3]> > a[I][4];

for(I = 0; I < 5; i++)

for(j = I; j < 5; j++)a[I][j]= 0;

for(I = 0; I < 5; i++)

{

for(j = 0; j < 5; j++)

cout < < a[I][j]< < " ";

cout < < endl

}

return0

}

Extended data:

Main functional usage

Main functions in 1 and C++

C++ inherits most features of C language, so it keeps the tradition that "the program always starts with the main function by default and always ends with the return statement or the end of the main function", but it should be noted that the main function in C++ must be written in the global scope if it wants to be the entrance and exit of program execution.

Cannot be written as a member of a structure or class. Although the main function can be used as a member function of a structure or class, it will lose its function as the entrance and exit of the program accordingly.

The writing format of global main function in C++ is exactly the same as that in C language, and the same C++ program can only have one global main function.

Principal Function in 2.Java

Java also uses main function as the entrance and exit of program execution, but as a "purer" object-oriented language, Java's main function is very different from C/C++.

First, the concept of return value is weakened. The return value of main is not allowed in JavaApplication, so intmain is forbidden, and voidmain must be used. Intmain is only used in JavaBean.

Secondly, all functions in Java must belong to the class, and there is no global function, so the main function cannot be a global member, but must be a member of the class.

Thirdly, because the main function has become a member function of the class, in order to be called directly by the system, it must be made a static function with public permission by using publicstatic.

Fourthly, the parameters of the main function are simplified, only the string array is needed, and the number of parameters is not needed (this is because Java arrays have subscript checking function).

The general format of the main function in JavaApplication is as follows (the class name can be customized, but when saving as Java source code, the main file name must be the same as the class name, otherwise it may not run).

publicclassMainDemo{

publicstaticvoidmain(String[]args){

//TODO: Write the contents of the main function here.

}

}

The running mechanism of JavaApplet is completely different from that of JavaApplication, so the main function is not needed.

3. The main function in C #

The main function in C# is similar to Java, and it must be a class member. It also uses a string array as the only parameter, and it is also a static function and voidmain.

The difference is that the first letter of Main is capitalized, that is, "main function". Whether it is limited to the public level is not important (there is no public by default, but public may still be needed in some occasions).

In addition, it should be noted that in C#, the restriction that the class name must be the same as the main file name no longer exists. Even if the class name is different from the main file name, the program can still run.

The main function in C# application is like this by default (note that the first letter of main is capitalized).

The difference between C# and C/C++ and java is that C# is not limited to executing from the main () function, but belongs to the event trigger.

classProgram{

staticvoidMain(string[]args){