C Getting Started section sixth custom functions

Source: Internet
Author: User

/*
1. No parameter no return value
void Hello ()
{
printf ("Hello world!\n");
}
2. No parameter has a return value
int Peoplwecount () {
return 10;
}
3. Have a parameter return value
int max (int a, int b)
{
Return a > B? A:B;
}
4. Parameter no return value (print one number)
void number (int a)
{
printf ("%d\n", a);
}
1. Write the function int sumvalue (int m,int N): Calculates the and of M to N.
int sumvalue (int m,int N)
{
int sum = 0;
for (int i = m; i <= N; i + +)
{
sum + = i;
}
return sum;
}
Write the function dayofyear (year, mouth,day) so that the function return is determined by these three parameters? What day is it? The first few days of the year.
*/
void DayOfYear (int year, Int. month, int day);//Declaration of function
void DayOfYear (int year, Int. month, int day)//definition of function
{int yearrun = 0;
if (year%400 = = 0 | | (0 = = year% 4 && 0! = year%100))
{
Yearrun = 1;
}
int daycount = 0;
Switch (month-1) {
Case 11:
Daycount + = 30;
Case 10:
Daycount + = 31;
Case 9:
Daycount + = 30;
Case 8:
Daycount + = 31;
Case 7:
Daycount + = 31;
Case 6:
Daycount + = 30;
Case 5:
Daycount + = 31;
Case 4:
Daycount + = 30;
Case 3:
Daycount + = 31;
Case 2:
Daycount + + Yearrun;
Case 1:
Daycount + = 31;
Case 0:
Daycount + = day;
Default
Break
}printf ("%d", daycount);
}
/*
3. Write a function that returns the middle number of three integers.

*/
int main (int argc, const char * argv[]) {

#pragma the definition of the mark------function------
/* Function: Code snippet with specific functionality
1. Library functions//system provides good functions
2. Custom functions//developers write their own functions

1. No parameter no return value

for (int i = 0; i <; i + +)
{
Hello ();
}

2. No parameter has a return value

A man has two hands, define a variable r = 2;
int r = 2;
int hands = R * Peoplwecount ();
printf ("%d\n", hands);

3. Have a parameter return value

int a = max (20,30);
printf ("%d\n", a);

4. Parameter no return value (print one number)
Number (4);
int a = Sumvalue (10,20);
printf ("%d\n", a);

*/
DayOfYear (2014, 3, 1);
printf ("\ n");
/*

int A, B;
scanf ("%d%d", &a,&b);
printf ("%d\n", add (b));
printf ("%d\n", Dev (A, b));
printf ("%d\n", nul (A, b));
float C = Divi (A, b);
printf ("%.2f\n", c);

The parameter changes do not change the value of the argument, and the parameter copies only the copy of the argument
The arguments do not change as they are manipulated, and the parameters change


Exchange is not, because just copy, is not changed//and ordinary elements as a variable no difference
int a[5] = {1,2,3,4,5};
Swap (a[1],a[3]);
for (int i =0; i < 5; i + +) {
//
printf ("%d", a[i]);
//    }
Changearray (a);
Long s = 0,n = 0;
int x = 0;
for (int i = 1;i <= 3; i + +)
{
x = Pingfang (i);
n = Jiecheng (x);
s = s + N;
}
printf ("%ld", s);
*/

printf ("%ld", Jiecheng2 (5));

C Getting Started section sixth custom functions

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.