1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <time.h> 4 #include <windows.h> 5 #define N 80 6 void print_text(int line, int col, char text[]); 7 void print_spaces(int n); 8 void print_blank_lines(int n); 9 int main() { 10 int line, col, i; 11 char text[N] = "hi, November~"; 12 srand(time(0)); 13 for(i = 1; i <= 10; ++i) { 14 line = rand() % 25; 15 col = rand() % 80; 16 print_text(line, col, text); 17 Sleep(1000); 18 } 19 return 0; 20 } 21 22 void print_spaces(int n) { 23 24 int i; 25 for(i = 1; i <= n; ++i) 26 printf(" "); 27 } 28 29 void print_blank_lines(int n) { 30 int i; 31 for(i = 1; i <= n; ++i) 32 printf("\n"); 33 } 34 35 void print_text(int line, int col, char text[]) { 36 print_blank_lines(line-1); 37 print_spaces(col-1); 38 printf("%s", text); 39 }
1 #include <stdio.h> 2 long long fac(int n); 3 int main() { 4 int i, n; 5 printf("Enter n: "); 6 scanf("%d", &n); 7 for (i = 1; i <= n; ++i) 8 printf("%d! = %lld\n", i, fac(i)); 9 return 0; 10 } 11 long long fac(int n) { 12 static long long p = 1; 13 p = p * n; 14 return p; 15 }
1 #include <stdio.h> 2 int func(int, int); 3 int main() { 4 int k = 4, m = 1, p1, p2; 5 p1 = func(k, m); 6 p2 = func(k, m); 7 printf("%d, %d\n", p1, p2); 8 return 0; 9 } 10 11 int func(int a, int b) { 12 static int m = 0, i = 2; 13 i += m + 1; 14 m = i + a + b; 15 return m;}
1 #include<stdio.h> 2 long long func(int n); 3 int main() 4 { 5 int n; 6 long long f; 7 while (scanf_s("%d", &n) != EOF) 8 { 9 f = func(n); 10 printf("n=%d,f=%lld\n", n, f); 11 } 12 return 0; 13 } 14 long long func(int n) 15 { 16 long long Y; 17 if (n == 1) 18 Y= 1; 19 else 20 Y= 2 * (func(n - 1) + 1) - 1; 21 return Y; 22 }
1 #include<stdio.h> 2 int func(int n, int m); 3 4 int main() 5 { 6 int n, m; 7 while (scanf_s("%d%d", &n, &m) != EOF) 8 printf("n=%d,m=%d,ans=%d\n", n, m, func(n, m)); 9 return 0; 10 } 11 int func(int n, int m) 12 { 13 int Y; 14 15 if (n == m || m == 0) 16 return 1; 17 18 if (n < m) 19 return 0; 20 21 else 22 Y = func(n - 1, m) + func(n - 1, m - 1); 23 return Y; 24 }
1 #include <stdio.h> 2 int mul(int n, int m); 3 int main() 4 { 5 int n, m; 6 while (scanf_s("%d%d", &n, &m) != EOF) 7 printf("%d * %d = %d\n", n, m, mul(n, m)); 8 return 0; 9 } 10 int mul(int n, int m) 11 { 12 13 if (m == 0) 14 return 0; 15 16 else 17 return n + mul(n, m - 1); 18 19 }
1 #include<stdio.h> 2 #include<stdlib.h> 3 4 void hanoi(unsigned int n, char from, char temp, char to); 5 void moveplate(unsigned int n, char from, char to); 6 int i; 7 8 int main() 9 { 10 unsigned int n; 11 12 while (scanf_s("%u", &n) != EOF) 13 { 14 hanoi(n, 'A', 'B', 'C'); 15 printf("\n"); 16 printf(" 一共移动了%u次", i); 17 printf("\n"); 18 i = 0; 19 } 20 system("pause"); 21 22 return 0; 23 } 24 25 void hanoi(unsigned int n, char from, char temp, char to) 26 { 27 if (n == 1) 28 moveplate(n, from, to); 29 else 30 { 31 hanoi(n - 1, from, to, temp); 32 moveplate(n, from, to); 33 hanoi(n - 1, temp, from, to); 34 } 35 } 36 void moveplate(unsigned int n, char from, char to) 37 { 38 i++; 39 printf("%u:%c-->%c\n", n, from, to); 40 }
#include<stdio.h> #include<stdlib.h> int is_prime(int n); int main() { int i, a, b; for (i = 1; i <= 20; ++i) { if (i % 2 == 0) { for (a = 2; a < i; a++) { b = i - a; if (is_prime(b) && is_prime(a) && b != 0) { printf("%d=%d+%d\n", i, a, b); break; } } } else continue; } } int is_prime(int n) { int i; int y = 1; for (i = 2; i < n; ++i) { if (n % i== 0) { y = 0; break; } } return y ; }
1 #include <stdio.h> 2 #include<stdlib.h> 3 #include<math.h> 4 long fun(long s); 5 6 int main() 7 { 8 long s, t; 9 printf("Enter a number: "); 10 while (scanf_s("%ld", &s) != EOF) 11 { 12 t = fun(s); 13 printf("new number is: %ld\n\n", t); 14 printf("Enter a number: "); 15 } 16 return 0; 17 } 18 19 long fun(long s) 20 { 21 int ans[100], i, t = 0, j, a; 22 long sum = 0; 23 for (i = 0; i <= 100; i++) 24 { 25 a = s % 10; 26 s = s / 10; 27 if (a % 2 == 1) 28 { 29 ans[t] = a; 30 t++; 31 } 32 else continue; 33 } 34 for (j = t - 1; j >= 0; j--) 35 { 36 sum = sum * 10 + ans[j]; 37 } 38 return sum; 39 40 }
标签:return,int,long,char,实验,func,include From: https://www.cnblogs.com/kennthy/p/16863076.html