Input a positive integer n and output n! */#include
int factorial(int n); ? //Function declaration
int main(int argc, char const *argv[]) ?//Main function
{
int n; ?//Variable definition
scanf(" %d", &n); //Enter an integer
printf("%d\n", factorial(n)); ? //Call function to calculate factorial
p>?
return 0;
}int factorial(int n) //Define calculation n! function
{ ?
int fact = 1;
for (int i = 1; i <= n; ++i)
{
fact = fact*i;
}
return fact;?
}
Features
1. C language is a high-level language. It combines the basic structures and statements of high-level languages ??with the practicality of low-level languages. C language can operate on bits, bytes and addresses just like assembly language, and these three are the most basic working units of computers.
2. C language is a structural language. The distinctive feature of structural languages ??is the separation of code and data, that is, each part of the program is independent of each other except for necessary information exchange. This structured approach makes the program hierarchy clear and easy to use, maintain, and debug. C language is provided to users in the form of functions. These functions can be easily called and have a variety of loops and conditional statements to control the program flow, thus making the program completely structured.
3. C language is fully functional. Has a wide variety of data types and introduces the concept of pointers to make programs more efficient. Moreover, the calculation function and logical judgment function are also relatively powerful.
4. C language has a wide range of applications. Suitable for a variety of operating systems, such as Windows, DOS, UNIX, LINUX, etc.; also suitable for a variety of machine models. C language is obviously better than other high-level languages ??for writing situations that require hardware operations. Some large-scale application software is also written in C language.