#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>
#define N 80
void printText(int line, int col, char text[]); // 函数声明
void printSpaces(int n); // 函数声明
void printBlankLines(int n); // 函数声明
int main()
{
int line, col, i;
char text[N] = "hi, May~";
srand(time(0)); // 以当前系统时间作为随机种子
for (i = 1; i <= 10; ++i)
{
line = rand() % 25;
col = rand() % 80;
printText(line, col, text);
Sleep(1000); // 暂停1000ms
}
return 0;
}
// 打印n个空格
void printSpaces(int n)
{
int i;
for (i = 1; i <= n; ++i)
printf(" ");
}
// 打印n行空白行
void printBlankLines(int n)
{
int i;
for (i = 1; i <= n; ++i)
printf("\n");
}
// 在第line行第col列打印一段文本
void printText(int line, int col, char text[])
{
printBlankLines(line - 1); // 打印n-1行空行
printSpaces(col - 1); // 打印n-1列空格
printf("%s", text);
}
在屏幕上输出随机跳动的字符串 hi,may~

第一次输入func 函数中将初始化m=0,i=2;再次输入func函数中 i为3 m为8
#include <stdio.h>
long long fun(int n);
int main()
{
int n;
long long f;
while (scanf_s("%d", &n) != EOF)
{
f = fun(n);
printf("n=%d,f=%lld\n", n, f);
}
return 0;
}
long long fun(int n)
{
long long s;
if (n == 0)
{
s =0;
}
else
s = 2 * fun(n - 1)+1;
return s;
}
#include <stdio.h>
long long fun(int n);
void hanoi( int n, char from, char temp, char to);
void moveplace(int n, char from, char to);
int main()
{
int n;
long long f;
while (scanf_s("%d",&n) != EOF)
{
hanoi(n, 'A', 'B', 'C');
f = fun(n);
printf("总共移动了 %lld 次\n", f);
}
return 0;
}
long long fun(int n)
{
long long s;
if (n == 0)
{
s =0;
}
else
s = 2 * fun(n - 1)+1;
return s;
}
void hanoi(int n, char from, char temp, char to)
{
if (n == 1)
moveplace(n, from, to);
else
{
hanoi(n - 1, from, to, temp);
moveplace(n, from, to);
hanoi(n - 1, temp, from, to);
}
}
void moveplace(int n, char from, char to)
{
printf("第 % d个盘子: % c-> % c\n", n, from, to);
}
#include <stdio.h>
int is_prime(int n);
int main()
{
int n,i,k,p,q;
i = 1; k = 1;
for (n = 4; n <= 20; n += 2)
{
do {
i++;
k = n - i;
p = is_prime(i);
q = is_prime(k);
}
while ( p*q==0);
printf("%d=%d+%d\n", n, i, k);
}
return 0;
}
int is_prime(int n)
{
int i;
for (i = 2; i < n; i++)
if (n % i != 0)
return 1;
else
return 0;
}

#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)
{
long n;
long result=0;
int p=1;
while (s != 0)
{
n = s % 10;
if (n % 2 != 0)
{
result = n*p+result;
p = 10 * p;
}
else
{
result = result;
}
s = s / 10;
}
return result;
}
