1.
1 #include2 int main() 3 { 4 int add(int a, int b); 5 int minus(int a, int b); 6 int quotient(int a, int b); 7 int mod(int a, int b); 8 int x, y, a, b, c, d; 9 scanf_s("%d%d", &x, &y);10 a = add(x, y);11 b = minus(x, y);12 c = quotient(x, y);13 d = mod(x, y);14 printf("x+y=%d,x-y=%d,x*y=%d,x/y=%d", a, b, c, d);15 return 0;16 }17 18 int add(int a, int b)19 {20 int c;21 c = a + b;22 return c;23 }24 25 int minus(int a, int b)26 {27 int c;28 c = a - b;29 return c;30 }31 32 int quotient(int a, int b)33 {34 int c;35 c = a * b;36 return c;37 }38 39 int mod(int a, int b)40 {41 int c;42 c = a / b;43 return c;44 }
图片:
2.
1 #include2 int main() 3 { 4 int a,b; 5 scanf_s("%d", &a); 6 b = prime(a); 7 if (b == 1) 8 { 9 printf("YES");10 }11 else if (b == 0)12 {13 printf("NO");14 }15 return 0;16 }17 18 int prime(int n)19 {20 int i;21 if (n == 1)22 {23 return 0;24 }25 if (n == 2)26 {27 return 1;28 }29 for (i = 2; i < n; i++)30 {31 if (n % i == 0)32 { 33 return 0;34 }35 }36 return 1;37 38 39 }
图片:
3.
1 #include2 int main() 3 { 4 int a, b, c, d, e; 5 scanf_s("%d%d%d%d", &a, &b, &c, &d); 6 e = max4(a, b, c, d); 7 printf("%d", e); 8 return 0; 9 }10 11 int max2(int a, int b)12 {13 if (a >= b)14 {15 return a;16 }17 if (a < b)18 {19 return b;20 }21 }22 23 int max4(int a, int b, int c, int d)24 {25 int x, y, z;26 x = max2(a, b);27 y = max2(c, d);28 z = max2(x, y);29 return z;30 }
图片:
4.
1 #include2 int main() 3 { 4 int a, b; 5 scanf_s("%d", &a); 6 b = factorial(a); 7 printf("%d", b); 8 return 0; 9 }10 11 int factorial(int a)12 { 13 if (a == 1 || a == 0)14 return 1;15 else16 return factorial(a - 1) * a;17 }
图片: