#include <stdio.h> #include <stdlib.h> #include <time.h> #include <windows.h> #define N 80 void print_text(int line, int col, char text[]); // 函数声明 void print_spaces(int n); // 函数声明 void print_blank_lines(int n); // 函数声明 int main() { int line, col, i; char text[N] = "hi, November~"; srand(time(0)); // 以当前系统时间作为随机种子 for (i = 1; i <= 10; ++i) { line = rand() % 25; //产生0-24之间的随机整数,即小黑屏有25行 col = rand() % 80; //产生0-79之间的随机整数,即小黑屏有80列 print_text(line, col, text); Sleep(1000); // 暂停1000ms }
#include<stdio.h> long long fac(int n); int main() { int i, n; printf("Enter n:"); scanf_s("%d", &n); for (i = 1; i <= n; ++i) printf("%d!=%11d\n", i, fac(i)); return 0; } long long fac(int n) { static long long p = 1; printf("p=%11d\n", p); p = p * n; return p; }
#include<stdio.h> int func(int, int); int main() { int k = 4, m = 1, p1, p2; p1=func(k,m); p2 = func(k, m); printf("%d,%d\n", p1, p2); return 0; } int func(int a, int b) { static int m = 0, i = 2; i += m + 1; m = i + a + b; return m; }
#include <stdio.h> long long func(int n); int main() { int n; long long f; while (scanf_s("%d", &n) != EOF) { f = func(n); printf("n=%d,f=%lld\n", n, f); }return 0; } long long func(int n) { long long a; if (n >= 1) { a = 2 * func(n - 1) + 1; } else { a = 0; } return a; }
#include<stdio.h> int func(int n, int m); int main() { int n, m; while (scanf_s("%d%d", &n, &m) != EOF) printf("n=%d,m=%d,ans=%d\n", n, m, func(n, m)); return 0; } int func(int n,int m) { if (n < m) { return 0; } else if(m == 0) { return 1; } else if (n == m) { return 1; } else { return func(n - 1, m - 1) + func(n - 1, m); } }
#include <stdio.h> int mul(int n, int m); int main() { int n, m; while (scanf_s("%d%d", &n, &m) != EOF) printf("%d*%d=%d\n", n, m, mul(n, m)); return 0; } int mul(int n, int m) { int a=0; if (m > 0) return n + mul(n, m - 1); else if (m == 0) return 0; else if (n == 0) return 0; }
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> void moveplate(unsigned int n, char from, char to); void hanoi(unsigned int n, char from, char temp, char to); int count = 0; int main() { unsigned int n; printf("请输入你需要进行移动的盘子数:\n"); while (scanf("%d", &n) != EOF) { count = 0; printf("请输入你需要进行移动的盘子数:\n"); hanoi(n, 'A', 'B', 'C'); printf("移动盘子的总次数为:%d\n", count); } return 0; } void moveplate(unsigned int n, char from, char to) { printf("%u:%c-->%c\n", n, from, to); count++; } void hanoi(unsigned int n, char from, char temp, char to) { if (n == 1) moveplate(n, from, to); else { hanoi(n - 1, from, to, temp); moveplate(n, from, to); hanoi(n - 1, temp, from, to); } }
#include <stdio.h> #define _CRT_SECURE_NO_WARNINGS int is_prime(int n) { int i; if (n <= 1)return 0; for (i = 2;i < n;i++) { if (n % i == 0)return 0; } return 1; } int main() { int x, y; for (x = 1;x <= 20;x++) { if (x % 2 == 0) { for (y = 1;y <= x;y++) { if (is_prime(y) && is_prime(x - y) && y <= x - y) printf("%d=%d+%d\n", x, y, x - y); } } } }
#include<stdio.h> long fun(long s); int main() { long s, t; printf("Enter a number:"); while (scanf_s("%ld", &s) != EOF) { t = fun(s); printf("new number is:%ld\n\n", t); printf("Enter a number:"); } return 0; } long fun(long s) { int a, b, i, d; int num[100]; a = 0; i = 0; d = s; while (d != 0) { if (d % 2==1) { num[i] = d % 10; i++; } d = d / 10; } for (b = i - 1; b >= 0; b--) { a = a * 10 + num[b]; } return a; }
return 0; } // 打印n个空格 void print_spaces(int n) { int i; for (i = 1; i <= n; ++i) printf(" "); } // 打印n行空白行 void print_blank_lines(int n) { int i; for (i = 1; i <= n; ++i) printf("\n"); } // 在第line行第col列打印一段文本 void print_text(int line, int col, char text[]) { print_blank_lines(line - 1); // 打印(line-1)行空行 print_spaces(col - 1); // 打印(col-1)列空格 printf("%s", text); // 在第line行、col列输出text中字符串 }
标签:return,int,long,char,实验,func,printf From: https://www.cnblogs.com/1234wwh/p/16871151.html